skillfed

pyrate-limiter

Python Rate-Limiter using Leaky-Bucket Algorithm

pyrate-limiter v4.4.0 7.9M downloads/30d#1,683 on PyPI512
Permissive license MIT Active released

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-limiter

uv

uv add pyrate-limiter

poetry

poetry add pyrate-limiter

Installing 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

Development Status :: 5 - Production/StableOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software Development :: DocumentationTopic :: Software Development :: Libraries :: Python ModulesTyping :: Typed

Tags

rate limiter pythonleaky bucket algorithmasync rate limitingrequest throttlingper-key rate limitsredis rate limiterapi quota enforcement
rate-limitingasync-friendlydistributed

More Python Modules packages