Python SDK
The RocketFlag Python SDK is a stdlib-only client for evaluating flags from Python 3.9+ applications.
Installation
Section titled “Installation”pip install rocketflagBasic Usage
Section titled “Basic Usage”from rocketflag import create_client
rocketflag = create_client()
flag = rocketflag.get_flag("ABC123def456")if flag.enabled: print(f'Feature "{flag.name}" is enabled!')You can also construct Client directly:
from rocketflag import Client
client = Client()flag = client.get_flag("ABC123def456")Advanced Usage
Section titled “Advanced Usage”Working with Cohorts
Section titled “Working with Cohorts”Pass a cohort identifier to target specific users:
flag = rocketflag.get_flag("ABC123def456", {"cohort": "user@example.com"})Working with Group Flags (Environments)
Section titled “Working with Group Flags (Environments)”When using Group Flags, specify the environment (env must be alphanumeric):
flag = rocketflag.get_flag("ABC123def456", {"env": "production"})Custom Configuration
Section titled “Custom Configuration”rocketflag = create_client("v1", "https://your-custom-proxy.com")Caching Responses
Section titled “Caching Responses”Opt-in in-memory cache keyed by flag ID and user context:
# Cache flag responses for 5 minutes.rocketflag = create_client(ttl_seconds=300)
flag = rocketflag.get_flag("ABC123def456", {"cohort": "beta"})
# Force a fresh fetch.flag = rocketflag.get_flag("ABC123def456", ttl_seconds=0)Without a client default or per-call TTL, every call hits the API.
Error Handling
Section titled “Error Handling”from rocketflag import APIError, InvalidResponseError, NetworkError, create_client
rocketflag = create_client()
try: flag = rocketflag.get_flag("ABC123def456")except APIError as err: print(f"API Error: {err.status} {err.status_text}")except InvalidResponseError as err: print(f"Invalid Response Error: {err}")except NetworkError as err: print(f"Network Error: {err}")APIError— non-OK HTTP status (includesstatus/status_text). A404means the flag ID is unknown.InvalidResponseError— body is not JSON or not a flag object.NetworkError— connection failure.
Source
Section titled “Source”- GitHub: RocketFlag/python-sdk
- PyPI: rocketflag