Install & Compatibility
Where this runs
tested against v0.5.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.940 runs
installs and imports cleanly · install 0.0s · import 0.679s · 70.8MB
glibcpy 3.10–3.940 runs
installs and imports cleanly · install 1.8s · import 0.562s · 20MB
69MB installed
● package 69MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Client
✓ from rejson import Client
✗ from rejson import Client
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+).
import os
from rejson import Client, Path
import json
# Ensure a RedisJSON server is running, e.g., via Docker:
# docker run -d -p 6379:6379 redislabs/rejson:latest
REDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')
REDIS_PORT = int(os.environ.get('REDIS_PORT', 6379))
try:
# Using the deprecated rejson-py client
rj = Client(host=REDIS_HOST, port=REDIS_PORT)
obj = {
'name': 'Alice',
'age': 30,
'city': 'New York',
'hobbies': ['reading', 'hiking'],
'address': {'street': '123 Main St', 'zip': '10001'}
}
# Set a JSON object at the root path
rj.jsonset('user:1', Path.rootPath(), obj)
print(f"Set JSON for user:1: {obj}")
# Get a specific field
name = rj.jsonget('user:1', Path('.name'))
print(f"User's name: {name}")
# Update a field
rj.jsonset('user:1', Path('.age'), 31)
updated_age = rj.jsonget('user:1', Path('.age'))
print(f"Updated user's age: {updated_age}")
# Append to an array
rj.jsonarrappend('user:1', Path('.hobbies'), 'coding')
hobbies = rj.jsonget('user:1', Path('.hobbies'))
print(f"User's hobbies after appending: {hobbies}")
# --- Recommended modern approach using redis-py (v4.0.0+) ---
# from redis import Redis
# r = Redis(host=REDIS_HOST, port=REDIS_PORT)
# r.json().set('user:2', Path.root_path(), {'email': 'bob@example.com'})
# email = r.json().get('user:2', Path('.email'))
# print(f"User 2 email (via redis-py): {email}")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure a Redis server with the ReJSON module is running and accessible.")
Debug
Known issues
breakingThe `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.fixMigrate 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)`. affects: rejson-py all versions, redis-py >=4.0.0
gotcha`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.fixEnsure 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.
affects: All versions of rejson-py and RedisJSON
breakingRedisJSON 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.fixExplicitly 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. affects: RedisJSON module >=2.6.9
Upgrade
Version history
0.5.6latest on PyPI · released Nov 18, 2021
Audit
Dependencies
redisrequiredrejson-py extends the redis-py client.