Python implementation of redis API, can be used for testing purposes.
Project description
A fast, pure-Python implementation of the Redis protocol — no server required.
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, or KeyDB — 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, or KeyDB, 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...
r = fakeredis.FakeStrictRedis(version=6)
# ...or like Valkey
r = fakeredis.FakeStrictRedis(server_type="valkey")
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fakeredis-2.36.1.tar.gz.
File metadata
- Download URL: fakeredis-2.36.1.tar.gz
- Upload date:
- Size: 211.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7240567f4e1c07a2b3d30c0fd88e5e598e948c2e25850a560727de1d1d3dc946
|
|
| MD5 |
94b9e5c3a8da9812e127e6ad67d50657
|
|
| BLAKE2b-256 |
1f48c08ec5c1d0d16e15247787b83d9b2a9cb1f1a27514cd85407956040cc383
|
Provenance
The following attestation bundles were made for fakeredis-2.36.1.tar.gz:
Publisher:
publish-pypi.yml on cunla/fakeredis-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fakeredis-2.36.1.tar.gz -
Subject digest:
7240567f4e1c07a2b3d30c0fd88e5e598e948c2e25850a560727de1d1d3dc946 - Sigstore transparency entry: 1749186232
- Sigstore integration time:
-
Permalink:
cunla/fakeredis-py@2d73f3f94e72c277d63b2cb8b9b465c46e297247 -
Branch / Tag:
refs/tags/v2.36.1 - Owner: https://github.com/cunla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d73f3f94e72c277d63b2cb8b9b465c46e297247 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fakeredis-2.36.1-py3-none-any.whl.
File metadata
- Download URL: fakeredis-2.36.1-py3-none-any.whl
- Upload date:
- Size: 139.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
220a77bebb985c59076951336478c4c983be76b5d9f44d3011dd61171d082062
|
|
| MD5 |
d4583464b830fb7cc565d43ff3630b79
|
|
| BLAKE2b-256 |
c7941f993adaa735f2922d991e1e66e64f2de1bf044bee601d03dde5b71513d4
|
Provenance
The following attestation bundles were made for fakeredis-2.36.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on cunla/fakeredis-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fakeredis-2.36.1-py3-none-any.whl -
Subject digest:
220a77bebb985c59076951336478c4c983be76b5d9f44d3011dd61171d082062 - Sigstore transparency entry: 1749186372
- Sigstore integration time:
-
Permalink:
cunla/fakeredis-py@2d73f3f94e72c277d63b2cb8b9b465c46e297247 -
Branch / Tag:
refs/tags/v2.36.1 - Owner: https://github.com/cunla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d73f3f94e72c277d63b2cb8b9b465c46e297247 -
Trigger Event:
release
-
Statement type: