pyrate-limiter
Python Rate-Limiter using Leaky-Bucket Algorithm
What it is and what it does
PyrateLimiter is a rate-limiting library that enforces request quotas using the Leaky-Bucket algorithm. It allows you to define multiple simultaneous rate limits (e.g., 5 per second and 1000 per hour) on the same key, and routes each key to a bucket that tracks and throttles incoming requests. The library works in both sync and async contexts, offering blocking (wait for a permit), non-blocking (fail fast), and timeout-based acquisition modes.
The package supports multiple storage backends: in-memory buckets for single-process use, SQLite for persistence, Redis (sync and async) for distributed systems, Postgres for shared state, and multiprocessing for worker pools. You can use it directly via `try_acquire()` calls, as a decorator on functions, or as a context manager. The same API works identically in sync and async code paths without blocking the event loop.
Use it for:
- Enforce API rate limits on web services (e.g., 100 requests per minute per user)
- Throttle background job workers to avoid overwhelming downstream services
- Distribute rate limits across multiple processes or machines using Redis or Postgres
- Implement per-resource quotas in multi-tenant applications with independent tracking
- Decorate async functions to prevent concurrent request spikes without blocking
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
PyrateLimiter implements the Leaky-Bucket rate-limiting algorithm with support for multiple simultaneous rate limits, pluggable backends (in-memory, SQLite, Redis, Postgres, multiprocessing), and both sync and async APIs.
Yes. PyrateLimiter is a mature, well-maintained library with zero known vulnerabilities, no runtime dependencies, and permissive licensing. It solves a common problem (rate limiting) with a clean API that works seamlessly in both sync and async code. Install it if you need to enforce request quotas or throttle access to resources.
Install
pyrate-limiter on PyPI
pip
pip install pyrate-limiteruv
uv add pyrate-limiterpoetry
poetry add pyrate-limiterInstalling pyrate-limiter
Before you install
Low friction: pure Python wheel with no runtime dependencies. Active maintenance with a recent release (61 days ago) and 512 repository stars. Supports Python 3.10 through 3.14.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects with minimal obligations.
Quickstart
pip install pyrate-limiter
from pyrate_limiter import Duration, Rate, Limiter
limiter = Limiter(Rate(5, Duration.SECOND * 2))
limiter.try_acquire("my-resource")
Requires Python 3.10 or later.
Verify before relying
- Performance characteristics under high concurrency or with large numbers of keys
- Behavior and overhead of each backend option (in-memory vs. Redis vs. Postgres) at scale
- Exact semantics of the leaking mechanism and background cleanup scheduling
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 61 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 7,896,876/month — #1,683 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pyrate_limiter-4.4.0-py3-none-any.whl
Keywords: aiohttp, httpx, leaky-bucket, limiter, rate, rate-limiter, rate_limiter, ratelimit, ratelimiter, ratelimiting, requests, throttle
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
requests-ratelimiterAdds rate-limiting to the requests library by…
permissive · top 5,000 on PyPI
rushrush provides rate-limiting algorithms…
permissive · top 15,000 on PyPI
fastapi-limiterAdds request rate limiting to FastAPI routes…
permissive · top 5,000 on PyPI
throttled-pyImplements rate limiting with multiple…
permissive · top 15,000 on PyPI
httpx-limiterProvides rate-limited HTTP transports for httpx…
permissive · top 15,000 on PyPI
aiolimiterImplements a rate limiter for asyncio using the…
permissive · top 5,000 on PyPI
asynciolimiterProvides rate limiting for async Python code by…
permissive · top 5,000 on PyPI
limitsImplements rate limiting with multiple…
permissive · top 1,000 on PyPI
slowapiAdds rate limiting to Starlette and FastAPI…
permissive · top 1,000 on PyPI
upstash-ratelimitProvides connectionless rate limiting for…
permissive · top 15,000 on PyPI