Skip to main content

⏲️ Rate-limiting, thread-safe and asynchronous decorators + context managers that implement the token-bucket algorithm.

Project description

limiter: Easy rate limiting for Python

limiter makes it easy to add rate limiting to Python projects, using a token bucket algorithm. limiter can provide Python projects and scripts with:

Here are a few benefits of using limiter:


You can define dynamic and static limiters, and use them across your project.

Dynamic limit

You can define a limiter with a set rate and capacity. Then you can consume a dynamic amount of tokens from different buckets using limit():

from limiter import get_limiter, limit

BURST_RATE: int = 3
MSG_BUCKET: bytes = b'messages'

limiter = get_limiter(rate=REFRESH_RATE, capacity=BURST_RATE)

def download_page(url: str) -> bytes:

@limit(limiter, consume=2)
async def download_page(url: str) -> bytes:

def send_page(page: bytes):
    with limit(limiter, consume=1.5):

async def send_page(page: bytes):
    async with limit(limiter):

@limit(limiter, bucket=MSG_BUCKET)
def send_email(to: str):

async def send_email(to: str):
    async with limit(limiter, bucket=MSG_BUCKET):

Static limit

You can define a static limit and share it between blocks of code:

limit_downloads = limit(limter, consume=2)

def download_page(url: str) -> bytes:

async def download_page(url: str) -> bytes:

def download_image(url: str) -> bytes:
    with limit_downloads:

async def download_image(url: str) -> bytes:
    async with limit_downloads:



  • Python 3.7+

Installing from PyPI

python3 -m pip install limiter


See LICENSE. If you'd like to use this project with a different license, please get in touch.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

limiter-0.2.0.tar.gz (15.7 kB view hashes)

Uploaded Source

Built Distribution

limiter-0.2.0-py2.py3-none-any.whl (15.9 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page