Registry / database / django-valkey

django-valkey

JSON →
library0.4.1pypypi✓ verified 90d ago

A modern, high-performance Valkey (and Redis) cache backend for Django. Version 0.4.0 supports Python >=3.10, Django 4.2-6.0, and includes advanced serialization (msgpack, zstd, msgspec), cluster support, async clients, and connection sharding. Released under the BSD license.

pip install django-valkey
INSTALL
IMPORT
SIG · DJANGO-VALKEY
D
django-valkey
databasepythonv0.4.1
Install
3.7s avg
Import
288ms
Disk
71MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.4.1 · 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
musl
glibc
py 3.10
✓ —
✓ 3.75s
py 3.11
✓ —
✓ 3.68s
py 3.12
✓ —
✓ 3.68s
py 3.13
✓ —
✓ 3.58s
py 3.9
✕ build_error
✕ build_error
71MB installed
● package 71MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cache
✓ from django.core.cache import cache
✗ from django_valkey import cache
django-valkey integrates as a Django cache backend; you import the standard Django cache object.
get_valkey_connection
✓ from django_valkey import get_valkey_connection

Configure django-valkey as your default cache backend.

# In settings.py: CACHES = { "default": { "BACKEND": "django_valkey.cache.ValkeyCache", "LOCATION": "valkey://127.0.0.1:6379/1", "OPTIONS": { "CLIENT_CLASS": "django_valkey.client.DefaultClient", } } } # In your code: from django.core.cache import cache cache.set("my_key", "hello world", timeout=60) print(cache.get("my_key"))
Debug
Known issues
breakingIn version 0.2.1, floats are no longer serialized to support atomic float operations. If your code relied on serialization of floats (e.g., storing float as string), you may need to adjust.
fix
None needed unless you were reading serialized floats from older versions; ensure compatibility.
affects: >=0.2.1
breakingIn version 0.3.0, `make_key`, `make_pattern`, `encode`, and `decode` became module-level functions (not just backend methods). If you were overriding them in a custom backend, update your code.
fix
Use `from django_valkey import make_key` instead of `self.make_key`.
affects: 0.3.0+
gotchaThe backend class is `django_valkey.cache.ValkeyCache`, not `django_valkey.cache.RedisCache` (the old name from django-redis). Using wrong backend name will cause ImportError.
fix
Use `'BACKEND': 'django_valkey.cache.ValkeyCache'` in CACHES settings.
affects: all
deprecatedThe old `BaseConnectionPool` class was renamed to `BaseConnectionFactory` in version 0.1.4. Using the old name will trigger a deprecation warning and may be removed.
fix
Use `BaseConnectionFactory` instead of `BaseConnectionPool`.
affects: >=0.1.4
Errors
Common errors & fixes
ImportError: cannot import name 'ValkeyCache' from 'django_valkey.cache'
You might have installed an old version (<0.1.0) or wrote the import path incorrectly.
fix
Ensure you have django-valkey installed and use: from django_valkey.cache import ValkeyCache
django.core.cache.backends.base.InvalidCacheBackendError: Could not find backend 'django_valkey.cache.ValkeyCache'
The BACKEND path in CACHES settings is incorrect.
fix
Set BACKEND to 'django_valkey.cache.ValkeyCache' and ensure django-valkey is installed.
redis.exceptions.ConnectionError: Error 111 connecting to 127.0.0.1:6379. Connection refused.
Valkey/Redis server is not running or unreachable.
fix
Start a Valkey/Redis server: valkey-server (or redis-server) or check LOCATION in settings.
Upgrade
Version history
0.4.1latest on PyPI · released May 6, 2026
Audit
Dependencies
djangorequiredCore framework dependency.
valkeyrequiredPython client for Valkey (compatible with redis-py).
msgpackoptionalAlternative serializer (faster than default JSON).
pyzstdoptionalAlternative serializer for compression.
msgspecoptionalFast serialization format supported since 0.4.0.
hiredisoptionalC-based parser for improved performance.
Agent activity
10 hits · last 30 days
node
10
Resources
django-valkey — pip install django-valkey · libregistry