Rust-powered rate limiting SDK for Python
Project description
pace-python
Rust-powered rate limiting for Python. Native engine via PyO3 — no Redis, no network hop, sub-millisecond decisions.
Install
pip install pace-python
Quick Start
from pace_sdk import Pace, PaceConfig, ProtectionMode, Algorithm
pace = Pace(PaceConfig(
mode=ProtectionMode.ACTIVE,
algorithm=Algorithm.TOKEN_BUCKET,
capacity=100,
refill_rate=10.0,
))
result = pace.check(ip="127.0.0.1", route="/api/generate")
if result.allowed:
print("✅ Request allowed")
else:
print(f"🚫 Blocked — reason: {result.reason}")
Algorithms
| Algorithm | Config Fields |
|---|---|
TOKEN_BUCKET |
capacity, refill_rate |
LEAKY_BUCKET |
capacity, refill_rate |
FIXED_WINDOW |
capacity, window |
SLIDING_WINDOW |
capacity, window |
Modes
ProtectionMode.ACTIVE # blocks requests over limit
ProtectionMode.SHADOW # logs but never blocks
ProtectionMode.DISABLED # zero overhead passthrough
FastAPI
from fastapi import FastAPI, Depends
from pace_sdk import Pace, PaceConfig, ProtectionMode, Algorithm
app = FastAPI()
pace = Pace(PaceConfig(
mode=ProtectionMode.ACTIVE,
algorithm=Algorithm.SLIDING_WINDOW,
capacity=100,
refill_rate=10.0,
))
@app.post("/api/generate", dependencies=[Depends(pace.middleware_fastapi())])
async def generate():
return {"success": True}
Flask
from flask import Flask
from pace_sdk import Pace, PaceConfig, ProtectionMode, Algorithm
app = Flask(__name__)
pace = Pace(PaceConfig(
mode=ProtectionMode.ACTIVE,
algorithm=Algorithm.TOKEN_BUCKET,
capacity=100,
refill_rate=10.0,
))
app.before_request(pace.middleware_flask())
@app.route("/api/generate", methods=["POST"])
def generate():
return {"success": True}
Debug Output
pace = Pace(PaceConfig(
mode=ProtectionMode.ACTIVE,
algorithm=Algorithm.TOKEN_BUCKET,
capacity=3,
refill_rate=1.0,
debug="pretty" # or "compact"
))
│ IP: 127.0.0.1
│ Algorithm: token_bucket
│ Reason: token_exhausted
│ Mode: active
│ Remaining: 0
│ Latency: 0ms
└────────────────────────────────────────
Connect to Pace Cloud
pace = Pace(PaceConfig(
mode=ProtectionMode.ACTIVE,
algorithm=Algorithm.TOKEN_BUCKET,
capacity=100,
refill_rate=10.0,
api_key="your-api-key",
))
License
Apache 2.0 © Suvodeep Mishra
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
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 pace_python-1.0.5-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: pace_python-1.0.5-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 241.8 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
015f647ccb4b361632eb2299775e808f0078851fa02aef145cea8fd03e5581a4
|
|
| MD5 |
d4b5f7ce364ab6266c42c5c90927f150
|
|
| BLAKE2b-256 |
1f9dcafdefcf846c9dc6dc5ada6bdbaabed11ae787165096c82f413ecf360472
|
File details
Details for the file pace_python-1.0.5-cp38-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: pace_python-1.0.5-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 401.0 kB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57117e8f28d532eb6b01eb036b0271f84c2ecf177ee39cc6b5f2637ba1627f75
|
|
| MD5 |
b1cb7220c4b9fd093754cb857fb13564
|
|
| BLAKE2b-256 |
a344412b579c9b772a4f825f69f6e7b7f53bbf17da2f60367936d372455e45d7
|
File details
Details for the file pace_python-1.0.5-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: pace_python-1.0.5-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 344.7 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5562ec1a4b7bd41b667bb6be97a2fae9ff8fcfcaa26e4a978ad97b907005a49b
|
|
| MD5 |
cd0f01873b850f2031041004af081a26
|
|
| BLAKE2b-256 |
0828f6756d4527b231b48253e351416a7182512bb6a0018dd0b37d438756c727
|