Limify
Framework-agnostic, Redis-backed rate limiting engine for modern Python systems.
Limify provides a clean-architecture rate limiting core with pluggable storage adapters, async and sync support, atomic Redis Lua execution, and framework adapters.
Limify is designed as infrastructure-level software for backend engineers, microservices, and API platforms.
Documentation
https://pedram-aliniaye-asli.github.io/limify
Features
-
Framework-agnostic core
-
Async and sync Redis support
-
Atomic Redis Lua token bucket implementation
-
FastAPI / Starlette middleware adapter
-
Rule-based rate limiting with wildcard matching
-
Plan-based rate limiting support
-
Multi-identity support:
- user_id
- org_id
- api_key
- client_ip
-
Clean architecture with dependency injection
-
Pluggable storage and algorithms
-
Fully testable design
Architecture
Limify uses layered clean architecture:
Application (FastAPI / Flask / etc.)
↓
Adapter (Middleware)
↓
Limiter (Orchestrator)
↓
Resolvers
├─ RuleResolver
├─ PlanResolver
└─ KeyResolver
↓
Algorithm (Token Bucket)
↓
Storage Adapter (Redis)
Core is fully independent of frameworks.
Installation
Core only
pip install limifyrate
With FastAPI / Starlette adapter
pip install "limifyrate[fastapi]"
Development install
git clone https://github.com/pedram-aliniaye-asli/limify.git
cd limify
pip install -e ".[dev]"
Requirements
- Python 3.10+
- Redis
Quick Start (Async)
Example using async Redis and FastAPI.
import redis.asyncio as redis
from fastapi import FastAPI
from limify import Limify, LimifyConfig
from limify.adapters.fastapi.middleware import LimifyMiddleware
from limify.core.redis_adapter import RedisAsyncAdapter
from limify.core.algorithms.token_bucket import AsyncTokenBucketAlgorithm
redis_client = redis.from_url("redis://localhost:6379")
adapter = RedisAsyncAdapter(redis_client)
algorithm = AsyncTokenBucketAlgorithm(adapter)
await algorithm.initialize()
config = LimifyConfig(
rules=[
{
"id": "default",
"method": "*",
"path": "/**", # Matches all endpoints (demo only) — not recommended.
"rate": "5/minute",
"priority": 0,
},
{
"id": "items",
"method": "*",
"path": "/items",
"rate": "10/minute",
"priority": 10,
},
]
)
limify = Limify(
algorithm=algorithm,
config=config,
)
app = FastAPI()
app.add_middleware(
LimifyMiddleware,
limiter=limify.limiter,
)
@app.get("/items")
async def items():
return {"status": "ok"}
Sync Example
Example using synchronous Redis.
import redis
from limify import Limify, LimifyConfig
from limify.core.redis_adapter import RedisSyncAdapter
from limify.core.algorithms.token_bucket import TokenBucketAlgorithm
redis_client = redis.Redis(host="localhost", port=6379)
adapter = RedisSyncAdapter(redis_client)
algorithm = TokenBucketAlgorithm(adapter)
config = LimifyConfig(
rules=[
{
"id": "default",
"method": "*",
"path": "/**",
"rate": "5/minute",
}
]
)
limify = Limify(
algorithm=algorithm,
config=config,
)
Redis Key Structure
Limify generates deterministic keys:
limify:{rule_id}:{plan_id}:{identity_type}:{identity_value}
Examples:
limify:items:default:user:42
limify:default:default:ip:127.0.0.1
limify:items:pro:apikey:abc123
Each identity and rule has an independent token bucket.
Rules
Rules define rate limits per endpoint.
Example:
{
"id": "items",
"method": "*",
"path": "/items",
"rate": "10/minute",
"priority": 10,
}
Supported wildcards:
/items/*
/api/**
Higher priority rules override lower priority ones.
Identity Resolution Priority
Default resolution order:
- user_id
- org_id
- api_key
- client_ip
- anonymous
Plan Support
Limify supports plan-based rate limiting using PlanProvider.
This enables multi-tier SaaS limits.
Example plans:
free → 10/minute
pro → 100/minute
enterprise → 1000/minute
Algorithms
Currently implemented:
- Token Bucket (async)
- Token Bucket (sync)
Future:
- Sliding Window
- Fixed Window
Storage Adapters
Currently implemented:
- RedisAsyncAdapter
- RedisSyncAdapter
Future:
- In-memory adapter
- PostgreSQL adapter
FastAPI Adapter
Limify provides Starlette-compatible middleware.
limify.adapters.fastapi.middleware.LimifyMiddleware
Adds headers:
X-RateLimit-Limit
X-RateLimit-Remaining
Retry-After
Project Structure
limify/
adapters/
fastapi/
core/
algorithms/
resolvers/
redis_adapter.py
limiter.py
...
config.py
defaults.py
plan_provider.py
...
Status
Alpha
Core architecture is stable and production-grade, but API surface may evolve.
Roadmap
- In-memory storage adapter
- Flask adapter
- Django adapter
- Sliding window algorithm
- Fixed window algorithm
- Metrics support
License
MIT License
Author
Pedram Aliniaye Asli
Limify is designed as reusable infrastructure for modern backend systems.
Metadata
Release files for limifyrate 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| limifyrate-0.1.5.tar.gz | 14.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| limifyrate-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.0 kB
Release files / limifyrate-0.1.5.tar.gz
| Download URL | limifyrate-0.1.5.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8b02f443d6ad59c67a46e464ec37a12149974f50211432cdfa8669dfc47db36
|
|
BLAKE2b-256 checksum How to use checksums |
438a4978796fa151db65282077bd2809f1d249a283fc59424ee14c774dec0ed8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 9, 2026.
Transparency logRelease files / limifyrate-0.1.5-py3-none-any.whl
| Download URL | limifyrate-0.1.5-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d605dd42370cb7cf1e440a08035d9fbeeacf5b4ee92a317737de9c5e47cb6007
|
|
BLAKE2b-256 checksum How to use checksums |
1d8836689dadf85c27faee56af3ca68d6fde99662f184a5f85ee0616fcf0c64c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 9, 2026.
Transparency log