FastAPI Redis¶
Official FastAPI integration for Redis - connection management and DI-based caching with automatic key consistency.
Idiomatic Redis for FastAPI: manage connection pools through the app lifespan,
cache responses and rate-limit endpoints with native Depends() factories, and
get OpenTelemetry instrumentation out of the box. Install with
pip install fastapi-redis-sdk (Python 3.10+, Redis 7.4+).
Documentation¶
Getting Started¶
- Installation - supported versions and how to install with pip, uv, or Poetry.
- Quick Start - wire up Redis and cache your first endpoint in a handful of lines.
User Guide¶
- Architecture - the decisions behind the library: why dependency injection over decorators, the connection lifecycle, the strings-vs-hashes storage model, and the telemetry layers.
- Caching - the
cache()/cache_evict()/cache_put()factories, the imperativeCacheBackend, caching Pydantic models, and HTTP cache headers (ETag,Cache-Control,304). - Rate Limiting - distributed per-client limits:
the per-route dependency and global limiter, the fluent rate language,
identifiers, and
X-RateLimit-*/Retry-Afterheaders. - Observability - OpenTelemetry spans and metrics for cache and rate-limit operations, and how to enable each layer.
- Configuration - Pydantic-Settings configuration
and the full
REDIS_*environment variable reference. - Benchmarks - performance measured against popular caching libraries.
API Reference¶
- API Reference - public functions, DI dependencies, and classes.
- Configuration API -
RedisSettingsfields plus theCoderandKeyBuildertypes.