Registry / web-framework / asgi-ratelimit

asgi-ratelimit

JSON →
library0.10.0pypypi✓ verified 80d ago

ASGI middleware for rate limiting requests using a token bucket algorithm. Current version 0.10.0, requires Python >=3.6,<4.0. Release cadence is irregular.

pip install asgi-ratelimit
INSTALL
IMPORT
SIG · ASGI-RATELIMIT
A
asgi-ratelimit
web-frameworkpythonv0.10.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.10.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RateLimitMiddleware
from ratelimit import RateLimitMiddleware
from asgi_ratelimit import RateLimitMiddleware
Rule
from ratelimit import Rule

Basic rate limiting middleware wrapping an ASGI app.

from asgi_ratelimit import RateLimitMiddleware, RateLimit app = RateLimitMiddleware( some_asgi_app, auth_func=lambda scope: scope["client"][0], limiter=RateLimit(10, 60) # 10 requests per 60 seconds )
Debug
Known issues
gotchaThe `auth_func` must return a hashable string (e.g., IP, user ID). Returning a tuple or non-hashable will cause a runtime TypeError.
fix
Ensure auth_func returns a string, e.g., lambda scope: scope['client'][0].
affects: all
gotchaRate limiter backends (Redis, memory) must be configured explicitly; default is in-memory dictionary (not shared across processes).
fix
For distributed apps, pass a Redis backend: from asgi_ratelimit import RedisBackend; RateLimitMiddleware(..., backend=RedisBackend('redis://localhost')).
affects: all
deprecatedThe `backend` parameter in v0.9+ changed; the old direct class import `from asgi_ratelimit.backends import RedisBackend` may break if using newer structuring.
fix
Use correct top-level import: `from asgi_ratelimit import RedisBackend` or check version for exact path.
affects: >=0.9.0
Upgrade
Version history
0.10.0latest on PyPI · released Dec 7, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
34 hits · last 30 days
node
28
OpenAI (training)
1
Resources
asgi-ratelimit — pip install asgi-ratelimit · libregistry