79565599

Date: 2025-04-10 01:53:49
Score: 0.5
Natty:
Report link

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
Reasons:
  • Contains signature (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: crayon