Featureflip Python SDK
Python SDK for Featureflip - evaluate feature flags locally with near-zero latency.
Installation
pip install featureflip
Quick Start
from featureflip import FeatureflipClient
# Initialize the client (blocks until flags are loaded)
client = FeatureflipClient(sdk_key="your-sdk-key")
# Evaluate a feature flag
enabled = client.variation("my-feature", {"user_id": "user-123"}, default=False)
if enabled:
print("Feature is enabled!")
else:
print("Feature is disabled")
# Clean shutdown
client.close()
Lifetime: Multiple
FeatureflipClient(sdk_key="x")calls with the same SDK key return distinct handles sharing one underlying client — you cannot accidentally open duplicate streaming connections by constructing multiple clients.close()is refcounted; the real shutdown runs only when the last handle is closed.
Configuration
from featureflip import FeatureflipClient, Config
client = FeatureflipClient(
sdk_key="your-sdk-key",
config=Config(
base_url="https://eval.featureflip.io", # Evaluation API URL
streaming=True, # Use SSE for real-time updates (default)
poll_interval=30.0, # Polling interval if streaming=False
send_events=True, # Enable analytics event tracking
flush_interval=30.0, # Event flush interval in seconds
init_timeout=10.0, # Max seconds to wait for initialization
)
)
The SDK key can also be set via the FEATUREFLIP_SDK_KEY environment variable.
Context Manager
with FeatureflipClient(sdk_key="your-sdk-key") as client:
enabled = client.variation("my-feature", {"user_id": "123"}, default=False)
# Automatically closes and flushes events on exit
Evaluation
# Boolean flag
enabled = client.variation("feature-key", {"user_id": "123"}, default=False)
# String flag
tier = client.variation("pricing-tier", {"user_id": "123"}, default="free")
# Number flag
limit = client.variation("rate-limit", {"user_id": "123"}, default=100)
# JSON flag
config = client.variation("ui-config", {"user_id": "123"}, default={"theme": "light"})
Detailed Evaluation
detail = client.variation_detail("feature-key", {"user_id": "123"}, default=False)
print(detail.value) # The evaluated value
print(detail.reason) # "RULE_MATCH", "FALLTHROUGH", "FLAG_DISABLED", etc.
print(detail.rule_id) # Rule ID if reason is RULE_MATCH
Event Tracking
# Track custom events
client.track("checkout-completed", {"user_id": "123"}, metadata={"total": 99.99})
# Record an identify event for analytics (does not affect flag evaluation)
client.identify({"user_id": "123", "email": "user@example.com", "plan": "pro"})
# Force flush pending events
client.flush()
Featureflip counts each event name, per environment. The metadata you pass is transmitted with the event but is not stored, and event counts are not surfaced in the app or API.
Flag Change Notifications
Subscribe to flag-configuration changes. The listener receives the keys affected by each change, batched into one call:
def on_flags_changed(keys):
print("flags changed:", keys)
unsubscribe = client.on_update(on_flags_changed)
...
unsubscribe() # or client.off_update(on_flags_changed)
The initial flag load does not fire. Beyond flags whose own configuration changed, an update also names flags whose evaluated value moves as a result: those referencing an edited segment, and those depending on a changed flag through a prerequisite.
Listeners run on the SDK's streaming or polling thread, so they must not block. A listener that raises is logged and isolated, affecting neither flag delivery nor the other listeners.
Testing
Use the test client for deterministic unit tests:
from featureflip import FeatureflipClient
# Create a test client with fixed values (no network calls)
client = FeatureflipClient.for_testing({
"my-feature": True,
"pricing-tier": "pro",
})
# Evaluations return the configured values
assert client.variation("my-feature", {}, default=False) is True
assert client.variation("pricing-tier", {}, default="free") == "pro"
# Unknown flags return the default
assert client.variation("unknown", {}, default="fallback") == "fallback"
# Update values at runtime
client.set_test_value("my-feature", False)
Features
- Client-side evaluation - Near-zero latency after initialization
- Real-time updates - SSE streaming with polling fallback
- Change notifications -
on_update()reports exactly which flags moved - Event tracking - Automatic batching and flushing of analytics events
- Test support -
for_testing()factory for deterministic unit tests - Type-safe - Full type hints with mypy strict mode compliance
Requirements
- Python 3.10+
Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
ruff check src/featureflip tests
# Run type checking
mypy src/featureflip --strict
License
Apache-2.0
Metadata
Release files for featureflip 2.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| featureflip-2.8.0.tar.gz | 125.5 kB | Without provenance | Details for featureflip-2.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| featureflip-2.8.0-py3-none-any.whl | Python 3 | none | any | Details for featureflip-2.8.0-py3-none-any.whl |
Total release size: 189.3 kB
Release files / featureflip-2.8.0.tar.gz
| Download URL | featureflip-2.8.0.tar.gz |
|---|---|
| Size | 125.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
966d5f094e13ce21b549ba105913e888f3e0273fa57cafe367788525dff36117
|
|
BLAKE2b-256 checksum How to use checksums |
54146cc7230942ea3ca2d72598bbc70206f75eee0582d6455ad304a1b5b06400
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / featureflip-2.8.0-py3-none-any.whl
| Download URL | featureflip-2.8.0-py3-none-any.whl |
|---|---|
| Size | 63.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1520ed96d48ce7a7513c21b92c760d00be0dd1c4aa0ffa7c09902a365be3384c
|
|
BLAKE2b-256 checksum How to use checksums |
ab8511e3bbb13b1e089c09e4be4389f0bc787dbc8d526c6d885731018269a791
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for featureflip 2.8.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.