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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c03920e9db2cac242e5e775850354ee095115ea4fd2354dc29cf0b78e9e3337f
|
|
| MD5 |
8cbb5163259b32545a8fadffa72c4d73
|
|
| BLAKE2b-256 |
6b65d9675f9383cf193adea587323fd0a3419636535f7c9a41212550374bf730
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
waitstate-0.1.0-py3-none-win_amd64.whl -
Subject digest:
c03920e9db2cac242e5e775850354ee095115ea4fd2354dc29cf0b78e9e3337f - Sigstore transparency entry: 1046838010
- Sigstore integration time:
-
Permalink:
waitstate-io/engine@c6a7a87e37aeab9b6b004c09690a47d839cc53c0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/waitstate-io
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@c6a7a87e37aeab9b6b004c09690a47d839cc53c0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file waitstate-0.1.0-py3-none-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: waitstate-0.1.0-py3-none-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: Python 3, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6743345e08684c462376b72e631e792b31c229ecb957d79449669fa1aa93206b
|
|
| MD5 |
d4a905546bae66c04d11b33d9eb5adfa
|
|
| BLAKE2b-256 |
5ad8a96f9560efbf2730bed4fa7eb596cd96dfe81c8d0816013d7bbd2b9bd885
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
waitstate-0.1.0-py3-none-manylinux_2_34_x86_64.whl -
Subject digest:
6743345e08684c462376b72e631e792b31c229ecb957d79449669fa1aa93206b - Sigstore transparency entry: 1046838013
- Sigstore integration time:
-
Permalink:
waitstate-io/engine@c6a7a87e37aeab9b6b004c09690a47d839cc53c0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/waitstate-io
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@c6a7a87e37aeab9b6b004c09690a47d839cc53c0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file waitstate-0.1.0-py3-none-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: waitstate-0.1.0-py3-none-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 2.3 MB
- Tags: Python 3, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97cedddb5fef6037ac06177547c2b6612b42aaa437118b7ee8b8716db843e8cf
|
|
| MD5 |
d7076fb28c69230a505cbf3bfdfb3364
|
|
| BLAKE2b-256 |
b7bfd46c6738182d1aa4aec8cec63795b586a88daf9a7f1e11e176cf0cb4f5cb
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
waitstate-0.1.0-py3-none-manylinux_2_34_aarch64.whl -
Subject digest:
97cedddb5fef6037ac06177547c2b6612b42aaa437118b7ee8b8716db843e8cf - Sigstore transparency entry: 1046838001
- Sigstore integration time:
-
Permalink:
waitstate-io/engine@c6a7a87e37aeab9b6b004c09690a47d839cc53c0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/waitstate-io
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@c6a7a87e37aeab9b6b004c09690a47d839cc53c0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file waitstate-0.1.0-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: waitstate-0.1.0-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.1 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3897096ec122eefb4bedc0045049e5729f5610b92768ad6054ec4bca96988f9
|
|
| MD5 |
41d98301f432855dd506ecab9a6f318d
|
|
| BLAKE2b-256 |
4c60cdfc67e6ef47b9d6ede454e4968ab7b761c7f9fce6f960cd9c712e830430
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
waitstate-0.1.0-py3-none-macosx_11_0_arm64.whl -
Subject digest:
d3897096ec122eefb4bedc0045049e5729f5610b92768ad6054ec4bca96988f9 - Sigstore transparency entry: 1046838007
- Sigstore integration time:
-
Permalink:
waitstate-io/engine@c6a7a87e37aeab9b6b004c09690a47d839cc53c0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/waitstate-io
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@c6a7a87e37aeab9b6b004c09690a47d839cc53c0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file waitstate-0.1.0-py3-none-macosx_10_12_x86_64.whl.
File metadata
- Download URL: waitstate-0.1.0-py3-none-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.1 MB
- Tags: Python 3, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acc5a227a4daa06916d99e0863bebfb8e1c58dece57a067d362a5a17f611e460
|
|
| MD5 |
b42c2a3e4395e31f462a83e6febda72d
|
|
| BLAKE2b-256 |
494164db132284d41ac4061cf841a1135a82d29d4f6a3873c34e70d5064f3a47
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
waitstate-0.1.0-py3-none-macosx_10_12_x86_64.whl -
Subject digest:
acc5a227a4daa06916d99e0863bebfb8e1c58dece57a067d362a5a17f611e460 - Sigstore transparency entry: 1046838002
- Sigstore integration time:
-
Permalink:
waitstate-io/engine@c6a7a87e37aeab9b6b004c09690a47d839cc53c0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/waitstate-io
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@c6a7a87e37aeab9b6b004c09690a47d839cc53c0 -
Trigger Event:
release
-
Statement type: