Skip to main content

Python SDK for Featureflip - a feature flag SaaS platform

Project description

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

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

# Identify users for segment building
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

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

featureflip-1.0.1.tar.gz (38.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

featureflip-1.0.1-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file featureflip-1.0.1.tar.gz.

File metadata

  • Download URL: featureflip-1.0.1.tar.gz
  • Upload date:
  • Size: 38.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for featureflip-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5f4a63f60309998820b43e12daa31eb9bf8435a799d3f3d3bdfb9a055ed30e8c
MD5 76cff80ed9f2315d4ae9964cf410402c
BLAKE2b-256 db6c6f2b748b91586ce6dfd2be00e844df51f478e050c7e5d397233b95322320

See more details on using hashes here.

File details

Details for the file featureflip-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: featureflip-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for featureflip-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a6a055570ff1e39738801d7a727a6beea2d472bc4ca6245686c8f665f3e85d59
MD5 3c0f807cf5edbe7959ae8ab5b706d06c
BLAKE2b-256 4e2243e87943728200253610a9b40ee51a868fd474f819a7b3787f96cf492aef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page