fakeredis

A pure-Python, in-memory implementation of the Redis protocol for testing.

Library
PyPI
v2.37.1
454stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
87/100Excellent
Development Activity100
Maintenance100
Community64
Maturity56
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
84/100Excellent
Architecture84
Code Quality85
Innovation80
Learning Curve88

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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search