Skip to main content

Intelligent rate limiting for Flask, FastAPI, and Django — inspired by Fast Rub's WaitManager

Project description

⏱️ WaitManager-Web

Intelligent rate limiting for Flask, FastAPI, and Django — inspired by Fast Rub's WaitManager.

✨ Features

  • 🔌 Plug & Play — Works with Flask, FastAPI, and Django
  • 🧠 Smart Rate Limiting — Low/Medium/High traffic tiers with automatic wait calculation
  • 📊 Per-Channel Tracking — Separate limits for API, login, upload, download, search, signup
  • 🎯 Per-IP Tracking — Track each client separately
  • 🔧 Fully Customizable — Custom channels, custom sleep callback, auto-tracking
  • 🪶 Zero Dependencies — Core module uses only Python stdlib
  • 📦 Optional Dependencies — Install only what you need

📦 Installation

pip install waitmanager-web               # Core only
pip install waitmanager-web[flask]        # + Flask
pip install waitmanager-web[fastapi]      # + FastAPI
pip install waitmanager-web[django]       # + Django
pip install waitmanager-web[all]          # Everything

🚀 Quick Start

Flask

from flask import Flask
from waitmanager.flask import FlaskWaitManager

app = Flask(__name__)
wm = FlaskWaitManager(low_traffic=100, high_wait=2.0, auto_track=True)
wm.init_app(app)

@app.route("/api/data")
@wm.limit(channel="api")
def get_data():
    return {"status": "ok"}

@app.route("/login", methods=["POST"])
@wm.limit(channel="login", max_requests=5, window=300)
def login():
    return {"status": "ok"}

FastAPI

from fastapi import FastAPI, Depends
from waitmanager import WaitManager
from waitmanager.fastapi import RateLimiter

app = FastAPI()
wm = WaitManager(low_traffic=100, high_wait=2.0)
limiter = RateLimiter(wm)

@app.get("/api/data")
async def get_data(_=Depends(limiter.limit("api"))):
    return {"status": "ok"}

@app.post("/login")
async def login(_=Depends(limiter.limit("login", max_requests=5, window=300))):
    return {"status": "ok"}

Django

# settings.py
MIDDLEWARE = [
    "waitmanager.django.WaitManagerMiddleware",
    ...
]

WAITMANAGER_CONFIG = {
    "low_traffic": 100,
    "high_wait": 2.0,
    "auto_track": True,
}
# views.py
from waitmanager.django import limit

@limit(channel="api")
def api_view(request):
    return JsonResponse({"status": "ok"})

@limit(channel="login", max_requests=5, window=300, block=True)
def login_view(request):
    return JsonResponse({"status": "ok"})

⚙️ Configuration

Parameter Type Default Description
low_traffic int 100 Max requests for "low traffic"
medium_traffic int 200 Max requests for "medium traffic"
low_wait float 0.0 Delay for low traffic (seconds)
medium_wait float 0.5 Delay for medium traffic
high_wait float 2.0 Delay for high traffic
time_window float 60.0 Time window (seconds)
auto_track bool False Auto-track every request
per_ip bool True Track per IP address
sleep_callback callable None Custom wait time function
channels list None Custom channel names

🎯 Custom Sleep Callback

def my_logic(channel, messages_count, last_time, **kwargs):
    if channel == "login" and messages_count > 3:
        return 30.0  # 30 second penalty
    return None  # Use default logic

wm = WaitManager(sleep_callback=my_logic)

🧪 Custom Channels

wm = WaitManager(channels=["api", "login", "payment", "export"])

📄 License

MIT © OandONE

🙏 Acknowledgments

Inspired by Fast Rub's WaitManager — the smartest rate limiter for Rubika bots.


"Good software is built on pain. WaitManager was built on Rubika's API." — OandONE

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

waitmanager_web-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

waitmanager_web-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file waitmanager_web-0.1.0.tar.gz.

File metadata

  • Download URL: waitmanager_web-0.1.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for waitmanager_web-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f53baaeaa841409d1b5bb3a9bdb6380b8ad61d66ed581634c1e981756c9fea5c
MD5 37e269225be4f37328543db2303c6cc8
BLAKE2b-256 1fd717ae6e513681368e616609cf5141568f656f572896ecb84ce339a7ddc6cb

See more details on using hashes here.

File details

Details for the file waitmanager_web-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for waitmanager_web-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64a3338c2b8a607290a7141bd89d4777c951f3592526a653fba005a1a25b4dbb
MD5 013f0dc51104a870cf8a7ae7a284c35e
BLAKE2b-256 9f79f997e8d7e4e650029c9113816b90a191172d420b29aae74c7435c0bcbdc7

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