METADATA 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. Metadata-Version: 2.4
  2. Name: redis
  3. Version: 7.4.0
  4. Summary: Python client for Redis database and key-value store
  5. Project-URL: Changes, https://github.com/redis/redis-py/releases
  6. Project-URL: Code, https://github.com/redis/redis-py
  7. Project-URL: Documentation, https://redis.readthedocs.io/en/latest/
  8. Project-URL: Homepage, https://github.com/redis/redis-py
  9. Project-URL: Issue tracker, https://github.com/redis/redis-py/issues
  10. Author-email: "Redis Inc." <oss@redis.com>
  11. License-Expression: MIT
  12. License-File: LICENSE
  13. Keywords: Redis,database,key-value-store
  14. Classifier: Development Status :: 5 - Production/Stable
  15. Classifier: Environment :: Console
  16. Classifier: Intended Audience :: Developers
  17. Classifier: License :: OSI Approved :: MIT License
  18. Classifier: Operating System :: OS Independent
  19. Classifier: Programming Language :: Python
  20. Classifier: Programming Language :: Python :: 3
  21. Classifier: Programming Language :: Python :: 3 :: Only
  22. Classifier: Programming Language :: Python :: 3.10
  23. Classifier: Programming Language :: Python :: 3.11
  24. Classifier: Programming Language :: Python :: 3.12
  25. Classifier: Programming Language :: Python :: 3.13
  26. Classifier: Programming Language :: Python :: 3.14
  27. Classifier: Programming Language :: Python :: Implementation :: CPython
  28. Classifier: Programming Language :: Python :: Implementation :: PyPy
  29. Requires-Python: >=3.10
  30. Requires-Dist: async-timeout>=4.0.3; python_full_version < '3.11.3'
  31. Provides-Extra: circuit-breaker
  32. Requires-Dist: pybreaker>=1.4.0; extra == 'circuit-breaker'
  33. Provides-Extra: hiredis
  34. Requires-Dist: hiredis>=3.2.0; extra == 'hiredis'
  35. Provides-Extra: jwt
  36. Requires-Dist: pyjwt>=2.9.0; extra == 'jwt'
  37. Provides-Extra: ocsp
  38. Requires-Dist: cryptography>=36.0.1; extra == 'ocsp'
  39. Requires-Dist: pyopenssl>=20.0.1; extra == 'ocsp'
  40. Requires-Dist: requests>=2.31.0; extra == 'ocsp'
  41. Provides-Extra: otel
  42. Requires-Dist: opentelemetry-api>=1.39.1; extra == 'otel'
  43. Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.39.1; extra == 'otel'
  44. Requires-Dist: opentelemetry-sdk>=1.39.1; extra == 'otel'
  45. Provides-Extra: xxhash
  46. Requires-Dist: xxhash~=3.6.0; extra == 'xxhash'
  47. Description-Content-Type: text/markdown
  48. # redis-py
  49. The Python interface to the Redis key-value store.
  50. [![CI](https://github.com/redis/redis-py/workflows/CI/badge.svg?branch=master)](https://github.com/redis/redis-py/actions?query=workflow%3ACI+branch%3Amaster)
  51. [![docs](https://readthedocs.org/projects/redis/badge/?version=stable&style=flat)](https://redis.readthedocs.io/en/stable/)
  52. [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/redis/redis-py/blob/master/LICENSE)
  53. [![pypi](https://badge.fury.io/py/redis.svg)](https://pypi.org/project/redis/)
  54. [![pre-release](https://img.shields.io/github/v/release/redis/redis-py?include_prereleases&label=latest-prerelease)](https://github.com/redis/redis-py/releases)
  55. [![codecov](https://codecov.io/gh/redis/redis-py/branch/master/graph/badge.svg?token=yenl5fzxxr)](https://codecov.io/gh/redis/redis-py)
  56. [Installation](#installation) | [Usage](#usage) | [Advanced Topics](#advanced-topics) | [Contributing](https://github.com/redis/redis-py/blob/master/CONTRIBUTING.md)
  57. ---------------------------------------------
  58. **Note:** redis-py 5.0 is the last version of redis-py that supports Python 3.7, as it has reached [end of life](https://devguide.python.org/versions/). redis-py 5.1 supports Python 3.8+.<br>
  59. **Note:** redis-py 6.1.0 is the last version of redis-py that supports Python 3.8, as it has reached [end of life](https://devguide.python.org/versions/). redis-py 6.2.0 supports Python 3.9+.
  60. ---------------------------------------------
  61. ## How do I Redis?
  62. [Learn for free at Redis University](https://redis.io/learn/university)
  63. [Try the Redis Cloud](https://redis.io/try-free/)
  64. [Dive in developer tutorials](https://redis.io/learn)
  65. [Join the Redis community](https://redis.io/community/)
  66. [Work at Redis](https://redis.io/careers/)
  67. ## Installation
  68. Start a redis via docker (for Redis versions >= 8.0):
  69. ``` bash
  70. docker run -p 6379:6379 -it redis:latest
  71. ```
  72. Start a redis via docker (for Redis versions < 8.0):
  73. ``` bash
  74. docker run -p 6379:6379 -it redis/redis-stack:latest
  75. ```
  76. To install redis-py, simply:
  77. ``` bash
  78. $ pip install redis
  79. ```
  80. For faster performance, install redis with hiredis support, this provides a compiled response parser, and *for most cases* requires zero code changes.
  81. By default, if hiredis >= 1.0 is available, redis-py will attempt to use it for response parsing.
  82. ``` bash
  83. $ pip install "redis[hiredis]"
  84. ```
  85. Looking for a high-level library to handle object mapping? See [redis-om-python](https://github.com/redis/redis-om-python)!
  86. ## Supported Redis Versions
  87. The most recent version of this library supports Redis version [7.2](https://github.com/redis/redis/blob/7.2/00-RELEASENOTES), [7.4](https://github.com/redis/redis/blob/7.4/00-RELEASENOTES), [8.0](https://github.com/redis/redis/blob/8.0/00-RELEASENOTES) and [8.2](https://github.com/redis/redis/blob/8.2/00-RELEASENOTES).
  88. The table below highlights version compatibility of the most-recent library versions and redis versions.
  89. | Library version | Supported redis versions |
  90. |-----------------|-------------------|
  91. | 3.5.3 | <= 6.2 Family of releases |
  92. | >= 4.5.0 | Version 5.0 to 7.0 |
  93. | >= 5.0.0 | Version 5.0 to 7.4 |
  94. | >= 6.0.0 | Version 7.2 to current |
  95. ## Usage
  96. ### Basic Example
  97. ``` python
  98. >>> import redis
  99. >>> r = redis.Redis(host='localhost', port=6379, db=0)
  100. >>> r.set('foo', 'bar')
  101. True
  102. >>> r.get('foo')
  103. b'bar'
  104. ```
  105. The above code connects to localhost on port 6379, sets a value in Redis, and retrieves it. All responses are returned as bytes in Python, to receive decoded strings, set *decode_responses=True*. For this, and more connection options, see [these examples](https://redis.readthedocs.io/en/stable/examples.html).
  106. #### RESP3 Support
  107. To enable support for RESP3, ensure you have at least version 5.0 of the client, and change your connection object to include *protocol=3*
  108. ``` python
  109. >>> import redis
  110. >>> r = redis.Redis(host='localhost', port=6379, db=0, protocol=3)
  111. ```
  112. ### Connection Pools
  113. By default, redis-py uses a connection pool to manage connections. Each instance of a Redis class receives its own connection pool. You can however define your own [redis.ConnectionPool](https://redis.readthedocs.io/en/stable/connections.html#connection-pools).
  114. ``` python
  115. >>> pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
  116. >>> r = redis.Redis(connection_pool=pool)
  117. ```
  118. Alternatively, you might want to look at [Async connections](https://redis.readthedocs.io/en/stable/examples/asyncio_examples.html), or [Cluster connections](https://redis.readthedocs.io/en/stable/connections.html#cluster-client), or even [Async Cluster connections](https://redis.readthedocs.io/en/stable/connections.html#async-cluster-client).
  119. ### Redis Commands
  120. There is built-in support for all of the [out-of-the-box Redis commands](https://redis.io/commands). They are exposed using the raw Redis command names (`HSET`, `HGETALL`, etc.) except where a word (i.e. del) is reserved by the language. The complete set of commands can be found [here](https://github.com/redis/redis-py/tree/master/redis/commands), or [the documentation](https://redis.readthedocs.io/en/stable/commands.html).
  121. ## Advanced Topics
  122. The [official Redis command documentation](https://redis.io/commands)
  123. does a great job of explaining each command in detail. redis-py attempts
  124. to adhere to the official command syntax. There are a few exceptions:
  125. - **MULTI/EXEC**: These are implemented as part of the Pipeline class.
  126. The pipeline is wrapped with the MULTI and EXEC statements by
  127. default when it is executed, which can be disabled by specifying
  128. transaction=False. See more about Pipelines below.
  129. - **SUBSCRIBE/LISTEN**: Similar to pipelines, PubSub is implemented as
  130. a separate class as it places the underlying connection in a state
  131. where it can\'t execute non-pubsub commands. Calling the pubsub
  132. method from the Redis client will return a PubSub instance where you
  133. can subscribe to channels and listen for messages. You can only call
  134. PUBLISH from the Redis client (see [this comment on issue
  135. #151](https://github.com/redis/redis-py/issues/151#issuecomment-1545015)
  136. for details).
  137. For more details, please see the documentation on [advanced topics page](https://redis.readthedocs.io/en/stable/advanced_features.html).
  138. ### Pipelines
  139. The following is a basic example of a [Redis pipeline](https://redis.io/docs/manual/pipelining/), a method to optimize round-trip calls, by batching Redis commands, and receiving their results as a list.
  140. ``` python
  141. >>> pipe = r.pipeline()
  142. >>> pipe.set('foo', 5)
  143. >>> pipe.set('bar', 18.5)
  144. >>> pipe.set('blee', "hello world!")
  145. >>> pipe.execute()
  146. [True, True, True]
  147. ```
  148. ### PubSub
  149. The following example shows how to utilize [Redis Pub/Sub](https://redis.io/docs/manual/pubsub/) to subscribe to specific channels.
  150. ``` python
  151. >>> r = redis.Redis(...)
  152. >>> p = r.pubsub()
  153. >>> p.subscribe('my-first-channel', 'my-second-channel', ...)
  154. >>> p.get_message()
  155. {'pattern': None, 'type': 'subscribe', 'channel': b'my-second-channel', 'data': 1}
  156. ```
  157. ### Redis’ search and query capabilities default dialect
  158. Release 6.0.0 introduces a client-side default dialect for Redis’ search and query capabilities.
  159. By default, the client now overrides the server-side dialect with version 2, automatically appending *DIALECT 2* to commands like *FT.AGGREGATE* and *FT.SEARCH*.
  160. **Important**: Be aware that the query dialect may impact the results returned. If needed, you can revert to a different dialect version by configuring the client accordingly.
  161. ``` python
  162. >>> from redis.commands.search.field import TextField
  163. >>> from redis.commands.search.query import Query
  164. >>> from redis.commands.search.index_definition import IndexDefinition
  165. >>> import redis
  166. >>> r = redis.Redis(host='localhost', port=6379, db=0)
  167. >>> r.ft().create_index(
  168. >>> (TextField("name"), TextField("lastname")),
  169. >>> definition=IndexDefinition(prefix=["test:"]),
  170. >>> )
  171. >>> r.hset("test:1", "name", "James")
  172. >>> r.hset("test:1", "lastname", "Brown")
  173. >>> # Query with default DIALECT 2
  174. >>> query = "@name: James Brown"
  175. >>> q = Query(query)
  176. >>> res = r.ft().search(q)
  177. >>> # Query with explicit DIALECT 1
  178. >>> query = "@name: James Brown"
  179. >>> q = Query(query).dialect(1)
  180. >>> res = r.ft().search(q)
  181. ```
  182. You can find further details in the [query dialect documentation](https://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/dialects/).
  183. ### Multi-database client (Active-Active)
  184. The multi-database client allows your application to connect to multiple Redis databases, which are typically replicas of each other. It is designed to work with Redis Software and Redis Cloud Active-Active setups. The client continuously monitors database health, detects failures, and automatically fails over to the next healthy database using a configurable strategy. When the original database becomes healthy again, the client can automatically switch back to it.<br>
  185. This is useful when:
  186. 1. You have more than one Redis deployment. This might include two independent Redis servers or two or more Redis databases replicated across multiple [active-active Redis Enterprise](https://redis.io/docs/latest/operate/rs/databases/active-active/) clusters.
  187. 2. You want your application to connect to one deployment at a time and to fail over to the next available deployment if the first deployment becomes unavailable.
  188. For the complete failover configuration options and examples, see the [Multi-database client docs](https://redis.readthedocs.io/en/latest/multi_database.html).
  189. ---------------------------------------------
  190. ### Author
  191. redis-py is developed and maintained by [Redis Inc](https://redis.io). It can be found [here](
  192. https://github.com/redis/redis-py), or downloaded from [pypi](https://pypi.org/project/redis/).
  193. Special thanks to:
  194. - Andy McCurdy (<sedrik@gmail.com>) the original author of redis-py.
  195. - Ludovico Magnocavallo, author of the original Python Redis client,
  196. from which some of the socket code is still used.
  197. - Alexander Solovyov for ideas on the generic response callback
  198. system.
  199. - Paul Hubbard for initial packaging support.
  200. [![Redis](https://github.com/redis/redis-py/blob/master/docs/_static/logo-redis.svg)](https://redis.io)