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
Metadata
Release files for halt-rate 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| halt_rate-0.6.0.tar.gz | 50.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| halt_rate-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 97.6 kB
Release files / halt_rate-0.6.0.tar.gz
| Download URL | halt_rate-0.6.0.tar.gz |
|---|---|
| Size | 50.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e34daff5bc2e003176151b6260ed5caf4070b8e15a845e4becdb5ceb6484546
|
|
BLAKE2b-256 checksum How to use checksums |
668189b75fb1c9b89710aeea53e6705028279b519a0144e56559c782db400d2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / halt_rate-0.6.0-py3-none-any.whl
| Download URL | halt_rate-0.6.0-py3-none-any.whl |
|---|---|
| Size | 47.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db2a9165738da3b1ca8b38b427d7d671a1da0c8a2ca85a5e8128c0c141109b7a
|
|
BLAKE2b-256 checksum How to use checksums |
f6fc4138d4b45020bbca0c318a94067b0c51d426dac639a53388577503fb96c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Security for halt-rate 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.