Skip to main content

django-cachex

PyPI version Python versions CI

Valkey and Redis cache backend for Django, with a Django admin UI for cache inspection. Full documentation at oliverhaas.github.io/django-cachex.

Quick Start

pip install django-cachex[valkey-py]
CACHES = {
    "default": {
        "BACKEND": "django_cachex.cache.ValkeyCache",
        "LOCATION": "valkey://127.0.0.1:6379/1",
    }
}

Features

  • One package for Valkey and Redis, standalone, Sentinel and Cluster.
  • Sync and async methods on every cache (get() and aget()), from one alias and one configuration.
  • Hash, list, set, sorted set and stream operations, and TTL and pattern helpers (ttl(), expire(), keys(), delete_pattern()).
  • Distributed locks with cache.lock().
  • Counting and weighted semaphores with cache.semaphore(), in-process or distributed.
  • Lua scripting with eval_script(), with optional key-prefixing and encoding hooks.
  • Pluggable serializers (Pickle, JSON, MsgPack, ormsgpack, orjson) and compressors (Zlib, Gzip, LZ4, LZMA, Zstandard), each with a fallback chain to migrate between formats.
  • Cache stampede prevention (TTL-based XFetch).
  • Client tracking, one option that keeps local copies of the values each process reads, kept current by the server's CLIENT TRACKING.
  • An opt-in ORM cache, django_cachex.orm, that caches ORM query results per table and invalidates them on every write.
  • LocMemCache and DatabaseCache extensions with the hash, list, set and sorted set operations, ttl()/expire()/persist(), key patterns and admin support, but no streams, locks, pipelines or Lua.
  • Experimental ValkeyGlideCache and ValkeyGlideClusterCache backends on valkey-glide, Valkey's official client with a Rust core.
  • S3Cache, which stores large values in an S3 Express One Zone or S3 Standard bucket, with parallel get_many() and set_many(). See S3 Cache.

Cache Admin

Add django_cachex.admin to INSTALLED_APPS to enable the cache admin:

INSTALLED_APPS = [
    # ...
    "django_cachex.admin",
]

The admin lists every configured cache, finds keys by wildcard pattern and type, and edits values and TTLs. It also shows server info and memory statistics, and with CACHEX_ADMIN = {"ALLOW_FLUSH": True} it flushes caches.

Cache list Key list Key detail

Requirements

  • Python 3.14+, including the free-threaded build (3.14t). On 3.14t, importing hiredis or libvalkey re-enables the GIL with a RuntimeWarning, unless you run with PYTHON_GIL=0 (or -Xgil=0).
  • Django 6.0 to 6.x (Django>=6,<7)
  • valkey-py 6.1 to 6.x (valkey>=6.1,<7) or redis-py 7.2 to 8.x (redis>=7.2,<9)
  • Valkey 7.2+ or Redis 6.2+ on the server. Installation lists the methods that need a newer server.
  • valkey-glide 2.5 to 2.x (the valkey-glide extra) for the glide backends. They need the cp314 GIL build and have no Sentinel variant.
  • obstore 0.12 (the s3 extra) for S3Cache.

Acknowledgments

This project started from django-redis and Django's official Redis cache backend. The admin UI was inspired by django-redisboard. The ORM cache is derived from django-cachalot 2.9.1 by Bertrand Bordage. The ASGI benchmark follows the shape of django-vcache's bench_compare.py (MIT, by David Burke / GlitchTip).

See also django-valkey and dj-cache-panel for related projects with similar goals.

License

MIT, see LICENSE, except for two parts under BSD-3-Clause:

  • The ORM cache, django_cachex/orm/, derived from django-cachalot. See django_cachex/orm/LICENSE.
  • Parts of django_cachex/serializers/, django_cachex/compressors/ and django_cachex/exceptions.py, derived from django-redis (Copyright (c) 2011-2016 Andrey Antukh). Each derived file says so in its header. See LICENSE.django-redis.

Metadata

Release files for django-cachex 0.15.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-cachex 0.15.0
File Size Uploaded Provenance Actions
django_cachex-0.15.0.tar.gz 268.3 kB With provenance Details for django_cachex-0.15.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-cachex 0.15.0
File Interpreter ABI Platform Actions
django_cachex-0.15.0-py3-none-any.whl Python 3 none any Details for django_cachex-0.15.0-py3-none-any.whl

Total release size: 581.2 kB

Release files / django_cachex-0.15.0.tar.gz

Download URL django_cachex-0.15.0.tar.gz
Size 268.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ca9fdf328f344c20affc7986f7034591e83aeffd3c4bd63741ec12cbb60c8115
BLAKE2b-256 checksum
How to use checksums
9509a0c980fac6ecb87647673ef3f8888403dc085b273f17a3abe722727b8e02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / django_cachex-0.15.0-py3-none-any.whl

Download URL django_cachex-0.15.0-py3-none-any.whl
Size 312.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f762eecac1eb0255e072d7143076e9f6d04c62c7605f50f8ff805f857b4eb46b
BLAKE2b-256 checksum
How to use checksums
2c1539b0348c51f127e6a4f6705e5ea2fbcfa35cc5924e8da0ed513074d6f85c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for django-cachex 0.15.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_cachex-0.15.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page