Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aegis_rl-0.1.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aegis_rl-0.1.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

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

Hashes for aegis_rl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 471760b000c86fb5d3ffcdfc94da60dfd0344e285b8417a6f86490547059b8e0
MD5 d6104eed55f222888986f6d0995ae67e
BLAKE2b-256 4b7933fed64e115b8ef6601fee2ecc6f2dc349f55fa354f053719deb5f8649e3

See more details on using hashes here.

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

Hashes for aegis_rl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29b238c70259934587663407e86de2ec5e765836368f1b9a67cc2f9f9f0ee7cd
MD5 6abda51242674055652fbf66f4dc0265
BLAKE2b-256 295fcc8765c88c12b0a5580e6e6c17eaf40afb9829debd50e53c08414d8eb02c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page