Skip to main content

ratelimit-lite

A lightweight, client-side rate limiter for outbound API calls — no database required. Works entirely in memory by default, with optional Redis support for coordinating limits across multiple processes or pods.

Install

pip install ratelimit-lite

For Redis support:

pip install ratelimit-lite[redis]

Quickstart

from ratelimit_lite.limiter import Limiter
from ratelimit_lite.decorator import rate_limited

limiter = Limiter(algorithm="sliding_window", backend="memory", limit=50, window_size=60)

@rate_limited(limiter, key="weather_api")
def call_weather_api():
    ...

Or use it as a context manager:

with limiter.acquire("weather_api"):
    call_weather_api()

By default, a blocked call raises RateLimitExceeded. Pass wait=True to block and retry automatically instead:

@rate_limited(limiter, key="weather_api", wait=True)
def call_weather_api():
    ...

Algorithms

  • "fixed_window" — simple counter that resets every window_size seconds. Fast and predictable, but allows brief bursts near window boundaries.
  • "sliding_window" — weighted counter that blends the previous and current window, avoiding boundary bursts. Recommended default for most use cases.

Backends

  • "memory" — in-process, no dependencies. State resets on restart and does not coordinate across multiple processes.
  • "redis" — coordinates limits across multiple processes or pods, using Lua scripts for atomicity. Requires a running Redis server.
from ratelimit_lite.limiter import Limiter

# uses localhost:6379 by default
limiter = Limiter(algorithm="sliding_window", backend="redis", limit=50, window_size=60)

To use a custom Redis connection, pass a configured client directly:

import redis
from ratelimit_lite.stores.redis_store import RedisStore

custom_client = redis.Redis(host="my-redis-host", port=6379)
store = RedisStore(redis_client=custom_client)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ratelimit_lite-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ratelimit_lite-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file ratelimit_lite-0.1.0.tar.gz.

File metadata

  • Download URL: ratelimit_lite-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for ratelimit_lite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f63f2286098eaa588283161c9132de698d4e79522d5c7d135890b1d1e720bf31
MD5 97162b7b603786472f857bd101e1624b
BLAKE2b-256 0001db23a4b8b3ee0f01c1dcd80b93928312ea94c78a75d91831d45fbb086dbe

See more details on using hashes here.

File details

Details for the file ratelimit_lite-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ratelimit_lite-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.3

File hashes

Hashes for ratelimit_lite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43b9897c7237ad5f4514147b8c0e7015644495fc770f0403c91ace38ac2b6a0b
MD5 74c211b6c4748c7f32e0a405fea7874d
BLAKE2b-256 ee95ab74e698bb87baeeee29f18fe70c6b2a5c74386088ed7d2f3564731e6b2b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page