Repolode
ZhuoZhuoCrayon

ZhuoZhuoCrayon/throttled-py

Python rate limiting library offering Fixed Window, Sliding Window, Token Bucket, Leaky Bucket and GCRA algorithms with Redis or in-memory storage.

Stars
649
Forks
36
Open issues
10
Last commit
4 days ago

What is it?

throttled-py is a Python library for rate limiting function calls and API requests. It supports five algorithms (Fixed Window, Sliding Window, Token Bucket, Leaky Bucket and GCRA) that can be selected through the `using` parameter, and quotas can be written as readable strings such as "100/s burst 200".

The library offers both synchronous and asynchronous APIs, and calls can be made as plain function calls, decorators, or context managers. Counters are kept in an in-memory LRU store with expiration, or in Redis in standalone, Sentinel, or Cluster mode. Calls can return immediately or wait and retry up to a timeout.

It includes official integrations for FastAPI and Flask that add decorator-based limits, RateLimit-* response headers and HTTP 429 handling. It also provides an OpenTelemetry hook option and integration with the MCP Python SDK.

Key features

  • 01Five rate limiting algorithms: Fixed Window, Sliding Window, Token Bucket, Leaky Bucket and GCRA.
  • 02Synchronous and asynchronous APIs with function call, decorator and context manager usage.
  • 03Redis storage in standalone, Sentinel and Cluster modes, plus an in-memory store with expiration and LRU eviction.
  • 04Wait-and-retry mode with a configurable timeout.
  • 05Official FastAPI and Flask integrations with HTTP 429 handling.

Use cases

  • Throttling outbound calls to a third-party API that enforces request quotas.
  • Limiting requests per user or IP on a FastAPI or Flask service.
  • Sharing rate limit state across multiple application instances through Redis.
  • Controlling request bursts in async Python workers.

Topics

FAQ

What is throttled-py?
Python rate limiting library offering Fixed Window, Sliding Window, Token Bucket, Leaky Bucket and GCRA algorithms with Redis or in-memory storage. throttled-py is a Python library for rate limiting function calls and API requests. It supports five algorithms (Fixed Window, Sliding Window, Token Bucket, Leaky Bucket and GCRA) that can be selected through the `using` parameter, and quotas can be written as readable strings such as "100/s burst 200".
Is throttled-py free to use? What license does it have?
throttled-py is open source under the MIT license. Check the license terms before using it in commercial products.
Is throttled-py still maintained?
Actively maintained. The last commit to throttled-py was on Oct 18, 2026.
What can I use throttled-py for?
Throttling outbound calls to a third-party API that enforces request quotas. Limiting requests per user or IP on a FastAPI or Flask service. Sharing rate limit state across multiple application instances through Redis. Controlling request bursts in async Python workers.
Where can I get throttled-py?
The source code and installation instructions are on GitHub: https://github.com/ZhuoZhuoCrayon/throttled-py

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects