{"id":5711,"library":"ratelim","title":"Ratelim","description":"Ratelim is a simple Python library (version 0.1.6, last released Feb 2015) that provides decorators to limit the number of times a function can be called within a specific time interval. It's particularly useful for respecting rate limits of external APIs. It supports both greedy and patient rate limiting strategies and preserves the function signature. This library has not been updated since 2015.","status":"maintenance","version":"0.1.6","language":"en","source_language":"en","source_url":"http://github.com/themiurgo/ratelim","tags":["rate-limiting","decorator","api-rate-limit","throttling"],"install":[{"cmd":"pip install ratelim","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"rate_limited","correct":"from ratelim import rate_limited"},{"symbol":"RateLimitException","correct":"from ratelim import RateLimitException"}],"quickstart":{"code":"import time\nfrom ratelim import rate_limited, RateLimitException\n\nn_calls = 5\nn_seconds = 10\n\n@rate_limited(calls=n_calls, period=n_seconds)\ndef limited_function():\n    print(f\"Calling limited_function at {time.time()}\")\n\nprint(f\"Attempting to call limited_function {n_calls + 2} times over {n_seconds} seconds...\")\nfor i in range(n_calls + 2):\n    try:\n        limited_function()\n    except RateLimitException:\n        print(f\"Rate limit exceeded for call {i+1}! Sleeping for {n_seconds} seconds...\")\n        time.sleep(n_seconds) # Manually handle retry logic\n        limited_function() # Retry after sleeping\n","lang":"python","description":"This quickstart demonstrates how to use the `@rate_limited` decorator to restrict function calls. It also shows how to catch `RateLimitException` and implement basic retry logic, as `ratelim` itself does not provide built-in `sleep_and_retry` functionality."},"warnings":[{"fix":"Consider using alternative, actively maintained libraries for rate limiting if starting a new project or if long-term support is crucial. If using `ratelim`, be aware of potential compatibility issues with newer Python versions and the lack of new features/bug fixes.","message":"The `ratelim` library has not been updated since February 2015. For new projects or applications requiring active maintenance, newer and more robust rate-limiting libraries (e.g., `pyrate-limiter`, `tomasbasham/ratelimit`) are recommended.","severity":"deprecated","affected_versions":"<=0.1.6"},{"fix":"Wrap calls to rate-limited functions in a `try...except RateLimitException` block and implement custom sleep/retry logic, as shown in the quickstart example.","message":"By default, when a rate limit is exceeded, `ratelim` raises a `RateLimitException` immediately. It does not automatically wait or retry. Users must implement their own `try-except` block and `time.sleep` (or equivalent for async) to handle waiting and retrying.","severity":"gotcha","affected_versions":"<=0.1.6"},{"fix":"For distributed or multi-process rate limiting, consider libraries that offer shared state backends (e.g., Redis, database), such as `pyrate-limiter` or `upstash-ratelimit`.","message":"The `ratelim` library uses in-memory counters, making it unsuitable for distributed systems or multi-process applications where rate limits need to be coordinated across multiple instances or processes.","severity":"gotcha","affected_versions":"<=0.1.6"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}