Registry / http-networking / ratelim

ratelim

JSON →
library0.1.6pypypi✓ verified 24d ago

Ratelim is a simple Python library (version 0.1.6, last released Feb 2015) that provides decorators to limit the number of times a function can be called within a specific time interval. It's particularly useful for respecting rate limits of external APIs. It supports both greedy and patient rate limiting strategies and preserves the function signature. This library has not been updated since 2015.

pip install ratelim
INSTALL
IMPORT
SIG · RATELIM
R
ratelim
http-networkingpythonv0.1.6
Install
1.7s avg
Import
35ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.6 · 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.036s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.034s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

rate_limited
from ratelim import greedy
from ratelim import rate_limited
rate_limited
from ratelim import patient
from ratelim import rate_limited

This quickstart demonstrates how to use the `@rate_limited` decorator to restrict function calls. It also shows how to catch `RateLimitException` and implement basic retry logic, as `ratelim` itself does not provide built-in `sleep_and_retry` functionality.

import time from ratelim import rate_limited, RateLimitException n_calls = 5 n_seconds = 10 @rate_limited(calls=n_calls, period=n_seconds) def limited_function(): print(f"Calling limited_function at {time.time()}") print(f"Attempting to call limited_function {n_calls + 2} times over {n_seconds} seconds...") for i in range(n_calls + 2): try: limited_function() except RateLimitException: print(f"Rate limit exceeded for call {i+1}! Sleeping for {n_seconds} seconds...") time.sleep(n_seconds) # Manually handle retry logic limited_function() # Retry after sleeping
Debug
Known issues
deprecatedThe `ratelim` library has not been updated since February 2015. For new projects or applications requiring active maintenance, newer and more robust rate-limiting libraries (e.g., `pyrate-limiter`, `tomasbasham/ratelimit`) are recommended.
fix
Consider using alternative, actively maintained libraries for rate limiting if starting a new project or if long-term support is crucial. If using `ratelim`, be aware of potential compatibility issues with newer Python versions and the lack of new features/bug fixes.
affects: <=0.1.6
gotchaBy default, when a rate limit is exceeded, `ratelim` raises a `RateLimitException` immediately. It does not automatically wait or retry. Users must implement their own `try-except` block and `time.sleep` (or equivalent for async) to handle waiting and retrying.
fix
Wrap calls to rate-limited functions in a `try...except RateLimitException` block and implement custom sleep/retry logic, as shown in the quickstart example.
affects: <=0.1.6
gotchaThe `ratelim` library uses in-memory counters, making it unsuitable for distributed systems or multi-process applications where rate limits need to be coordinated across multiple instances or processes.
fix
For distributed or multi-process rate limiting, consider libraries that offer shared state backends (e.g., Redis, database), such as `pyrate-limiter` or `upstash-ratelimit`.
affects: <=0.1.6
Upgrade
Version history
0.1.6latest on PyPI · released Feb 27, 2015
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
Amazon
2
Resources
ratelim — pip install ratelim · libregistry