{"id":5925,"library":"fastapi-limiter","title":"FastAPI Limiter","description":"fastapi-limiter is a Python library that provides robust request rate limiting capabilities for FastAPI applications. It integrates with Redis as a backend to store and manage rate limit counters. Currently at version 0.2.0, it's an early-stage project with releases driven by feature additions and bug fixes, and primarily supports Python 3.9 and above.","status":"active","version":"0.2.0","language":"python","source_language":"en","source_url":"https://github.com/long2ice/fastapi-limiter","tags":["fastapi","rate-limiting","redis","security","async"],"install":[{"cmd":"pip install fastapi-limiter redis","lang":"bash","label":"Install FastAPI Limiter with Redis client"}],"dependencies":[{"reason":"The `redis` library (specifically `redis>=4.0` for asyncio support) is required to provide the Redis client functionality, which serves as the backend for all rate limiting operations.","package":"redis","optional":false}],"imports":[{"symbol":"FastAPILimiter","correct":"from fastapi_limiter import FastAPILimiter"},{"symbol":"RateLimiter","correct":"from fastapi_limiter.depends import RateLimiter"},{"note":"For asynchronous FastAPI applications, ensure you import the asyncio-compatible Redis client (`redis.asyncio.Redis`) to prevent blocking the event loop. The synchronous client is only appropriate for blocking contexts.","wrong":"from redis import Redis","symbol":"Redis","correct":"from redis.asyncio import Redis"}],"quickstart":{"code":"import os\nfrom fastapi import FastAPI, Depends\nfrom fastapi_limiter import FastAPILimiter\nfrom fastapi_limiter.depends import RateLimiter\nfrom redis.asyncio import Redis # Use asyncio for FastAPI\n\napp = FastAPI()\n\n# Configure Redis URL via environment variable or default to localhost\nREDIS_URL = os.environ.get('REDIS_URL', 'redis://localhost:6379')\n\n@app.on_event('startup')\nasync def startup():\n    redis_client = Redis.from_url(REDIS_URL, encoding='utf8', decode_responses=True)\n    await FastAPILimiter.init(redis_client)\n    print(\"FastAPILimiter initialized.\")\n\n@app.get('/', dependencies=[Depends(RateLimiter(times=2, seconds=5))])\nasync def homepage():\n    return {'message': 'Hello world!'}\n\n@app.get('/limited', dependencies=[Depends(RateLimiter(times=1, seconds=10))])\nasync def limited_endpoint():\n    return {'message': 'This endpoint is more limited!'}\n\n# To run this example:\n# 1. Install uvicorn: pip install uvicorn\n# 2. Run Redis locally (e.g., via Docker: docker run --name some-redis -p 6379:6379 -d redis)\n# 3. Save the code as main.py\n# 4. Execute: uvicorn main:app --reload\n","lang":"python","description":"This quickstart demonstrates how to initialize `fastapi-limiter` with an async Redis client during FastAPI's application startup event. It then applies different rate limits to two distinct endpoints using the `RateLimiter` dependency. The Redis connection uses an environment variable for configuration."},"warnings":[{"fix":"Ensure `FastAPILimiter.init` is properly awaited within an asynchronous startup function linked to `@app.on_event('startup')`.","message":"You must explicitly call `await FastAPILimiter.init(redis_client)` during your FastAPI application's startup event (e.g., in `@app.on_event('startup')`). Failing to do so will result in the rate limiter not being initialized and will cause errors when endpoints attempt to use it.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Import `Redis` from `redis.asyncio` and ensure all Redis client operations are `await`ed.","message":"For async FastAPI applications, always use `redis.asyncio.Redis` (or methods like `Redis.from_url` from `redis.asyncio`) for your Redis client. Using the synchronous `redis.Redis` directly in an `async def` context will block the event loop, leading to performance degradation and concurrency issues.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"It is highly advisable to pin your dependency to an exact version (e.g., `fastapi-limiter==0.2.0`) and carefully review changelogs or GitHub releases before upgrading.","message":"As a 0.x.x version library, `fastapi-limiter` may introduce breaking changes in minor or patch releases without strictly adhering to semantic versioning. The API surface may evolve rapidly.","severity":"breaking","affected_versions":"All 0.x.x versions"},{"fix":"Ensure you include `redis` in your project's dependencies and install it (e.g., `pip install redis`).","message":"The `redis` library, which provides the Redis client, is a peer dependency and not automatically installed alongside `fastapi-limiter`. You must install it separately for the library to function.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.2.0':37 '3.9':58 'addit':50 'applic':19 'async':67 'backend':26 'bug':52 'capabl':16 'counter':33 'current':34 'driven':47 'earli':42 'early-stag':41 'fastapi':1,4,18,61 'fastapi-limit':3 'featur':49 'fix':53 'integr':21 'librari':9 'limit':2,5,15,32,64 'manag':30 'primarili':55 'project':44 'provid':11 'python':8,57 'rate':14,31,63 'rate-limit':62 'redi':23,65 'releas':46 'request':13 'robust':12 'secur':66 'stage':43 'store':28 'support':56 'version':36","created_at":"2026-04-14T18:34:23.545988+00:00","updated_at":"2026-04-16T14:56:34.192199+00:00","problems":{"verify_error":"error: Failed to parse: `fastapi-limiter redis`\n  Caused by: Expected one of `@`, `(`, `<`, `=`, `>`, `~`, `!`, `;`, found `r`\nfastapi-limiter redis\n                ^"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.2.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/long2ice/fastapi-limiter","docs":"https://github.com/long2ice/fastapi-limiter","changelog":null,"pypi":"https://pypi.org/project/fastapi-limiter/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","http-networking","database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"install_fail","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-05","install_tag":null}}