A Python library to rate limit functions and commands.
Project description
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}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file function_rate_limiter-0.1.1.tar.gz.
File metadata
- Download URL: function_rate_limiter-0.1.1.tar.gz
- Upload date:
- Size: 1.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4b5a2b65b4e7b00f74ee0f978cec698ab66d447f88990132211229937d4032f
|
|
| MD5 |
2e1451fa71ce1b0e00d2b835cbc92351
|
|
| BLAKE2b-256 |
f0d7de4837706733ee583b2c57d8a199dd813cee88abc6c0aa9770be35e8c5eb
|
File details
Details for the file function_rate_limiter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: function_rate_limiter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8353b96464272934302a55a189e7532df7d9e872af04e1a75723fb819be084a3
|
|
| MD5 |
85ef5e557d3c46e5f866325a3bd2a731
|
|
| BLAKE2b-256 |
d5d17d1e4d85c72b161bb8cd2e06d1e31e4490d6c259a5f710b533c1f709bd2a
|