Adds rate limiting to Flask applications with global defaults, per-route limits, blueprint rules, and exempt routes. State can persist in memory or external stores via the limits library.
Overview
Flask-Limiter is an extension that adds rate limiting to Flask applications. Limits can be defined application-wide, as defaults on routes, per blueprint, on class-based views, or on individual endpoints with decorators.
Configuration options include storage backends such as in-memory storage, Redis, Memcached, MongoDB, Valkey, and Redis cluster URIs through the limits library. Strategies include fixed-window, moving-window, and sliding-window-counter limiters. Requests are keyed by a chosen function, commonly the client remote address.
When a limit is exceeded, the view is not called and the extension raises an HTTP 429 error. Built-in Flask static file routes are exempt from default limits unless configured otherwise. An optional Flask CLI subcommand lists effective limits and configuration after installing the cli extra.
Installation is through pip, with optional extras for each storage backend and for the command-line inspection tools. The extension initializes either in the Limiter constructor with the app or via deferred init_app.
Key features
- Per-route limit decorators
- Global default rate limits
- Blueprint-level limiting
- Route exemption support
- Redis and Memcached backends
- Multiple rate limit strategies
- Flask CLI limit inspection
- Custom rate limit key functions
Use cases
- Protecting public Flask API endpoints
- Throttling abusive clients by IP
- Shared limits across blueprint modules
- Production limits backed by Redis
- Development testing with in-memory storage