fakeredis
A pure-Python, in-memory implementation of the Redis protocol for testing.
Repository Health
Technical Analysis
fakeredis is a drop-in replacement for redis-py and valkey-py that implements the Redis protocol entirely in memory, with no server, container, or network connection required. You instantiate a FakeStrictRedis (or its async equivalent) exactly where you would use a real client, and your code runs against a fast, isolated in-memory store.
Beyond core Redis commands, fakeredis emulates Redis Stack features such as JSON, Bloom and Cuckoo filters, TimeSeries, and Geo commands, and can pin the behavior of specific Redis, Valkey, DragonflyDB, or KeyDB versions. This makes it ideal for unit tests that need deterministic, dependency-free Redis behavior.
What You Get
- A drop-in FakeStrictRedis client compatible with redis-py’s synchronous and asyncio APIs
- Fully in-memory operation with no server, Docker, or network dependency
- Emulation of Redis Stack modules: JSON, Bloom/Cuckoo filters, TimeSeries, TopK, and Geo
- Shared or per-client isolated in-memory servers for flexible test setups
- Multi-backend support for Redis, Valkey, DragonflyDB, and KeyDB with version pinning
Common Use Cases
- Unit-testing Redis-backed application code without a running Redis server
- Running fast, isolated CI test suites that need Redis semantics
- Emulating Redis Stack data structures in tests without extra infrastructure
- Prototyping Redis-dependent logic locally with zero setup
Under The Hood
Architecture - The core is a fake socket layer: _basefakesocket.py and _fakesocket.py parse the Redis wire protocol and dispatch commands, backed by an in-process _server.py that holds the keyspace. Command behavior is organized into mixins under commands_mixins/ and stack/ (for example _json_mixin.py, _bf_mixin.py, _timeseries_mixin.py), each implementing a family of commands. A generated commands.json and _command_args_parsing.py drive argument validation, and aioredis.py adapts the same machinery to the asyncio client. Client construction routes through _client_setup.py, letting FakeStrictRedis mirror redis-py’s constructor surface.
Tech Stack - Pure Python targeting modern versions, packaged with pyproject.toml and uv lockfiles. It integrates directly with redis-py/valkey-py client types, with optional extras pulling in dependencies for JSON and probabilistic data-structure support.
Code Quality - Testing is extensive and a first-class concern: the test/ tree includes async tests, Redis Stack tests, hypothesis-based property tests, and backend-specific suites (e.g. DragonflyDB), with CI coverage reporting. The mixin-per-command-family layout keeps the large command surface maintainable, and the package ships py.typed for type checking.
API Design - Developer experience is excellent because the API is deliberately identical to redis-py: fakeredis.FakeStrictRedis() behaves like a real client, so adoption requires essentially no learning. Additional capabilities are opt-in through install extras and standard client keyword arguments.
Used by 4 apps in this directory
Agno
Devops · AI Development · Automation
Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.
Dragonfly
Databases · Developer Tools · Devops
A modern Redis and Memcached replacement engineered for multi-core servers — delivering 25x more throughput, better cache hit rates, and up to 80% lower memory consumption with full API compatibility.
Label Studio
AI Development · Data Engineering
Label Studio is an open-source, multi-type data labeling platform that lets teams annotate images, text, audio, video, and time series data with a configurable XML-based UI and export annotations in formats ready for any ML framework.
Rasa Open Source
AI Assistants · AI Development
Rasa Open Source is a Python machine learning framework for building contextual, multi-turn chatbots and voice assistants that understand natural language and maintain conversation state.