Embedded persistent rate limiting for Python, powered by Rust
Project description
Why Flint
I was tired of adding Redis just to rate limit a local Python service.
Most rate limiters are either in-memory and reset on restart, tied to HTTP proxies, or require a separate infrastructure service. Flint embeds inside the Python process and persists counter state to a local append-only log.
The result is simple:
Python process + .flint/ directory = durable rate limiting
What Flint Does
Flint is an embedded rate limiter with:
- Rust core;
- Python bindings via PyO3;
- append-only AOF persistence;
- single-writer data directory locking;
- GIL-aware Python API;
- CLI inspect/admin commands;
- token bucket algorithm;
- sliding window log algorithm;
- fixed window counter algorithm;
- crash recovery from local files;
- no Redis, daemon, broker, or cloud dependency.
Comparison
| Solution | Persistent | No Redis | Embedded | Observable |
|---|---|---|---|---|
| Flint | Yes | Yes | Yes | Yes |
| SlowAPI | No | Yes | Yes | No |
| redis-py + limits | No | No | No | No |
| nginx rate limit | No | Yes | No | No |
Flint's unique advantage is the combination of persistent counters and zero external infrastructure.
Install
pip install flint-limiter
The Python module is:
import flint
Quickstart
import flint
limiter = flint.Limiter(data_dir=".flint")
limiter.limit(
"api:user-42",
rate=100,
per="1m",
algorithm="token_bucket",
)
if limiter.allow("api:user-42"):
process_request()
With context:
result = limiter.check("api:user-42")
print(result.allowed)
print(result.remaining)
print(result.reset_at)
CLI
flint limit add "api:user-42" --rate 100 --per 1m --algorithm token_bucket
flint limit list
flint limit status "api:user-42"
flint limit reset "api:user-42"
flint limit history "api:user-42"
Use a custom data directory:
flint --data-dir /var/lib/myapp/flint limit status "api:user-42"
Algorithms
| Algorithm | Use case |
|---|---|
token_bucket |
Smooth rate limiting with bursts |
sliding_window_log |
Precise rolling-window limits |
fixed_window_counter |
Simple high-throughput window counters |
Storage
Flint stores state under data_dir:
.flint/
flint.aof
flint.lock
The AOF records durable events:
LIMIT_CONFIGURED
ALLOW
DENY
RESET
On restart, Flint replays the log and restores counters. A crash-truncated final line is ignored deterministically; corruption in the middle of the log fails loudly.
What Flint Replaces
Flint replaces:
- Redis-backed rate limiting libraries;
- in-memory Python limiters that reset on restart;
- nginx-only HTTP rate limiting;
- custom database counters;
- hand-written local counters with no history.
The unique property is persistent rate limiting without Redis.
Build And Test
cargo fmt --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
Python:
python3 -m venv .venv
.venv/bin/pip install -U pip maturin pytest
.venv/bin/maturin develop
.venv/bin/python -m pytest -q tests/python
License
BSD 3-Clause.
Project details
Release history Release notifications | RSS feed
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 flint_limiter-0.1.0.tar.gz.
File metadata
- Download URL: flint_limiter-0.1.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
271be5738506bf9ea783c76d437946215943cdf42be18459b43f9c9665e3b854
|
|
| MD5 |
4413d0bcc8dc4935d88a9434e2c9b248
|
|
| BLAKE2b-256 |
97fd7afe4e8085d518d4f43e7552de1492aee58ab4c589296d5a07f2cf8f517c
|
File details
Details for the file flint_limiter-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: flint_limiter-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 373.2 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
779505d2c214d572c71dbb156943ecf327d3c00775a819f4f1619934d381f0fd
|
|
| MD5 |
14b4e158152ca72cf360d3403f8cbc7a
|
|
| BLAKE2b-256 |
076f7b62dc58c63c968cd1fbaad66e5b42985059b69ce183b6077e41fa71252e
|