coredis
Fully-typed async Redis client for Python with native cluster, sentinel, and structured-concurrency support via anyio.
Repository Health
Technical Analysis
coredis is an async Redis client for Python built on anyio, so the same codebase runs unmodified on either asyncio or trio. It targets teams that want strict typing end to end — including through pipelines, Lua scripts, and Redis functions — plus first-class support for Redis Cluster and Sentinel topologies rather than bolt-on extras.
Beyond the core command surface, coredis ships server-assisted client-side caching, support for Redis Stack modules (JSON, search, timeseries, autocomplete), pub/sub and stream consumer helpers, and optional OpenTelemetry instrumentation. Performance-sensitive modules such as the RESP parser and response packer are compiled with mypyc, and the library is tested against Redis, Valkey, and Dragonfly, making it a viable driver for any RESP-compatible backend.
What You Get
- Redis, RedisCluster, and Sentinel client classes with a consistent, fully-typed command API
- Structured concurrency via anyio, so the same client code runs on asyncio or trio backends
- Server-assisted client-side caching for reducing round trips on hot keys
- Redis Stack module support (JSON, search, timeseries, autocomplete)
- Pipelining, Lua scripting, Redis functions, and a stream consumer abstraction
- Optional OpenTelemetry instrumentation and optional beartype runtime type validation
Common Use Cases
- Building async web services (FastAPI, Starlette, aiohttp) that need a typed Redis client
- Connecting to Redis Cluster or Sentinel-managed primary/replica setups from async code
- Using Redis-protocol-compatible databases like Valkey or Dragonfly as a drop-in backend
- Implementing client-side caching to cut latency on frequently-read keys
- Running trio-based applications that need a Redis client without an asyncio dependency
Under The Hood
Architecture
coredis is organized in clearly separated layers: client/ exposes the public Redis, RedisCluster, and Sentinel entry points; commands/ implements the RESP command surface, request routing, and validators as mixins shared across client variants; connection/ and pool/ own the TCP/Unix-socket/cluster/sentinel connection primitives and their pooling strategies; and cluster/ isolates topology discovery, slot layout, and node management so cluster-awareness doesn’t leak into the base client. Client-side caching lives in patterns/cache.py, and the RESP protocol parser and response packer are factored into standalone modules deliberately chosen for mypyc compilation, showing the codebase is architected around isolating performance-critical serialization from the rest of the async control flow.
Tech Stack
coredis is built on anyio for structured concurrency across asyncio and trio, with beartype for optional runtime type checking, opentelemetry-sdk for tracing/metrics, and exceptiongroup/typing_extensions/packaging for compatibility shims. The build uses hatchling with hatch-vcs for versioning and hatch-mypyc to compile hot-path modules (parser, packer, utility functions) into native extensions for performance, all managed through uv. Documentation is built with Sphinx, and integration tests run against real Redis, cluster, and sentinel instances via docker-compose.
Code Quality
The test suite spans over fifty files under tests/, covering the basic client, cluster client, individual command groups, connection pooling, pub/sub, Lua locks, retries, encoding, and Redis Stack modules, run with pytest-asyncio plus pytest-mypy-plugins (to test type stubs) and pytest-memray (to catch memory regressions). mypy runs in strict mode with disallow_untyped_defs, disallow_any_generics, and warn_return_any all enabled, and ruff enforces linting; three separate GitHub Actions workflows handle CI, wheel builds, and cross-version compatibility testing.
What Makes It Unique Most Python Redis clients are asyncio-only; coredis’s use of anyio lets the same client run on trio without a separate codepath, while still keeping full type inference through pipelines, Lua scripts, and Redis functions — a combination few alternatives in the ecosystem offer. Compiling its serialization hot paths with mypyc and testing against Valkey and Dragonfly in addition to Redis itself further sets it apart as a client built for both correctness and raw throughput.