No project description provided
Project description
Rate Limiting Decorator
This Python module provides a rate_limit_decorator
that allows you to limit the rate at which a function can be called. It supports both synchronous and asynchronous functions, making it versatile for various applications.
Features
- Rate Limiting: Control the maximum number of function calls within a given time interval.
- Support for Asynchronous and Synchronous Functions: The decorator works seamlessly with both types of functions.
- Easy Integration: Simply apply the decorator to your function, and it will handle rate limiting for you.
Usage
Here’s a basic example of how to use the rate_limit_decorator
:
Synchronous
from rate_limit_guard import rate_limit_decorator
@rate_limit_decorator(interval=1, max_calls=5)
def my_function():
print("Function is called")
def main():
try:
for _ in range(10):
my_function()
except RuntimeError:
# this will be raised after the rate limit is reached
pass
Asynchronous
from rate_limit_guard import rate_limit_decorator
import asyncio
@rate_limit_decorator(interval=1, max_calls=5)
async def my_async_function():
print("Async function is called")
await asyncio.sleep(0.5)
async def main():
try:
for _ in range(10):
await my_async_function()
except RuntimeError:
# this will be raised after the rate limit is reached
pass
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
rate_limit_guard-0.1.0.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for rate_limit_guard-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a1b2a84e5cea2d2e10b224be554554a1cedd7ee2ca859dab20fe38af1b6d355 |
|
MD5 | ac6e9aafbb9e35e5afde530e873cd337 |
|
BLAKE2b-256 | f32f88622a049ec93e0db5c4d83693c896113e043c54813c7bb8fcdc26e80e04 |