Function Rate Limiter
A simple Python library to rate limit function calls to a specific number of times per second/minute.
Installation
pip install .
Usage
You can use the @rate_limit decorator to easily limit how frequently a function is executed.
Blocking (Wait)
By default, the rate limiter will block and wait until the function is allowed to run.
import time
from function_rate_limiter import rate_limit
# Allow 2 calls per 5 seconds
@rate_limit(max_calls=2, period=5)
def print_hello():
print(f"Hello at {time.strftime('%X')}")
for _ in range(5):
print_hello()
Non-Blocking (Raise Exception)
If you don't want the function to block, set wait=False. It will raise a RateLimitExceeded exception instead.
from function_rate_limiter import rate_limit, RateLimitExceeded
@rate_limit(max_calls=2, period=5, wait=False)
def quick_task():
print("Doing work...")
try:
for _ in range(5):
quick_task()
except RateLimitExceeded as e:
print(f"Error: {e}")
Metadata
Release files for function-rate-limiter 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| function_rate_limiter-0.1.1.tar.gz | 1.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| function_rate_limiter-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 4.5 kB
Release files / function_rate_limiter-0.1.1.tar.gz
| Download URL | function_rate_limiter-0.1.1.tar.gz |
|---|---|
| Size | 1.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c4b5a2b65b4e7b00f74ee0f978cec698ab66d447f88990132211229937d4032f
|
|
BLAKE2b-256 checksum How to use checksums |
f0d7de4837706733ee583b2c57d8a199dd813cee88abc6c0aa9770be35e8c5eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / function_rate_limiter-0.1.1-py3-none-any.whl
| Download URL | function_rate_limiter-0.1.1-py3-none-any.whl |
|---|---|
| Size | 2.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8353b96464272934302a55a189e7532df7d9e872af04e1a75723fb819be084a3
|
|
BLAKE2b-256 checksum How to use checksums |
d5d17d1e4d85c72b161bb8cd2e06d1e31e4490d6c259a5f710b533c1f709bd2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|