Skip to main content
fakeredis

A fast, pure-Python implementation of the Redis protocol — no server required.

PyPI version CI Coverage Downloads Python versions License Open Source Helpers

Documentation · Supported commands · Changelog · Sponsor


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.Redis and redis.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, Count-Min Sketch, Top-K, T-Digest, TimeSeries, and vector sets.
  • 🤝 Share or isolate state — one shared in-memory server across clients, or independent servers per test.
  • 🌐 Real TCP mode — expose the fake server over a socket with TcpFakeServer, for clients you can't inject.

📥 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
pip install "fakeredis[digest]"       # DIGEST and DELEX IFDEQ / IFDNE (XXH3 digests)
pip install "fakeredis[vectorset]"    # vector set (V*) commands, Python 3.11+

🚀 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"

🌐 TCP server mode

The fake clients above only help when you can hand one to the code under test. When the code opens its own connection — or isn't Python at all — TcpFakeServer serves the same in-memory server over a real TCP socket, so anything that speaks the Redis protocol can connect to it:

from threading import Thread

import redis
from fakeredis import TcpFakeServer

server = TcpFakeServer(("127.0.0.1", 6379), server_type="redis")
thread = Thread(target=server.serve_forever, daemon=True)
thread.start()

r = redis.Redis(host="127.0.0.1", port=6379)  # a regular client, not a fake one
r.set("foo", "bar")
r.get("foo")  # b'bar'

# When you are done:
r.close()
server.shutdown()
server.server_close()
thread.join()
  • Any client — redis-py, valkey-py, redis-cli, or a client in another language. All connections share one FakeServer, so they see the same data.
  • RESP2 and RESP3 — connections start in RESP2 and switch when the client sends HELLO 3, as with a real server. Pub/sub and blocking commands work over the socket too.
  • Server type and version — pass server_type ("redis", "valkey", "dragonfly", "kividb") and server_version (defaults to (8, 0)), e.g. TcpFakeServer(address, server_type="valkey", server_version=(8, 1)).
  • Free port — bind to port 0 to let the OS choose one, then read it back from server.server_address.

TcpFakeServer is a standard-library ThreadingTCPServer, handling each client connection on its own thread. It is meant for tests and local development, not as a production Redis replacement.

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.40.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 fakeredis 2.40.0
File Size Uploaded Provenance Actions
fakeredis-2.40.0.tar.gz 332.7 kB With provenance Details for fakeredis-2.40.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fakeredis 2.40.0
File Interpreter ABI Platform Actions
fakeredis-2.40.0-py3-none-any.whl Python 3 none any Details for fakeredis-2.40.0-py3-none-any.whl

Total release size: 536.8 kB

Release files / fakeredis-2.40.0.tar.gz

Download URL fakeredis-2.40.0.tar.gz
Size 332.7 kB
Tags Source
SHA-256 checksum
How to use checksums
16eb05a3e97c37a033c73d1da7e885eb2aa47ba7604cc377144339efa2780a02
BLAKE2b-256 checksum
How to use checksums
61d08cbd1339c2a606a0ceda74e1a181248d372bb2c66bc6cf9d954871839ff9
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 14, 2026.

Transparency log

Release files / fakeredis-2.40.0-py3-none-any.whl

Download URL fakeredis-2.40.0-py3-none-any.whl
Size 204.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b155ef2442134372eb1cc5664cf5638ccbe0a6dde9d1942153708e2782f315c9
BLAKE2b-256 checksum
How to use checksums
c7e46919d3653d72c53d1fb22c97ceb6fa3664cad302994e90ee52279f7eb394
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 14, 2026.

Transparency log

Security for fakeredis 2.40.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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fakeredis-2.40.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 Oct 14, 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.

Release history Release notifications | RSS feed

This release

2.40.0 This release

2 release files Full provenance

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