Official server-side Python SDK for SwitchPilot feature flags
Project description
switchpilot
The official server-side Python SDK for SwitchPilot feature flags.
Install
pip install switchpilot
Quick start
Create one reusable synchronous client. Existing integrations require no changes.
import os
from switchpilot import SwitchPilot
client = SwitchPilot(api_key=os.environ["SWITCHPILOT_API_KEY"])
enabled = client.is_enabled("new-checkout")
Cache and reliability
The default cache TTL is 60 seconds. is_enabled() and get_all() evaluate flags locally while the cache is fresh; they do not make one HTTP request per evaluation. refresh() requests a synchronization explicitly.
The SDK automatically sends the last ETag as If-None-Match. A 304 Not Modified renews cache freshness without parsing a body. Concurrent threads share one refresh.
The last valid 200 response is retained as Last Known Good. If a refresh fails, it remains usable until:
stale_expires_at = last_successful_refresh_at + cache_ttl + stale_if_error
The stale-if-error window defaults to 5 minutes. The fallback is used only when no usable configuration exists. A missing flag continues to use the per-call fallback, then the client fallback.
client = SwitchPilot(
api_key=os.environ["SWITCHPILOT_API_KEY"],
cache_ttl=60,
stale_if_error=300,
fallback=False,
timeout=2,
)
cache_ttl=0 preserves the existing behavior of revalidating each evaluation, while Last Known Good can still be used within stale_if_error after failure.
Methods
client.is_enabled("new-checkout")
client.is_enabled("new-checkout", True) # per-call fallback
client.get_all() # defensive copy
client.refresh() # manual synchronization
client.get_status() # local; never performs I/O
get_status() returns an immutable dataclass with cache freshness, stale use, refresh timestamps, ETag, safe error information, and rate_limited_until. It never exposes the API key.
On 429 Too Many Requests, the SDK respects Retry-After, performs no retry loop, and serves Last Known Good when usable. Calls before the deadline do not contact the API.
Server-side only
Python 3.10 or newer is required. The package includes typing metadata. Never expose the project API key to a browser or logs. Redirect following is disabled so Authorization cannot be forwarded to another origin.
For an editable local install:
pip install -e sdks/python
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 Distribution
Built Distribution
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 switchpilot-0.2.0.tar.gz.
File metadata
- Download URL: switchpilot-0.2.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e20be0d039be30913ffed535f7f39ce22ac40a39247bb4b7ca7ee59d1108e8a
|
|
| MD5 |
e4909b497770cf02c698b691b17d0699
|
|
| BLAKE2b-256 |
b4664363a6724c5f83a23f5ad7fb23c50de414e795411a20a53cffaa623cb931
|
File details
Details for the file switchpilot-0.2.0-py3-none-any.whl.
File metadata
- Download URL: switchpilot-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ca119e6213f099e6b3899ebef337e85fa051cbaa97c30e92752740198e0a289
|
|
| MD5 |
8607e3f8b2d56ac970630bc61d59d0af
|
|
| BLAKE2b-256 |
55b10107c248acfd89dfbcb75782ede5f5359d12812952b37272e7655f3875d6
|