throttled-py supports multiple algorithms (Fixed Window, Sliding Window, Token Bucket, Leaky Bucket & GCRA) and storage backends (Redis, in-memory), enabling function-level rate limiting across diverse scenarios.
import requests
from throttled import Throttled, rate_limter, exceptions
# Default: Token Bucket algorithm
@Throttled(key="/posts", quota=rate_limter.per_sec(10))
def api_call():
try:
response = requests.get('https://jsonplaceholder.typicode.com/posts', timeout=1)
except Exception as e:
response = e
return response