Python SDK
Flipswitch SDK for Python with real-time SSE support
The Flipswitch Python SDK provides an OpenFeature-compatible provider with automatic cache invalidation via Server-Sent Events (SSE).
Requirements
- Python 3.9+
- OpenFeature SDK
Installation
Quick Start
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
api_key | str | required | Environment API key from dashboard |
base_url | str | https://api.flipswitch.dev | Your Flipswitch server URL |
enable_realtime | bool | True | Enable SSE for real-time flag updates |
Evaluation Context
Pass user attributes for targeting:
Real-Time Updates
When enable_realtime=True is set (default), the SDK maintains an SSE connection to receive instant flag changes:
- The SSE client receives a
flag-changeevent - The local cache is immediately invalidated
- Next flag evaluation fetches the fresh value
Event Listeners
Connection Status
Detailed Evaluation
Get full evaluation details including variant and reason:
Bulk Flag Evaluation
Evaluate all flags at once:
FastAPI Integration
Django Integration
Reconnection Strategy
The SSE client automatically reconnects with exponential backoff:
- Initial delay: 1 second
- Maximum delay: 30 seconds
- Backoff multiplier: 2x
Shutdown
Always shutdown the provider when done:
In long-running applications (FastAPI, Django), make sure to call shutdown() when the application stops to close the SSE connection properly.
Troubleshooting
SSE connection keeps disconnecting
Check if your proxy or load balancer supports long-lived connections. Configure timeout settings accordingly.
Flags not updating in real-time
Verify that enable_realtime=True is set and check the SSE status:
Import errors
Make sure you have installed all required dependencies: