| 1 |
Installation |
| 2 |
============ |
| 3 |
|
| 4 |
|
| 5 |
Python Version |
| 6 |
-------------- |
| 7 |
|
| 8 |
We recommend using the latest version of Python. CacheLib supports |
| 9 |
Python 3.11 and newer. |
| 10 |
|
| 11 |
|
| 12 |
Dependencies |
| 13 |
------------ |
| 14 |
|
| 15 |
There are no required dependencies beyond Python itself. CacheLib is a |
| 16 |
standalone library that works out of the box. |
| 17 |
|
| 18 |
|
| 19 |
Optional Dependencies |
| 20 |
~~~~~~~~~~~~~~~~~~~~~ |
| 21 |
|
| 22 |
When you install CacheLib :class:`.SimpleCache` and :class:`.FileSystemCache` |
| 23 |
will work without any additional dependencies. |
| 24 |
However, some backends require additional dependencies to be installed. |
| 25 |
|
| 26 |
CacheLib will detect and use them if they are already installed but if not, |
| 27 |
you can use pip extras to install them as needed: |
| 28 |
|
| 29 |
.. tabs:: |
| 30 |
|
| 31 |
.. group-tab:: Redis |
| 32 |
|
| 33 |
Installs `redis-py`_ required for :class:`.RedisCache`. |
| 34 |
|
| 35 |
.. code-block:: console |
| 36 |
|
| 37 |
$ pip install cachelib[redis] |
| 38 |
|
| 39 |
.. group-tab:: Memcached |
| 40 |
|
| 41 |
Installs `pylibmc`_ required for :class:`.MemcachedCache`. |
| 42 |
|
| 43 |
.. code-block:: console |
| 44 |
|
| 45 |
$ pip install cachelib[memcached] |
| 46 |
|
| 47 |
.. group-tab:: DynamoDB |
| 48 |
|
| 49 |
Installs `boto3`_ required for :class:`.DynamoDbCache`. |
| 50 |
|
| 51 |
.. code-block:: console |
| 52 |
|
| 53 |
$ pip install cachelib[dynamodb] |
| 54 |
|
| 55 |
.. group-tab:: MongoDB |
| 56 |
|
| 57 |
Installs `pymongo`_ required for :class:`.MongoDbCache`. |
| 58 |
|
| 59 |
.. code-block:: console |
| 60 |
|
| 61 |
$ pip install cachelib[mongodb] |
| 62 |
|
| 63 |
.. group-tab:: Valkey |
| 64 |
|
| 65 |
Installs `valkey-py`_ required for :class:`.ValkeyCache`. |
| 66 |
|
| 67 |
.. code-block:: console |
| 68 |
|
| 69 |
$ pip install cachelib[valkey] |
| 70 |
|
| 71 |
.. group-tab:: uWSGI |
| 72 |
|
| 73 |
Installs `uWSGI`_ required for :class:`.UWSGICache`. |
| 74 |
|
| 75 |
.. code-block:: console |
| 76 |
|
| 77 |
$ pip install cachelib[uwsgi] |
| 78 |
|
| 79 |
.. _redis-py: https://redis.readthedocs.io/en/stable/ |
| 80 |
.. _pylibmc: https://sendapatch.se/projects/pylibmc/ |
| 81 |
.. _boto3: https://boto3.amazonaws.com/v1/documentation/api/latest/index.html |
| 82 |
.. _pymongo: https://pymongo.readthedocs.io/ |
| 83 |
.. _valkey-py: https://valkey-py.readthedocs.io/en/latest/ |
| 84 |
.. _uWSGI: https://uwsgi-docs.readthedocs.io/en/latest/ |
| 85 |
|
| 86 |
|
| 87 |
Virtual Environments |
| 88 |
-------------------- |
| 89 |
|
| 90 |
Use a virtual environment to manage the dependencies for your project, |
| 91 |
both in development and in production. |
| 92 |
|
| 93 |
What problem does a virtual environment solve? The more Python projects |
| 94 |
you have, the more likely it is that you need to work with different |
| 95 |
versions of Python libraries, or even Python itself. Newer versions of |
| 96 |
libraries for one project can break compatibility in another project. |
| 97 |
|
| 98 |
Virtual environments are independent groups of Python libraries, one for |
| 99 |
each project. Packages installed for one project will not affect other |
| 100 |
projects or the operating system's packages. |
| 101 |
|
| 102 |
Python comes bundled with the :mod:`venv` module to create virtual |
| 103 |
environments. |
| 104 |
|
| 105 |
|
| 106 |
.. _install-create-env: |
| 107 |
|
| 108 |
Create an environment |
| 109 |
~~~~~~~~~~~~~~~~~~~~~ |
| 110 |
|
| 111 |
Create a project folder and a :file:`.venv` folder within: |
| 112 |
|
| 113 |
.. tabs:: |
| 114 |
|
| 115 |
.. group-tab:: macOS/Linux |
| 116 |
|
| 117 |
.. code-block:: console |
| 118 |
|
| 119 |
$ mkdir myproject |
| 120 |
$ cd myproject |
| 121 |
$ python3 -m venv .venv |
| 122 |
|
| 123 |
.. group-tab:: Windows |
| 124 |
|
| 125 |
.. code-block:: doscon |
| 126 |
|
| 127 |
C:\> mkdir myproject |
| 128 |
C:\> cd myproject |
| 129 |
C:\> py -3 -m venv .venv |
| 130 |
|
| 131 |
|
| 132 |
.. _install-activate-env: |
| 133 |
|
| 134 |
Activate the environment |
| 135 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 136 |
|
| 137 |
Before you work on your project, activate the corresponding environment: |
| 138 |
|
| 139 |
.. tabs:: |
| 140 |
|
| 141 |
.. group-tab:: macOS/Linux |
| 142 |
|
| 143 |
.. code-block:: console |
| 144 |
|
| 145 |
$ . .venv/bin/activate |
| 146 |
|
| 147 |
.. group-tab:: Windows |
| 148 |
|
| 149 |
.. code-block:: doscon |
| 150 |
|
| 151 |
C:\> .venv\Scripts\activate |
| 152 |
|
| 153 |
Your shell prompt will change to show the name of the activated |
| 154 |
environment. |
| 155 |
|
| 156 |
|
| 157 |
Install CacheLib |
| 158 |
---------------- |
| 159 |
|
| 160 |
Within the activated environment, use the following command to install |
| 161 |
CacheLib: |
| 162 |
|
| 163 |
.. code-block:: console |
| 164 |
|
| 165 |
$ pip install cachelib |
| 166 |
|
| 167 |
CacheLib is now installed. Check out the :doc:`quickstart` to get |
| 168 |
started. |