A rate limiting extension for Starlette and Fastapi
Project description
SlowApi
A rate limiting library for Starlette and FastAPI adapted from flask-limiter.
This package is used in various production setups, handling millions of requests per month, and seems to behave as expected.
There might be some API changes when changing the code to be fully async
, but we will notify users via appropriate semver
version changes.
The documentation is on read the docs.
Quick start
Installation
slowapi
is available from pypi so you can install it as usual:
$ pip install slowapi
Features
Most feature are coming from FlaskLimiter and the underlying limits.
Supported now:
- Single and multiple
limit
decorator on endpoint functions to apply limits - redis, memcached and memory backends to track your limits (memory as a fallback)
- support for sync and async HTTP endpoints
- Support for shared limits across a set of routes
Limitations and known issues
- The
request
argument must be explicitly passed to your endpoint, orslowapi
won't be able to hook into it. In other words, write:
@limiter.limit("5/minute")
async def myendpoint(request: Request)
pass
and not:
@limiter.limit("5/minute")
async def myendpoint()
pass
websocket
endpoints are not supported yet.
Developing and contributing
PRs are more than welcome! Please include tests for your changes :)
The package uses poetry to manage dependencies. To setup your dev env:
$ poetry install
To run the tests:
$ pytest
Credits
Credits go to flask-limiter of which SlowApi is a (still partial) adaptation to Starlette and FastAPI.
It's also important to mention that the actual rate limiting work is done by limits, slowapi
is just a wrapper around it.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file slowapi-0.1.9.tar.gz
.
File metadata
- Download URL: slowapi-0.1.9.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.2 Linux/6.6.11-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 639192d0f1ca01b1c6d95bf6c71d794c3a9ee189855337b4821f7f457dddad77 |
|
MD5 | 726be5caae0edc822299b16099894e0f |
|
BLAKE2b-256 | a099adfc7f94ca024736f061257d39118e1542bade7a52e86415a4c4ae92d8ff |
File details
Details for the file slowapi-0.1.9-py3-none-any.whl
.
File metadata
- Download URL: slowapi-0.1.9-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.2 Linux/6.6.11-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfad116cfb84ad9d763ee155c1e5c5cbf00b0d47399a769b227865f5df576e36 |
|
MD5 | ce24d08cec75be692f8f7ebb624a9a24 |
|
BLAKE2b-256 | 2bbbf71c4b7d7e7eb3fc1e8c0458a8979b912f40b58002b9fbf37729b8cb464b |