A request rate limiter for FastAPI applications, powered by pyrate-limiter.
FastAPI-Limiter is a rate limiting library for FastAPI applications that helps control the number of requests clients can make to your API endpoints. It integrates seamlessly with FastAPI's dependency injection system and provides flexible rules to prevent abuse, ensure fair usage, and protect backend resources. The library supports both HTTP routes and WebSocket connections, making it versatile for various API scenarios.
FastAPI developers building public or private APIs that need protection against excessive requests, DDoS mitigation, or usage-based access control. It's particularly useful for developers who want a lightweight, dependency-injection-friendly rate limiter that aligns with FastAPI's design patterns.
Developers choose FastAPI-Limiter because it's specifically built for FastAPI, offering a clean, intuitive API that leverages FastAPI's dependency system. Unlike generic rate limiters, it provides built-in support for WebSocket rate limiting, conditional skipping, and easy integration via middleware or per-route dependencies, all while being powered by the robust `pyrate-limiter` library.
A request rate limiter for fastapi
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Leverages FastAPI's dependency injection system, as shown by using Depends(RateLimiter(...)) in route definitions, making it intuitive for FastAPI developers.
Utilizes pyrate-limiter's Rate and Duration classes to define custom limits, such as Rate(2, Duration.SECOND * 5) for granular control over request rates.
Provides WebSocketRateLimiter for rate limiting data sent over WebSocket connections, demonstrated in the websocket endpoint example, which is rare among FastAPI rate limiters.
Allows skipping rate limiting with async callables and custom callbacks for exceeded limits, as illustrated in the skip and callback sections for tailored responses.
Relies on pyrate-limiter which is likely in-memory by default, making it unsuitable for multi-instance deployments without additional setup for persistent storage like Redis.
Requires pyrate-limiter for core functionality, which may introduce compatibility issues or limit features to what pyrate-limiter offers, such as basic rate algorithms.
Focuses on basic fixed-window rate limiting; lacks native support for more complex scenarios like token bucket algorithms or integration with external auth systems without custom code.