SDKs

Python SDK

4 min read

Use the Python SDK to initialize FlagPilot, evaluate flags, pass target users, and handle fallback behavior in production.

Installation

Terminal
pip install flagpilot

Initialization

main.py
from flagpilot import FlagPilot
import os

flagpilot = FlagPilot(
    api_key=os.getenv("FLAGPILOT_SECRET_KEY"),
    environment="production"
)
flagpilot.initialize()

# Evaluate a feature flag
is_enabled = flagpilot.evaluate("checkout-redesign", user_id=user["id"])

if is_enabled:
    # Serve new checkout experience
    pass

Evaluating a flag

main.py
is_enabled = flagpilot.evaluate("checkout-redesign", user_id="user_123")

Target users

Send stable opaque user IDs and optional attributes to keep percentage rollouts and targeting rules consistent.

main.py
flagpilot.evaluate("checkout-redesign", user_id="user_123")

Error handling

Use a conservative fallback value when evaluation fails or the SDK cannot reach its configured source.

Best practices

  • Reuse one SDK client instance per app runtime.
  • Set the SDK environment option to development, staging, or production.
  • Hash or pseudonymize sensitive user identifiers before sending them to evaluations.

FAQ

How does Python SDK interact with local caches?

Configurations are synced down using Edge Config or fallback REST triggers. The client automatically reads evaluations in-memory, resulting in sub-millisecond local evaluation times.

Where can I obtain support for Python SDK?

You can open a support ticket in your dashboard, check the community roadmap, or consult the FlagPilot Platform Status page.

Was this page helpful?