Skip to content

Migrating to paceapi

Guides for moving from common Python / FastAPI rate-limiting and caching libraries to paceapi.

Supported migration guides

Rate limiting

Migrating from Primary shift Guide
slowapi Decorators + request: Request + app.state → FastAPI Depends(limiter.limit(...)) From slowapi
fastapi-limiter Global FastAPILimiter.init() / pyrate_limiter wrapper → explicit Limiter instance with built-in stores & failover From fastapi-limiter
limits Hand-rolled limits / limits.aio storage & hit() + get_window_stats() → single-round-trip Limiter with FastAPI/Starlette integration From limits

Caching

Migrating from Primary shift Guide
fastapi-cache2 Global FastAPICache.init() + wildcard KEYS/DEL clears → namespaced Cache with O(1) invalidation From fastapi-cache2
cashews Global cache.setup() + wildcard string-key invalidation → typed namespaces with O(1) scoped invalidation From cashews
aiocache Global caches registry + untyped JSON/pickle → typed Pydantic serialization, single-flight, and O(1) invalidation From aiocache

General differences across all migrations

Keep these design defaults in mind regardless of which library you are moving from:

  • No global singletons: Create Limiter and Cache instances explicitly and pass them to your app or factory. In tests, instantiate fresh objects instead of resetting global state.
  • Caller-owned Redis clients: RedisStore(client) wraps your redis.asyncio client (or RedisCluster) and never closes it. Share one store across both Limiter and Cache.
  • Fresh keyspaces on cutover: paceapi uses its own Redis key layout, so rate-limit counters and caches start fresh on deploy (old keys expire naturally via TTL; delete any legacy keys that had no expiry after cutover).
  • Async-native only: Cached functions (@ns.cached) must be async def; blocking sync functions are rejected at decoration time rather than offloaded to a thread pool.
  • Fail-open reads, fail-loud writes: Rate-limit store failures default to on_store_error="allow" (configurable to "deny", "raise", or fallback=MemoryStore()). Cache reads fail open to recomputation; cache writes and invalidations propagate errors so stale data is not left behind silently.
  • Built-in backends: Memory, Redis/Valkey (redis>=8.0.0), MongoDB (pymongo>=4.13.0), and Memcached (emcache>=1.4.0). For DynamoDB or disk caches, implement LimiterStore or CacheStore.