A production-grade distributed rate limiting SDK for Python powered by Redis and Lua.
Project description
๐ก๏ธ Aegis
A production-grade distributed rate limiting SDK for Python featuring multiple rate limiting algorithms, Redis-backed atomic execution with Lua scripts, and a clean, extensible backend architecture.
Why Aegis?
Modern backend applications rarely run on a single server.
Whether you're building APIs with FastAPI, Flask, Django, or any other framework, your application will eventually be deployed across multiple instances behind a load balancer. At that point, traditional in-memory rate limiting stops working because each server maintains its own counters.
Aegis was built to solve that problem.
It provides multiple production-proven rate limiting algorithms, atomic Redis execution using Lua scripts, and an SDK that makes distributed rate limiting easy to integrate into your applications.
Features
๐ Multiple Rate Limiting Algorithms
- Fixed Window
- Sliding Window Log
- Token Bucket
- Leaky Bucket
โก Multiple Backends
- In-Memory
- Redis
๐ Distributed & Atomic
- Redis Lua Scripts
- Atomic Operations
- Race Condition Safe
- Redis Server Time
- TTL-based Cleanup
๐งช Well Tested
- Unit tests for all algorithms
- Redis integration tests
- Distributed behavior validation
Quick Start
Installation
Installation instructions will be available once Aegis is published on PyPI.
pip install aegis
Example
from app import Aegis, RedisBackend
backend = RedisBackend()
limiter = Aegis(
backend=backend,
algorithm="fixed_window",
limit=100,
window_size=60,
)
if limiter.allow("user123"):
print("Request Allowed")
else:
print("Rate Limited")
Supported Algorithms
| Algorithm | In-Memory | Redis | Distributed |
|---|---|---|---|
| Fixed Window | โ | โ | โ |
| Sliding Window | โ | โ | โ |
| Token Bucket | โ | โ | โ |
| Leaky Bucket | โ | โ | โ |
Architecture
Client
โ
โผ
RateLimitMiddleware
โ
โผ
Aegis SDK
โ
โโโโโโโโโโโโโโดโโโโโโโโโโโโโ
โ โ
RedisBackend MemoryBackend
โ โ
โผ โผ
Redis Algorithms Memory Algorithms
โ โ
โผ โผ
Redis + Lua Scripts InMemory Storage
Project Structure
aegis/
โ
โโโ algorithms/
โโโ backends/
โโโ middleware/
โโโ redis/
โโโ storage/
โโโ lua/
โโโ core/
โโโ tests/
โโโ docs/
Roadmap
Version 0.1
- Four rate limiting algorithms
- Redis backend
- Lua-based atomic execution
- SDK Factory
- Backend abstraction
- FastAPI middleware
Next
- Benchmarks
- Prometheus Metrics
- OpenTelemetry Support
- GitHub Actions
- PyPI Release
- Documentation
Future
- Node.js SDK
- Go SDK
- Java SDK
Documentation
Detailed documentation is available inside the docs/ directory.
- Architecture
- Algorithms
- Benchmarking
- SDK Guide
Contributing
Contributions, issues, and feature requests are welcome.
Please read CONTRIBUTING.md before opening a Pull Request.
License
This project is licensed under the MIT License.
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 aegis_rl-0.1.0.tar.gz.
File metadata
- Download URL: aegis_rl-0.1.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
471760b000c86fb5d3ffcdfc94da60dfd0344e285b8417a6f86490547059b8e0
|
|
| MD5 |
d6104eed55f222888986f6d0995ae67e
|
|
| BLAKE2b-256 |
4b7933fed64e115b8ef6601fee2ecc6f2dc349f55fa354f053719deb5f8649e3
|
File details
Details for the file aegis_rl-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aegis_rl-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29b238c70259934587663407e86de2ec5e765836368f1b9a67cc2f9f9f0ee7cd
|
|
| MD5 |
6abda51242674055652fbf66f4dc0265
|
|
| BLAKE2b-256 |
295fcc8765c88c12b0a5580e6e6c17eaf40afb9829debd50e53c08414d8eb02c
|