fakeredis is a drop-in replacement for redis-py and valkey-py that runs entirely in-memory. Write tests that depend on Redis, Valkey, DragonflyDB, KeyDB, or KiviDB — without spinning up a real server, a container, or a network connection.
import fakeredis
r = fakeredis.FakeStrictRedis()
r.set("foo", "bar")
r.get("foo") # b'bar'
That's it. No server to install, no port to manage, no teardown.
✨ Why fakeredis?
- 🚀 Zero setup — no Redis server, Docker, or network required. Pure Python.
- 🔌 Drop-in compatible — same API as
redis.Redisandredis.asyncio.Redis. - ⚡ Fast & isolated — in-memory, so tests run quickly and start from a clean slate.
- 🧩 Multi-backend — emulate Redis, Valkey, DragonflyDB, KeyDB, or KiviDB, and pin a specific server version.
- 📦 Redis Stack support — JSON, Bloom/Cuckoo filters, TimeSeries, and Geo commands.
- 🤝 Share or isolate state — one shared in-memory server across clients, or independent servers per test.
📥 Installation
pip install fakeredis
Optional extras enable additional command families:
pip install "fakeredis[lua]" # EVAL / EVALSHA scripting
pip install "fakeredis[json]" # JSON.* commands
pip install "fakeredis[bf]" # Bloom / Cuckoo / Count-Min / Top-K filters
pip install "fakeredis[probabilistic]" # alias for the probabilistic filters
pip install "fakeredis[valkey]" # Valkey client compatibility
🚀 Quickstart
Use it like redis.Redis:
import fakeredis
r = fakeredis.FakeStrictRedis()
r.lpush("queue", "a", "b", "c")
r.lrange("queue", 0, -1) # [b'c', b'b', b'a']
Share one in-memory server between clients:
server = fakeredis.FakeServer()
r1 = fakeredis.FakeStrictRedis(server=server)
r2 = fakeredis.FakeStrictRedis(server=server)
r1.set("greeting", "hello")
r2.get("greeting") # b'hello' — same underlying data
Async is supported too:
import fakeredis
async def main():
r = fakeredis.FakeAsyncRedis()
await r.set("foo", "bar")
await r.get("foo") # b'bar'
Pin a server type and version:
# Behave like Redis 6 — which is what KeyDB is compatible with...
r = fakeredis.FakeStrictRedis(version=6)
# ...or like Valkey, DragonflyDB or KiviDB
r = fakeredis.FakeStrictRedis(server_type="valkey")
r = fakeredis.FakeStrictRedis(server_type="dragonfly")
r = fakeredis.FakeStrictRedis(server_type="kividb")
Using it in tests (pytest)
import pytest
import fakeredis
@pytest.fixture
def redis_client():
return fakeredis.FakeStrictRedis()
def test_cache_set(redis_client):
redis_client.set("user:1", "alice")
assert redis_client.get("user:1") == b"alice"
See the official documentation for the full list of supported commands and configuration options.
❤️ Sponsor
fakeredis-py is developed and maintained for free. If it saves you time, please consider becoming a sponsor — it directly supports continued development.
🤝 Contributing
Contributions are welcome! Check out the contributing guide and the open issues to get started.
Metadata
Release files for fakeredis 2.39.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fakeredis-2.39.0.tar.gz | 301.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fakeredis-2.39.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 488.2 kB
Release files / fakeredis-2.39.0.tar.gz
| Download URL | fakeredis-2.39.0.tar.gz |
|---|---|
| Size | 301.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e89c3410f290330042638ff5cca3e22788fa267dcaf28a64b4f483e14577208d
|
|
BLAKE2b-256 checksum How to use checksums |
2f273ed3eee5e5a929345c37024b814a70f6e2452ffdab77a2680c2ebba3614a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 1, 2026.
Transparency logRelease files / fakeredis-2.39.0-py3-none-any.whl
| Download URL | fakeredis-2.39.0-py3-none-any.whl |
|---|---|
| Size | 186.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
acd1450575259634db2942d5bae93e383aac32bb9968aab29fe7b0c2ab880bb8
|
|
BLAKE2b-256 checksum How to use checksums |
35ca8bf657139922808196e6480ec6ed94008897e23d603abd5b27538cfdf811
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 1, 2026.
Transparency log