Skip to main content

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()

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
  • 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.4.3

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

Source distribution (sdist)

Source distribution for featureflip 2.4.3
File Size Uploaded
featureflip-2.4.3.tar.gz 88.8 kB Details

Built distribution (wheel)

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

Total release size: 136.8 kB

Release files / featureflip-2.4.3.tar.gz

Download URL featureflip-2.4.3.tar.gz
Size 88.8 kB
Tags Source
SHA-256 checksum
How to use checksums
820119c3ba8d25a0b03f42ab6875d752ce8ffbd7ec645d5e2101d5c8c5b6f368
BLAKE2b-256 checksum
How to use checksums
65fbca32dc0c0d512be1ed9d2d16ec6f1bb4b1191d1677dbf1285ac9a4e8f2b9
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.4.3-py3-none-any.whl

Download URL featureflip-2.4.3-py3-none-any.whl
Size 48.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2898ab4a40cbb4411ec7f69b91e4fa471a519420d43fce99536736c420b1174e
BLAKE2b-256 checksum
How to use checksums
58d08f1fce8750037cccaada0a6169f94a9820a649694d97e2f825b03e16c36b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

2.7.0

2 release files

2.6.0

2 release files

2.5.1

2 release files

This release

2.4.3 This release

2 release files

2.4.2

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

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