Halt — Python SDK
SaaS-aware, cross-language rate limiting. Per-user / per-API-key / per-plan limits, quotas, weighted endpoints, abuse controls, atomic Redis accuracy (sync + async), and built-in observability — with a matching TypeScript package.
📖 Full documentation: halt.afroawi.com
Install
pip install halt-rate
# optional extras
pip install "halt-rate[redis]" # production store (sync + async)
pip install "halt-rate[fastapi]" # framework adapter
pip install "halt-rate[otel]" # OpenTelemetry metrics
Installs as halt-rate; import as halt.
Quick start
from halt import RateLimiter, InMemoryStore, presets
limiter = RateLimiter(
store=InMemoryStore(), # use RedisStore in production
policy=presets.PUBLIC_API, # 100 req/min per IP
)
decision = limiter.check(request) # or: await limiter.acheck(request)
if not decision.allowed:
# respond 429, Retry-After: decision.retry_after
...
Production Redis (sync + async), FastAPI/Flask/Django adapters, plan-based limits, quotas, penalties, and observability are covered in the docs → halt.afroawi.com/docs.
Resilience
Rate limiting sits in the critical path of every request, so a Redis outage or latency spike must not take down your service. Choose what happens when Redis is unavailable:
import redis
from halt import RateLimiter, RedisStore, presets
store = RedisStore(
client=redis.Redis.from_url(REDIS_URL, socket_timeout=0.2), # surface slow Redis as errors
fail_mode="fallback", # "open" (default) | "closed" | "fallback"
# circuit breaker on by default: after 5 failures, skip Redis for 5s (prevents cascades)
)
open(default) — allow the request; don't take traffic down.closed— block (429); safest for abuse-sensitive routes.fallback— evaluate against a local in-memory store (LocalStore), so limits are still enforced (per-instance, approximate) instead of blanket allow. Works withAsyncRedisStoretoo.- Circuit breaker (on by default) stops hammering a down Redis and serves from the fallback
until it recovers. Set the client's
socket_timeoutso latency spikes trip it.
Features
- Algorithms: token bucket, fixed/sliding window, leaky bucket
- Keys: IP, user, API key, composite, or custom
- Atomic Redis store (Lua, cluster-safe), sync and async, + in-memory dev store
- Resilient: configurable fail-open / fail-closed / local-fallback + built-in circuit breaker
- SaaS: per-plan limits, quotas, weighted endpoints, abuse penalties
- Observability:
StatsCollector+ OpenTelemetry metrics - Adapters: FastAPI, Flask, Django
Links
- Docs: https://halt.afroawi.com
- PyPI: https://pypi.org/project/halt-rate/
- Source & issues: https://github.com/surafel-kindu/halt
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file halt_rate-0.6.0.tar.gz.
File metadata
- Download URL: halt_rate-0.6.0.tar.gz
- Upload date:
- Size: 50.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e34daff5bc2e003176151b6260ed5caf4070b8e15a845e4becdb5ceb6484546
|
|
| MD5 |
46cbb2b0afbe510968f9cb500526b287
|
|
| BLAKE2b-256 |
668189b75fb1c9b89710aeea53e6705028279b519a0144e56559c782db400d2f
|
File details
Details for the file halt_rate-0.6.0-py3-none-any.whl.
File metadata
- Download URL: halt_rate-0.6.0-py3-none-any.whl
- Upload date:
- Size: 47.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db2a9165738da3b1ca8b38b427d7d671a1da0c8a2ca85a5e8128c0c141109b7a
|
|
| MD5 |
2803b58f901ac3af48665797af1983ea
|
|
| BLAKE2b-256 |
f6fc4138d4b45020bbca0c318a94067b0c51d426dac639a53388577503fb96c1
|