Framework-agnostic, Redis-backed rate limiting engine for modern async Python systems.
Project description
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.
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 limifyrate-0.1.5.tar.gz.
File metadata
- Download URL: limifyrate-0.1.5.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8b02f443d6ad59c67a46e464ec37a12149974f50211432cdfa8669dfc47db36
|
|
| MD5 |
448cd536210a4b5cd3b84007ad205b9d
|
|
| BLAKE2b-256 |
438a4978796fa151db65282077bd2809f1d249a283fc59424ee14c774dec0ed8
|
Provenance
The following attestation bundles were made for limifyrate-0.1.5.tar.gz:
Publisher:
publish-pypi.yml on pedram-aliniaye-asli/limify
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
limifyrate-0.1.5.tar.gz -
Subject digest:
c8b02f443d6ad59c67a46e464ec37a12149974f50211432cdfa8669dfc47db36 - Sigstore transparency entry: 1069157907
- Sigstore integration time:
-
Permalink:
pedram-aliniaye-asli/limify@f36895615282b01c2b806a359a180c69736d7cd6 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/pedram-aliniaye-asli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f36895615282b01c2b806a359a180c69736d7cd6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file limifyrate-0.1.5-py3-none-any.whl.
File metadata
- Download URL: limifyrate-0.1.5-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d605dd42370cb7cf1e440a08035d9fbeeacf5b4ee92a317737de9c5e47cb6007
|
|
| MD5 |
cee5df1ab3abe384f74e0e3a6ebcb9e2
|
|
| BLAKE2b-256 |
1d8836689dadf85c27faee56af3ca68d6fde99662f184a5f85ee0616fcf0c64c
|
Provenance
The following attestation bundles were made for limifyrate-0.1.5-py3-none-any.whl:
Publisher:
publish-pypi.yml on pedram-aliniaye-asli/limify
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
limifyrate-0.1.5-py3-none-any.whl -
Subject digest:
d605dd42370cb7cf1e440a08035d9fbeeacf5b4ee92a317737de9c5e47cb6007 - Sigstore transparency entry: 1069157957
- Sigstore integration time:
-
Permalink:
pedram-aliniaye-asli/limify@f36895615282b01c2b806a359a180c69736d7cd6 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/pedram-aliniaye-asli
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f36895615282b01c2b806a359a180c69736d7cd6 -
Trigger Event:
push
-
Statement type: