Registry / http-networking / ratelimiter

ratelimiter

JSON →
library1.2.0.post0pypypi✓ verified 24d ago

The `ratelimiter` library provides a simple mechanism for rate-limiting operations in Python, both synchronously (using decorators or context managers) and asynchronously (using `async with`). It allows developers to control the frequency of function calls, often useful when interacting with APIs that have usage limits. The current version is 1.2.0.post0, and the project has not seen updates since 2017, suggesting it is no longer actively maintained.

pip install ratelimiter
INSTALL
IMPORT
SIG · RATELIMITER
R
ratelimiter
http-networkingpythonv1.2.0.post0
Install
1.5s avg
Import
73ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.0.post0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.030s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.028s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RateLimiter
from ratelimiter import RateLimiter
import ratelimiter

Demonstrates both decorator and context manager usage of `RateLimiter`. It defines a limit of 2 calls per 3-second period and includes a callback to inform when rate-limiting occurs. The `time.sleep` calls simulate work and illustrate how the limiter pauses execution.

import time from ratelimiter import RateLimiter def limited_function(): print(f"Function called at {time.time()}") def callback_function(until): duration = int(round(until - time.time())) print(f'Rate limited, sleeping for {duration} seconds') # Using as a decorator @RateLimiter(max_calls=2, period=3, callback=callback_function) def do_something_decorated(item): print(f"Processing item {item} (decorated)") print("--- Decorator Example ---") for i in range(5): do_something_decorated(i) time.sleep(0.5) # Simulate some work between calls # Using as a context manager rate_limiter_cm = RateLimiter(max_calls=2, period=3, callback=callback_function) print("\n--- Context Manager Example ---") for i in range(5): with rate_limiter_cm: print(f"Processing item {i} (context manager)") time.sleep(0.5) # Simulate some work between calls
Debug
Known issues
deprecatedThe `ratelimiter` library has not been updated since December 2017. While it may still function, it is not actively maintained, meaning it might not receive bug fixes, security patches, or compatibility updates for newer Python versions or evolving best practices. Consider more actively maintained alternatives like `pyrate-limiter` or `limits` for new projects.
fix
For new projects, evaluate actively maintained alternatives. For existing projects, thoroughly test on your target Python versions.
affects: <=1.2.0.post0
gotchaThe behavior of callbacks differs between synchronous and asynchronous usage. For synchronous decorators/context managers, the `callback` function is executed in a *separate thread*, allowing it to `sleep` without blocking the main program. For `async with` usage, the `callback` must be a *coroutine* and is *not* called in a a separate thread.
fix
Ensure your callback implementation correctly handles the execution context (thread for sync, coroutine for async) and potential blocking behavior. If using `async with`, make sure the callback is `async def`.
affects: All versions
gotchaThis library is designed for in-process rate limiting. It does not inherently support distributed rate limiting across multiple processes or machines without additional external coordination (e.g., a shared Redis backend). Using it directly in a distributed system will lead to each process having its own independent rate limit.
fix
For distributed systems, consider libraries or custom implementations that integrate with shared backends like Redis or databases (e.g., `limits` or `pyrate-limiter` with appropriate backends).
affects: All versions
Upgrade
Version history
1.2.0.post0latest on PyPI · released Dec 12, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
Resources
ratelimiter — pip install ratelimiter · libregistry