Skip to main content

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.

PyPI license

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

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

pace_python-1.0.6-cp38-abi3-win_amd64.whl (241.3 kB view details)

Uploaded CPython 3.8+Windows x86-64

pace_python-1.0.6-cp38-abi3-manylinux_2_34_x86_64.whl (402.6 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.34+ x86-64

pace_python-1.0.6-cp38-abi3-macosx_11_0_arm64.whl (345.6 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file pace_python-1.0.6-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pace_python-1.0.6-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 241.3 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

Hashes for pace_python-1.0.6-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 44380cd84cc04ec4cd3b1793dc1f88b40c5fec171cba074eb970a1aad818bbbb
MD5 e38accec479604bc68867a0e3462de27
BLAKE2b-256 7b8c995405e9897daf9c2c064b3e35546ff0c49a3a196dcff58aea50c3bf9e95

See more details on using hashes here.

File details

Details for the file pace_python-1.0.6-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pace_python-1.0.6-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 71c37937d664d9297e8464f04d8a9c05057940f7dd481c85c57e71bb40f36461
MD5 8d5beb4c2e63e28601b3db62616a6f9c
BLAKE2b-256 bbb395dda751bebdc597c71313140fae534f75ce2266d026af8f5a2b717be7ce

See more details on using hashes here.

File details

Details for the file pace_python-1.0.6-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pace_python-1.0.6-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 536e698d04fecd5762c595b7bb526478149fc5af1ea8fa2e3f801e006602e38e
MD5 4aa032cc281898d077977c6eda3230c9
BLAKE2b-256 9b75b05f7f43abe0a9d192102b029871826ac986778ac8a2cc147a7c80b08958

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