{
  "schema_version": 2,
  "id": "develop/clients/redis-py",
  "title": "redis-py guide (Python)",
  "url": "https://redis.io/docs/latest/develop/clients/redis-py/",
  "summary": "Connect your Python application to a Redis database",
  "aliases": [
    "/develop/connect/clients/python/redis-py",
    "/develop/connect/clients/python/",
    "/develop/clients/python/",
    "/clients/python/",
    "/connect/clients/redis-py/",
    "/clients/redis-py/",
    "/develop/clients/python/redis-py/"
  ],
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-10-05T16:11:44+01:00",
  "children": [
    {
      "id": "develop/clients/redis-py/connect",
      "summary": "Connect your Python application to a Redis database",
      "title": "Connect to the server",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/connect/"
    },
    {
      "id": "develop/clients/redis-py/async",
      "summary": "Use redis-py with asyncio for non-blocking Redis access",
      "title": "Asynchronous operations with redis-py",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/async/"
    },
    {
      "id": "develop/clients/redis-py/amr",
      "summary": "Learn how to authenticate to an Azure Managed Redis (AMR) database",
      "title": "Connect to Azure Managed Redis",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/amr/"
    },
    {
      "id": "develop/clients/redis-py/queryjson",
      "summary": "Learn how to use Redis Search with JSON and hash documents.",
      "title": "Index and query documents",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/queryjson/"
    },
    {
      "id": "develop/clients/redis-py/vecsearch",
      "summary": "Learn how to index and query vector embeddings with Redis",
      "title": "Index and query vectors",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/vecsearch/"
    },
    {
      "id": "develop/clients/redis-py/vecsets",
      "summary": "Index and query embeddings with Redis vector sets",
      "title": "Vector set embeddings",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/vecsets/"
    },
    {
      "id": "develop/clients/redis-py/prob",
      "summary": "Learn how to use approximate calculations with Redis.",
      "title": "Probabilistic data types",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/prob/"
    },
    {
      "id": "develop/clients/redis-py/transpipe",
      "summary": "Learn how to use Redis pipelines and transactions",
      "title": "Pipelines and transactions",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/transpipe/"
    },
    {
      "id": "develop/clients/redis-py/scaniter",
      "summary": "Iterate through results from `SCAN`, `HSCAN`, etc.",
      "title": "Scan iteration",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/scaniter/"
    },
    {
      "id": "develop/clients/redis-py/error-handling",
      "summary": "Learn how to handle errors when using redis-py",
      "title": "Error handling",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/error-handling/"
    },
    {
      "id": "develop/clients/redis-py/failover",
      "summary": "Improve reliability using the failover features of redis-py.",
      "title": "Client-side geographic failover",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/failover/"
    },
    {
      "id": "develop/clients/redis-py/produsage",
      "summary": "Get your `redis-py` app ready for production",
      "title": "Production usage",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/produsage/"
    },
    {
      "id": "develop/clients/redis-py/observability",
      "summary": "Monitor your client's activity for optimization and debugging.",
      "title": "Observability",
      "url": "https://redis.io/docs/latest/develop/clients/redis-py/observability/"
    }
  ],
  "page_type": "content",
  "content_hash": "4d858bad12ea0becd46e98ab43fba8ed3a9a8c2129d8bfc7dd23232b300f4f17",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "[redis-py](https://github.com/redis/redis-py) is the Python client for Redis. \nThe sections below explain how to install `redis-py` and connect your application\nto a Redis database.\n\n`redis-py` requires a running Redis server. See [here](https://redis.io/docs/latest/operate/oss_and_stack/install) for Redis Open Source installation instructions.\n\nYou can also access Redis with an object-mapping client interface. See\n[RedisOM for Python](https://redis.io/docs/latest/integrate/redisom-for-python)\nfor more information."
    },
    {
      "id": "install",
      "title": "Install",
      "role": "setup",
      "text": "To install `redis-py`, enter:\n\n[code example]\n\nFor faster performance, install Redis with [`hiredis`](https://github.com/redis/hiredis) support. This provides a compiled response parser, and for most cases requires zero code changes. By default, if `hiredis` >= 1.0 is available, `redis-py` attempts to use it for response parsing.\n\n> [!NOTE]\n> The Python `distutils` packaging scheme is no longer part of Python 3.12 and greater. If you're having difficulties getting `redis-py` installed in a Python 3.12 environment, consider updating to a recent release of `redis-py`.\n\n[code example]"
    },
    {
      "id": "connect-and-test",
      "title": "Connect and test",
      "role": "content",
      "text": "Connect to localhost on port 6379, set a value in Redis, and retrieve it. All responses are returned as bytes in Python. To receive decoded strings, set `decode_responses=True`. For more connection options, see [these examples](https://redis.readthedocs.io/en/stable/examples.html).\n\nConnect to a Redis server and establish a client connection\n\n[code example]\n\n\n\nStore and retrieve a simple string.\n\nSet and retrieve string values using SET and GET commands\n\n[code example]\n\n\n\nStore and retrieve a dict.\n\nStore and retrieve hash data structures using HSET and HGETALL\n\n[code example]\n\n\n\nClose the connection when you're done.\n\nClose the Redis connection\n\n[code example]"
    },
    {
      "id": "more-information",
      "title": "More information",
      "role": "content",
      "text": "The [`redis-py`](https://redis.readthedocs.io/en/stable/index.html) website\nhas a [command reference](https://redis.readthedocs.io/en/stable/commands.html)\nand some [tutorials](https://redis.readthedocs.io/en/stable/examples.html) for\nvarious tasks. There are also some examples in the\n[GitHub repository](https://github.com/redis/redis-py) for `redis-py`.\n \nSee also the other pages in this section for more information and examples:"
    }
  ],
  "examples": [
    {
      "id": "install-ex0",
      "language": "bash",
      "code": "pip install redis",
      "section_id": "install"
    },
    {
      "id": "install-ex1",
      "language": "bash",
      "code": "pip install redis[hiredis]",
      "section_id": "install"
    },
    {
      "id": "connect-and-test-ex0",
      "language": "python",
      "code": "import redis\nr = redis.Redis(host='localhost', port=6379, decode_responses=True)",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex1",
      "language": "python",
      "code": "r.set('foo', 'bar')\n# True\nr.get('foo')\n# bar",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex2",
      "language": "python",
      "code": "r.hset('user-session:123', mapping={\n    'name': 'John',\n    \"surname\": 'Smith',\n    \"company\": 'Redis',\n    \"age\": 29\n})\n# True\n\nr.hgetall('user-session:123')\n# {'surname': 'Smith', 'name': 'John', 'company': 'Redis', 'age': '29'}",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex3",
      "language": "python",
      "code": "r.close()",
      "section_id": "connect-and-test"
    }
  ]
}
