Python rate limiting libraries

Updated Nov 2026

Python rate limiting libraries cap how many requests a client can make in a time window or how fast a program sends outgoing calls. A limiter counts hits per key under a strategy such as a fixed window or a leaky bucket. These libraries let web APIs and AI agents stay within a set request budget.

Popularity

limits has the most monthly downloads in this comparison, at 43.7M, a count that includes installs through Flask-Limiter and SlowAPI.

LibraryMonthly downloadsStarsLast releaseLicense
limits
43.7M
657Feb 2026MIT
Django REST framework
30.3M
Not on GitHubOct 2026BSD-3-Clause
slowapi
24.9M
2.1KJun 2026MIT
aiolimiter
16.0M
Not on GitHubSep 2026MIT
ratelimit
15.4M
Not on GitHubDec 2018MIT
PyrateLimiter
11.9M
534Oct 2026MIT
Flask-Limiter
7.5M
Not on GitHubDec 2025MIT
django-axes
5.0M
Not on GitHubOct 2026MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Provides rate-limiting strategies with interchangeable storage backends.

Downloads / mo
43.7M
Stars
657
Last release
5.8.0
License
MIT

Strengths

  • Shares APIs across rate strategies. Switch strategies while retaining hit, test, and window-stat methods.
  • Provides synchronous and coroutine interfaces. Use the async namespace for coroutine-based storage and strategies.

Limitations

  • Fixed windows allow boundary bursts. Use a moving-window strategy when boundary bursts are unacceptable.

Quickstart

From README.rst
$ python3.13 -m pip install limits==5.8.0
from limits import parse
from limits.storage import MemoryStorage
from limits.strategies import MovingWindowRateLimiter

limiter = MovingWindowRateLimiter(MemoryStorage())
rate = parse("1/minute")
print(limiter.hit(rate, "example"))

limits examples

From open-source projects on GitHub

Django REST framework

Builds web APIs for Django.

Downloads / mo
30.3M
Last release
3.18.3
License
BSD-3-Clause

Quickstart

From throttling.py
$ python3.13 -m pip install djangorestframework==3.18.3
from django.contrib.auth.models import AnonymousUser
from rest_framework.test import APIRequestFactory
from rest_framework.throttling import UserRateThrottle

class ExampleThrottle(UserRateThrottle):
    rate = "2/minute"

request = APIRequestFactory().get("/")
request.user = AnonymousUser()
print(ExampleThrottle().allow_request(request, view=None))

Django REST framework examples

From open-source projects on GitHub
def get_cache_key(self, request, view):
    """Use the authenticated user ID as the throttle cache key."""

    if request.user and not request.user.is_authenticated:
        return None  # Defer to RequestEntryAnonRateThrottle for anonymous users.

    return super().get_cache_key(request, view)

Adds rate limiting to Starlette and FastAPI HTTP endpoints.

Downloads / mo
24.9M
Stars
2.1K
Last release
0.1.10
License
MIT

Strengths

  • Fits asynchronous HTTP endpoints. Limit synchronous or asynchronous routes through the same wrapper.
  • Shares quotas across routes. Apply shared limits to a selected set of routes.

Limitations

  • Endpoints need a request argument. Include request in each rate-limited endpoint’s function signature.
  • Decorator order affects enforcement. Place the route decorator above the limit decorator.
  • WebSocket routes are unsupported. Use another limiter for WebSocket traffic.

Quickstart

From index.md
$ python3.13 -m pip install slowapi==0.1.10 starlette
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import PlainTextResponse
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from slowapi.util import get_remote_address

limiter = Limiter(key_func=get_remote_address)
app = Starlette()
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)

@limiter.limit("5/minute")
async def homepage(request: Request):
    return PlainTextResponse("test")

app.add_route("/home", homepage)

slowapi examples

From open-source projects on GitHub

Limits asyncio code with a leaky bucket.

Downloads / mo
16.0M
Last release
1.3.0
License
MIT

Quickstart

From index.html
$ python3.13 -m pip install aiolimiter==1.3.0
import asyncio
from aiolimiter import AsyncLimiter

async def main():
    limiter = AsyncLimiter(100)
    async with limiter:
        print("permit acquired")

asyncio.run(main())

aiolimiter examples

From open-source projects on GitHub

Limits API calls through a function decorator.

Downloads / mo
15.4M
Last release
2.2.1
License
MIT

Quickstart

From README.md
$ python3.13 -m pip install ratelimit==2.2.1
from ratelimit import limits

@limits(calls=1, period=1)
def example():
    return "permitted"

print(example())

ratelimit examples

From open-source projects on GitHub

Provides configurable bucket algorithms and storage backends for rate limiting.

Downloads / mo
11.9M
Stars
534
Last release
4.5.1
License
MIT

Strengths

  • Chooses algorithms per bucket. Set the bucket algorithm to match the allowed request pattern.
  • Can wait for available quota. Choose blocking behavior or reject immediately when the bucket is full.

Limitations

  • Sync acquisition can block. Use try_acquire_async to wait without blocking the event loop.

Quickstart

From README.md
$ python3.13 -m pip install pyrate-limiter==4.5.1
from pyrate_limiter import Duration, Rate, Limiter

limiter = Limiter(Rate(5, Duration.SECOND * 2))
print(limiter.try_acquire("my-resource"))

PyrateLimiter examples

From open-source projects on GitHub
def build_limiter(rate: str) -> Limiter:
    from pyrate_limiter import Limiter, Rate

    limit, interval = parse_units(rate)
    return Limiter(Rate(limit, interval))

Adds rate limiting to Flask applications.

Downloads / mo
7.5M
Last release
4.1.1
License
MIT

Quickstart

From api.html
$ python3.13 -m pip install flask-limiter==4.1.1 flask==3.1.3
from flask import Flask
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address

app = Flask(__name__)
limiter = Limiter(get_remote_address, app=app)

@app.get("/")
@limiter.limit("5/minute")
def index():
    return "permitted"

Flask-Limiter examples

From open-source projects on GitHub
def create_limiter(self, app: Flask) -> Limiter:
    limiter = Limiter(
        key_func=app.config.get("RATELIMIT_KEY_FUNC", get_remote_address)
    )
    limiter.init_app(app)
    return limiter

Tracks failed login attempts on Django sites.

Downloads / mo
5.0M
Last release
9.0.0
License
MIT

Quickstart

From proxy.py
$ python3.13 -m pip install django-axes==9.0.0
from django.test import RequestFactory
from axes.handlers.proxy import AxesProxyHandler

request = RequestFactory().post("/login/")
print(AxesProxyHandler.is_allowed(request, {"username": "example"}))

django-axes examples

From open-source projects on GitHub
def post(self, request, *args, **kwargs):
    user = self.get_object()
    form = self.get_form()
    if form.is_valid():
        reset(username=user.username)
        return self.form_valid(form)
    else:
        return self.form_invalid(form)

FAQ

limits suits code that needs rate-limiting strategies over Redis, Memcached, or MongoDB storage. SlowAPI and Flask-Limiter suit FastAPI, Starlette, and Flask routes. aiolimiter suits asyncio code that needs a leaky bucket limiter.

SlowAPI is a rate limiting library for Starlette and FastAPI, adapted from Flask-Limiter. It tracks limits in Redis, Memcached, or memory.

SlowAPI applies a limit decorator to each endpoint function. The route decorator must sit above the limit decorator. Each limited endpoint also takes the request as an explicit argument.

aiolimiter is an asyncio rate limiter built on the leaky bucket algorithm.

Flask-Limiter adds rate limiting to Flask applications.

For coding agents

Found your rate limiting library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official