Response Bandwidth Limiter
Read this in other languages: English, 日本語
Response Bandwidth Limiter lets you configure a transfer speed limit for each endpoint in FastAPI and Starlette. The limit applies independently to each response.
It can also reject, delay, or throttle requests based on request counts. Group requests by IP address, API key, user, or another identifier, and use Redis to share counters across workers.
Installation
Requires Python 3.10 or later. For the FastAPI example below, install the library, FastAPI, and the Uvicorn server:
python -m pip install response-bandwidth-limiter fastapi uvicorn
For Starlette applications, see Installation and usage.
Quick Start
Save the following as main.py:
from fastapi import FastAPI, Request
from starlette.responses import PlainTextResponse
from response_bandwidth_limiter import ResponseBandwidthLimiter
app = FastAPI()
limiter = ResponseBandwidthLimiter()
@app.get("/download")
@limiter.limit(1024) # 1024 bytes per second
async def download(request: Request):
return PlainTextResponse("payload" * 4096)
limiter.init_app(app)
Register routes first, then call limiter.init_app(app) to install the middleware. Each response from /download is limited to 1,024 bytes per second; concurrent responses each have their own limit.
From the directory containing main.py, start the server:
python -m uvicorn main:app --host 127.0.0.1 --port 8000
Open http://127.0.0.1:8000/download in your browser. The response contains 28 KiB of repeated payload text and takes about 28 seconds to finish transferring at the configured rate. This delay is intentional.
Key Considerations
- Request counters and IP block / allow state are process-local by default. Use Redis to share them across workers; runtime configuration updates still remain process-local.
- Enable
trusted_proxy_headersonly behind a trusted reverse proxy that rewrites or sanitizes client IP headers. init_app()handles shutdown signals by default. Setinstall_signal_handlers=Falseto manage shutdown in your application. See Shutdown behavior for details.- Actual transfer speed also depends on network conditions.
Documentation
| Topic | Contents |
|---|---|
| Installation and usage | FastAPI, Starlette, optional dependencies, shutdown behavior |
| Request-count policies and scopes | limit_rules, action priority, IP / API-key / user grouping |
| Redis, runtime updates, and migration | Shared counters, endpoint identifiers, limitations, migration from key_func |
| API reference | Public methods, storage, rules, custom actions |
| Development and distribution checks | Compatibility tests, wheel verification, release process |
Runnable examples are in example/.
Project
Acknowledgements
This library was inspired by slowapi (MIT Licensed).
License
Metadata
Release files for response-bandwidth-limiter 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| response_bandwidth_limiter-0.2.2.tar.gz | 50.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| response_bandwidth_limiter-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 85.0 kB
Release files / response_bandwidth_limiter-0.2.2.tar.gz
| Download URL | response_bandwidth_limiter-0.2.2.tar.gz |
|---|---|
| Size | 50.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9e8dc6c5086995f3b27246ff60e34688defbc9b66b47139587aeb2527a89f79
|
|
BLAKE2b-256 checksum How to use checksums |
541b5ba7609d3eea4bb51b2ec0eddb3734f6d756115f664771732e3b35fe51b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.
Transparency logRelease files / response_bandwidth_limiter-0.2.2-py3-none-any.whl
| Download URL | response_bandwidth_limiter-0.2.2-py3-none-any.whl |
|---|---|
| Size | 34.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fac0c54b4fe13a8a7dd88d9cd17dd8a260c038b61808a6dd79a835c5376f1a9b
|
|
BLAKE2b-256 checksum How to use checksums |
c2269496403b07c9e6dedba9ca335753876ea5b344b1b95fd1a672c1c633d4b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.
Transparency log