HaltModern Rate Limiting v0.5.0 / v0.5.0

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.

PyPI
pip install halt-rate
main.pyFastAPI middleware
from 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

Refreshed daily
Total · last 30 days
501
157 in the last 7 days
npm
501
157 in the last week
PyPI
in the last week

Works with your stack

Popular frameworks and storage engines, ready out of the box.

FastAPI
Express
Next.js
Redis
PostgreSQL
MongoDB

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:

Allowed · 200

Client

fetch("/api/data", {
  headers: { "x-api-key": "team_pro_key" }
});
req#1req#2req#3req#4req#5req#6

Halt Middleware

const limiter = new RateLimiter({...});

app.use(haltMiddleware(limiter));
Policy check passed

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.

8 frameworks6 storage backends4 algorithms

Frameworks

8 items
FastAPI
FastAPI

High-performance Python web framework.

Flask
Flask

Lightweight Python microframework.

Django
Django

Batteries-included Python framework.

Express
Express

Minimal Node.js web framework.

Next.js
Next.js

React framework for fullstack web.

Hono
Hono

Tiny, ultrafast — runs on Node, edge, and serverless.

Fastify
Fastify

Fast and low-overhead Node.js framework.

GraphQL
GraphQL (Apollo)

Per-operation rate limits via an Apollo plugin.

Storage Backends

6 items
In-Memory
In-Memory

Local, development-only store.

Redis
Redis

Atomic, cluster-safe limits — recommended for production.

PostgreSQL
PostgreSQL

Relational store with strong consistency.

MongoDB
MongoDB

Document store with TTL indexes.

DynamoDB
DynamoDB

AWS serverless key-value store.

Memcached
Memcached

Distributed cache for fast lookups.

Algorithms

4 items

Token Bucket

Burst-friendly

Fixed Window

Simple & fast

Sliding Window

Most accurate

Leaky Bucket

Traffic shaping

Open 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.

Ship rate limits in minutes

Ready to protect your API?

Install halt-rate and add bulletproof rate limiting to any service.