Modern rate limiting
for APIs & SaaS
Drop-in middleware with safe defaults, observability hooks, and distributed storage support. Works the same in Python and TypeScript.
pip install halt-ratefrom fastapi import FastAPI
from halt import RateLimiter, InMemoryStore, presets
from halt.adapters.fastapi import HaltMiddleware
app = FastAPI()
limiter = RateLimiter(
store=InMemoryStore(),
policy=presets.PUBLIC_API # 100 req/min
)
app.add_middleware(HaltMiddleware, limiter=limiter)Downloads
Halt at work
Halt sits between your clients and your handlers as a middleware. It identifies who is calling, counts their requests against a policy, and forwards or blocks each one in well under a millisecond your route code never changes. Watch a 4-requests-per-window policy handle a burst of six:
Client
fetch("/api/data", {
headers: { "x-api-key": "team_pro_key" }
});Halt Middleware
const limiter = new RateLimiter({...});
app.use(haltMiddleware(limiter));API Server
app.get("/api/data", async (req, res) => {
return res.json({ ok: true });
});Accepted 1 rapid requests
Live logs
12:41:01 req_id=8f1 user=team_pro check=pass remaining=3
12:41:01 forwarded=true target="/api/data" status=200 latency=25ms
1 · Identify
Each request is keyed by IP, user, or API key you pick the strategy, including composite keys like user:ip.
2 · Count
The counter for that key is read from your store (in-memory, Redis, Postgres…) and checked against the policy's limit.
3 · Decide
Within the limit, the request is forwarded untouched. Over it, Halt answers 429 before your handler ever runs.
4 · Respond
Every response carries RateLimit-* headers, and blocked ones add Retry-After so well-behaved clients back off on their own.
When the window expires the counters reset automatically burst-friendly algorithms like Token Bucket even refill gradually, so steady clients are never starved.
Why Halt
Everything you need for reliable limits
Production-grade algorithms, storage, and telemetry in one toolkit.
4 Algorithms
Token Bucket, Fixed Window, Sliding Window, and Leaky Bucket.
6 Storage Backends
Memory, Redis (atomic), PostgreSQL, MongoDB, DynamoDB, Memcached.
SaaS-Ready
Plans, quotas, penalties, weighted endpoints, per-plan tagging.
Built-in Observability
StatsCollector for a /halt/stats endpoint + OpenTelemetry metrics adapter.
Framework Support
FastAPI, Flask, Django, Express, Next.js adapters built-in.
Smart Defaults
Health-check exemptions, private IP allowlist, RateLimit-* headers.
Supported stack
Frameworks, storage, and algorithms
Everything you need is grouped below with direct links and compact summaries.
Frameworks
8 itemsStorage Backends
6 itemsOpen source
Built in the open contribute to Halt
Halt is MIT-licensed and developed as a monorepo with the Python and TypeScript SDKs side by side. Bug reports, docs fixes, new adapters, and storage backends are all welcome.
Start hacking in minutes
Python 3.8+ · Node 18+# Grab the monorepo
git clone https://github.com/surafel-kindu/halt.git
cd halt
# Python SDK packages/python
pip install -e ".[dev]"
pytest
# TypeScript SDK packages/typescript
npm install
npm run build && npm testDev setup, code style (black, ruff, mypy on Python; ESLint on TypeScript), and how to send your first PR.
Read CONTRIBUTING.mdFound an edge case in an algorithm or adapter? Open an issue a small reproduction goes a long way.
Open an issuepackages/python the core limiter plus FastAPI, Flask, and Django adapters, tested with pytest.
Browse the sourcepackages/typescript Express and Next.js adapters, kept in feature parity with the Python SDK.
Browse the sourceReady to protect your API?
Install halt-rate and add bulletproof rate limiting to any service.