Skip to main content

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

Metadata

Release files for switchpilot 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for switchpilot 0.2.0
File Size Uploaded Provenance
switchpilot-0.2.0.tar.gz 6.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for switchpilot 0.2.0
File Interpreter ABI Platform
switchpilot-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.6 kB

Release files / switchpilot-0.2.0.tar.gz

Download URL switchpilot-0.2.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7e20be0d039be30913ffed535f7f39ce22ac40a39247bb4b7ca7ee59d1108e8a
BLAKE2b-256 checksum
How to use checksums
b4664363a6724c5f83a23f5ad7fb23c50de414e795411a20a53cffaa623cb931
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / switchpilot-0.2.0-py3-none-any.whl

Download URL switchpilot-0.2.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ca119e6213f099e6b3899ebef337e85fa051cbaa97c30e92752740198e0a289
BLAKE2b-256 checksum
How to use checksums
55b10107c248acfd89dfbcb75782ede5f5359d12812952b37272e7655f3875d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Security for switchpilot 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page