skills/featbit/featbit-skills/featbit-sdks-python

featbit-sdks-python

Installation
SKILL.md

FeatBit Python Server SDK

When to Use This Skill

Use for server-side Python applications — Flask, Django, FastAPI, background workers, or scripts — that evaluate feature flags on the backend.

Why server SDK: Flags sync via WebSocket on startup (<100ms) and are evaluated locally with no remote call per request. The process holds one persistent singleton client.

Do not use for browser JavaScript, React, React Native, or any frontend context.

Source

https://github.com/featbit/featbit-python-sdk

Setup Workflow

Copy and track progress:

  • Step 1: Install the package
  • Step 2: Configure the singleton client
  • Step 3: Evaluate the first feature flag
  • Step 4: Shut down cleanly

Step 1: Install the package

Run:

pip install fb-python-sdk

Step 2: Configure the singleton client

from fbclient import get, set_config
from fbclient.config import Config

set_config(Config(
    env_secret='<your-env-secret>',
    event_url='http://localhost:5100',
    streaming_url='ws://localhost:5100'
))
client = get()

Why set_config + get(): This initializes a process-wide singleton. Call set_config once at application startup; every subsequent get() returns the same instance.

Step 3: Evaluate the first feature flag

if client.initialize:
    user = {'key': 'user-key-123', 'name': 'Jane'}
    detail = client.variation_detail('flag-key', user, default=None)
    print(f'flag returns {detail.variation}, reason: {detail.reason}')

Why check client.initialize: This property (no parentheses) confirms the SDK has synced flag data. If false, env_secret, event_url, or streaming_url is likely wrong.

Step 4: Shut down cleanly

client.stop()

Call client.stop() when the process exits to flush pending analytics events.

Feature Flag Evaluation

user = {'key': 'user-key-123', 'name': 'Jane'}

# Value only
flag_value = client.variation('flag-key', user, False)

# Value + reason
detail = client.variation_detail('flag-key', user, default=None)
print(detail.variation)  # the resolved value
print(detail.reason)     # why this value was returned

# All flags for a user
all_flags = client.get_all_latest_flag_variations(user)

Use variation when only the resolved value is needed. Use variation_detail when the caller needs to know why a specific value was returned (targeting rule, default, etc.).

User Custom Properties

The Python SDK represents a user as a plain dict. Add any extra keys directly — no builder class is required:

user = {
    'key': 'bob-id',       # required: unique identifier
    'name': 'Bob',         # required: display name
    'age': 25,             # custom property
    'country': 'FR',       # custom property
    'plan': 'premium',     # custom property
}
flag_value = client.variation('flag-key', user, False)

FeatBit targeting rules can reference any key in this dict.

Read Next Only When Needed

Weekly Installs
2
GitHub Stars
11
First Seen
Mar 11, 2026
Installed on
amp2
cline2
opencode2
cursor2
kimi-cli2
codex2