{"id":8589,"library":"rejson","title":"rejson (Deprecated: use redis-py for RedisJSON features)","description":"rejson-py is a Python client library for RedisJSON, a Redis module that implements the JSON data type. It provides an extended interface to redis-py, offering on-the-fly serialization and deserialization of JSON objects. As of `redis-py` version 4.0.0, this library is deprecated, and its functionalities have been integrated directly into the `redis-py` client. The `rejson` package is currently at version 0.5.6 and has a very slow release cadence, with the last update in November 2021.","status":"deprecated","version":"0.5.6","language":"en","source_language":"en","source_url":"https://github.com/RedisJSON/redisjson-py","tags":["redis","json","database","client","deprecated","redisjson"],"install":[{"cmd":"pip install rejson","lang":"bash","label":"For the deprecated rejson-py client"},{"cmd":"pip install redis","lang":"bash","label":"Recommended: For RedisJSON features in redis-py (v4.0.0+)"}],"dependencies":[{"reason":"rejson-py extends the redis-py client.","package":"redis","optional":false}],"imports":[{"note":"This import is for the deprecated rejson-py library. For modern RedisJSON usage, use `from redis import Redis` and access JSON commands via `redis_client.json()`.","wrong":"from redis import Redis","symbol":"Client","correct":"from rejson import Client, Path"},{"note":"This import is for the deprecated rejson-py library.","symbol":"Path","correct":"from rejson import Client, Path"}],"quickstart":{"code":"import os\nfrom rejson import Client, Path\nimport json\n\n# Ensure a RedisJSON server is running, e.g., via Docker:\n# docker run -d -p 6379:6379 redislabs/rejson:latest\n\nREDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')\nREDIS_PORT = int(os.environ.get('REDIS_PORT', 6379))\n\ntry:\n    # Using the deprecated rejson-py client\n    rj = Client(host=REDIS_HOST, port=REDIS_PORT)\n\n    obj = {\n        'name': 'Alice',\n        'age': 30,\n        'city': 'New York',\n        'hobbies': ['reading', 'hiking'],\n        'address': {'street': '123 Main St', 'zip': '10001'}\n    }\n\n    # Set a JSON object at the root path\n    rj.jsonset('user:1', Path.rootPath(), obj)\n    print(f\"Set JSON for user:1: {obj}\")\n\n    # Get a specific field\n    name = rj.jsonget('user:1', Path('.name'))\n    print(f\"User's name: {name}\")\n\n    # Update a field\n    rj.jsonset('user:1', Path('.age'), 31)\n    updated_age = rj.jsonget('user:1', Path('.age'))\n    print(f\"Updated user's age: {updated_age}\")\n\n    # Append to an array\n    rj.jsonarrappend('user:1', Path('.hobbies'), 'coding')\n    hobbies = rj.jsonget('user:1', Path('.hobbies'))\n    print(f\"User's hobbies after appending: {hobbies}\")\n\n    # --- Recommended modern approach using redis-py (v4.0.0+) ---\n    # from redis import Redis\n    # r = Redis(host=REDIS_HOST, port=REDIS_PORT)\n    # r.json().set('user:2', Path.root_path(), {'email': 'bob@example.com'})\n    # email = r.json().get('user:2', Path('.email'))\n    # print(f\"User 2 email (via redis-py): {email}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure a Redis server with the ReJSON module is running and accessible.\")","lang":"python","description":"This quickstart demonstrates basic operations (set, get, update, append) using the `rejson-py` client. It requires a running Redis server with the RedisJSON module loaded. A commented-out section shows the equivalent approach using the recommended `redis-py` client (v4.0.0+)."},"warnings":[{"fix":"Migrate your code to use the `redis.Redis().json()` interface from the `redis` library. This is the recommended and actively maintained way to interact with RedisJSON from Python. For example, instead of `rj.jsonset('key', Path.rootPath(), data)`, use `r.json().set('key', Path.root_path(), data)`.","message":"The `rejson-py` library is deprecated since `redis-py` version 4.0.0. All its features for interacting with RedisJSON have been merged into the official `redis-py` client.","severity":"breaking","affected_versions":"rejson-py all versions, redis-py >=4.0.0"},{"fix":"Ensure your Redis server instance has the RedisJSON module loaded. This can typically be done via Docker (`docker run -p 6379:6379 redislabs/rejson:latest`) or by adding `loadmodule /path/to/rejson.so` to your `redis.conf` and restarting Redis.","message":"`rejson-py` (and the `redis-py` JSON client) requires a Redis server with the RedisJSON module specifically loaded. Installing the Python client alone is not enough; the Redis server must be configured with the module.","severity":"gotcha","affected_versions":"All versions of rejson-py and RedisJSON"},{"fix":"Explicitly specify the root path in your JSONPath expressions (e.g., `Path.rootPath()` or `Path('.')`) to avoid ambiguity, especially if interacting with different RedisJSON server versions or using RESP3.","message":"RedisJSON server module (v2.6.9+) changed the default JSONPath root from `$` to `.` under RESP3. While `rejson-py` abstracts some of this, direct path usage might be affected.","severity":"breaking","affected_versions":"RedisJSON module >=2.6.9"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install rejson` to install the deprecated client, or `pip install redis` for the recommended `redis-py` client.","cause":"The 'rejson' Python package is not installed in your environment.","error":"ImportError: No module named 'rejson'"},{"fix":"Ensure you are connecting to a Redis server that has the RedisJSON module installed and loaded. A simple way to test is to use `docker run -p 6379:6379 redislabs/rejson:latest` and configure your client to connect to `localhost:6379`.","cause":"Your Redis server does not have the RedisJSON module loaded, or you are connecting to a Redis instance without the module.","error":"redis.exceptions.ResponseError: unknown command `JSON.SET`"},{"fix":"If you intend to use `rejson-py`, ensure you import `Client` from `rejson`. If you are using `redis-py` (v4.0.0+), access JSON commands via the `json()` method of the `Redis` client, e.g., `r = Redis(); r.json().set(...)`.","cause":"You are trying to use `rejson-py` client methods (like `jsonset`) on a standard `redis.Redis` object, likely after upgrading `redis-py` or attempting to use its native JSON features without the `rejson-py` client.","error":"AttributeError: 'Redis' object has no attribute 'jsonset'"}]}