A Python web framework for building APIs with standard type hints, offering automatic validation, OpenAPI docs and high performance.
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
An in-memory data store that is API-compatible with Redis and Memcached, aiming to be a drop-in replacement for both.
Opinionated best practices and conventions for building production FastAPI applications, drawn from startup experience.
A lightweight ASGI framework and toolkit for building async web services and APIs in Python.
Distributed task queue for Python that runs background jobs and schedules work across workers and message brokers.
Open source home automation platform that runs locally and puts control and privacy first, often on a Raspberry Pi or local server.