Skip to main content

WaitState SDK — adaptive rate limiting for any language

Project description

waitstate

Python SDK for WaitState - adaptive gating that adds fleet-wide traffic intelligence on top of your existing infrastructure.

Built from a single Rust core via UniFFI. Native performance, no C toolchains required.

Install

pip install waitstate

Quick start

import os
from waitstate import WaitstateClient

client = WaitstateClient(
    publish_key=os.environ["WAITSTATE_PUBLISH_KEY"],
    secret_key=os.environ["WAITSTATE_SECRET_KEY"],
)

# Synchronous, in-memory, zero network calls on the hot path
result = client.gate("free", 1.0)

if not result.allowed:
    return {"error": "rate_limited", "reason": str(result.reason)}, 429

Framework middleware

FastAPI

from fastapi import Depends, FastAPI, Request
from waitstate import WaitstateClient
from waitstate.middleware.fastapi import create_dependency, create_response_hook

client = WaitstateClient(
    publish_key=os.environ["WAITSTATE_PUBLISH_KEY"],
    secret_key=os.environ["WAITSTATE_SECRET_KEY"],
)

app = FastAPI()
gate = create_dependency(client)
app.middleware("http")(create_response_hook(client))

@app.get("/search")
async def search(request: Request, _=Depends(gate)):
    ...

Flask

from flask import Flask
from waitstate import WaitstateClient
from waitstate.middleware.flask import init_app

client = WaitstateClient(
    publish_key=os.environ["WAITSTATE_PUBLISH_KEY"],
    secret_key=os.environ["WAITSTATE_SECRET_KEY"],
)

app = Flask(__name__)
init_app(app, client)

Django

# settings.py
WAITSTATE_PUBLISH_KEY = os.environ["WAITSTATE_PUBLISH_KEY"]
WAITSTATE_SECRET_KEY = os.environ["WAITSTATE_SECRET_KEY"]

MIDDLEWARE = [
    "waitstate.middleware.django.WaitstateMiddleware",
    # ...
]

Agent mode

If you prefer not to embed the SDK, point it at a local waitstate-agent sidecar instead:

client = WaitstateClient(agent_url="http://localhost:9000")

result = client.gate("free", 1.0)

In agent mode, gate calls are HTTP round-trips to the sidecar (~1ms on localhost). The agent handles all background sync and telemetry.

Configuration

Parameter Type Default Description
publish_key str - Required (embedded mode). From the dashboard.
secret_key str - Required (embedded mode). Store in env vars.
agent_url str None Use agent mode instead of embedded.
base_url str https://api.waitstate.io Control plane URL.
site_id str None Shard key for DO routing. Isolates sites within one org.

How it works

  • gate() checks an in-memory policy - synchronous, sub-millisecond in embedded mode.
  • Background tasks send health telemetry (pulses) to the control plane and receive updated policies.
  • If the control plane is unreachable, the SDK fails open (all requests allowed).
  • If the lease expires, the SDK enters safe mode - a fixed RPS cap to prevent runaway traffic.
  • Zero Python dependencies. The compiled Rust core is distributed as a platform-specific wheel.

Supported platforms

Pre-built wheels are available for:

  • Linux x86_64 / aarch64
  • macOS x86_64 / aarch64 (Apple Silicon)
  • Windows x86_64

Documentation

Full docs, API reference, and reflex rule guides: waitstate.io/docs

License

Apache 2.0

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.

waitstate-0.1.0-py3-none-win_amd64.whl (1.9 MB view details)

Uploaded Python 3Windows x86-64

waitstate-0.1.0-py3-none-manylinux_2_34_x86_64.whl (2.3 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ x86-64

waitstate-0.1.0-py3-none-manylinux_2_34_aarch64.whl (2.3 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ ARM64

waitstate-0.1.0-py3-none-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

waitstate-0.1.0-py3-none-macosx_10_12_x86_64.whl (2.1 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file waitstate-0.1.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: waitstate-0.1.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for waitstate-0.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 c03920e9db2cac242e5e775850354ee095115ea4fd2354dc29cf0b78e9e3337f
MD5 8cbb5163259b32545a8fadffa72c4d73
BLAKE2b-256 6b65d9675f9383cf193adea587323fd0a3419636535f7c9a41212550374bf730

See more details on using hashes here.

Provenance

The following attestation bundles were made for waitstate-0.1.0-py3-none-win_amd64.whl:

Publisher: publish-python.yml on waitstate-io/engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file waitstate-0.1.0-py3-none-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for waitstate-0.1.0-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6743345e08684c462376b72e631e792b31c229ecb957d79449669fa1aa93206b
MD5 d4a905546bae66c04d11b33d9eb5adfa
BLAKE2b-256 5ad8a96f9560efbf2730bed4fa7eb596cd96dfe81c8d0816013d7bbd2b9bd885

See more details on using hashes here.

Provenance

The following attestation bundles were made for waitstate-0.1.0-py3-none-manylinux_2_34_x86_64.whl:

Publisher: publish-python.yml on waitstate-io/engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file waitstate-0.1.0-py3-none-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for waitstate-0.1.0-py3-none-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 97cedddb5fef6037ac06177547c2b6612b42aaa437118b7ee8b8716db843e8cf
MD5 d7076fb28c69230a505cbf3bfdfb3364
BLAKE2b-256 b7bfd46c6738182d1aa4aec8cec63795b586a88daf9a7f1e11e176cf0cb4f5cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for waitstate-0.1.0-py3-none-manylinux_2_34_aarch64.whl:

Publisher: publish-python.yml on waitstate-io/engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file waitstate-0.1.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for waitstate-0.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d3897096ec122eefb4bedc0045049e5729f5610b92768ad6054ec4bca96988f9
MD5 41d98301f432855dd506ecab9a6f318d
BLAKE2b-256 4c60cdfc67e6ef47b9d6ede454e4968ab7b761c7f9fce6f960cd9c712e830430

See more details on using hashes here.

Provenance

The following attestation bundles were made for waitstate-0.1.0-py3-none-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on waitstate-io/engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file waitstate-0.1.0-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for waitstate-0.1.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 acc5a227a4daa06916d99e0863bebfb8e1c58dece57a067d362a5a17f611e460
MD5 b42c2a3e4395e31f462a83e6febda72d
BLAKE2b-256 494164db132284d41ac4061cf841a1135a82d29d4f6a3873c34e70d5064f3a47

See more details on using hashes here.

Provenance

The following attestation bundles were made for waitstate-0.1.0-py3-none-macosx_10_12_x86_64.whl:

Publisher: publish-python.yml on waitstate-io/engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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