Skip to main content

Python SDK for Flagr — OpenFeature-compatible

Project description

flagr-sdk

Python SDK for Flagr — OpenFeature-compatible feature flag client.

Connects to the Flagr Evaluation API via SSE, seeds a local in-memory cache from the initial snapshot, and applies real-time updates as flags change. Every flag evaluation is fully local — no network call per check.

Prerequisites

  • Python >= 3.9
  • An active Flagr account and an SDK key (sdk_live_...) from the dashboard

Install

pip install flagr-sdk

Quickstart

from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from flagr import FlagrProvider

api.set_provider(FlagrProvider(
    sdk_key="sdk_live_xxx",
    base_url="https://api.flagr.dev",
))

client = api.get_client()

enabled = client.get_boolean_value(
    "new-checkout",
    default_value=False,
    # targeting_key maps to tenant_id — use a user ID, org ID, account ID, or any entity identifier
    evaluation_context=EvaluationContext(targeting_key="a1b2c3d4-e5f6-7890-abcd-ef1234567890"),
)

Running locally

# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate

# Install the package with dev dependencies
pip install -e ".[dev]"

Running tests

# Unit tests (no server required)
pytest tests/test_provider.py -v

# Integration tests (requires a running Flagr API + valid SDK key)
FLAGR_SDK_KEY=sdk_live_xxx FLAGR_BASE_URL=http://localhost:8080 pytest tests/test_integration.py -v

# Run all tests
pytest -v

# Type-check
mypy src/

# Lint
ruff check src/ tests/

Releasing a new version

Releases are fully automated via GitHub Actions using PyPI's OIDC trusted publishing — no API token required.

  1. Bump the version in pyproject.toml:

    [project]
    version = "0.1.1"
    
  2. Commit and push the version bump, then create and push the tag:

    git add pyproject.toml
    git commit -m "chore: bump sdk-python to v0.1.1"
    git tag sdk-python/v0.1.1
    git push origin sdk-python/v0.1.1
    

    The tag must match the pattern sdk-python/v*.

  3. GitHub Actions runs .github/workflows/publish.yml, which builds the distributions with hatch and publishes them to PyPI via trusted publishing. No credentials needed locally.

PyPI setup (one-time): The PyPI project must have trusted publishing configured for this repository and the pypi GitHub Actions environment. See PyPI trusted publishing docs.

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

flagr_sdk-0.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

flagr_sdk-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file flagr_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: flagr_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for flagr_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1bf4412ce2fa4c0c8c8b998800520aac926b5de590e97128ef8fd3c93e1403cf
MD5 2b5d3aea7454655cf5425717b6264695
BLAKE2b-256 10e812cbe3b5629cc6879c7045bb3f917927cc09d624e18af62908a37659b005

See more details on using hashes here.

File details

Details for the file flagr_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flagr_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for flagr_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 504abd1ec62e263177d44f31ee421879b307bbbe18892585b40e1e5d440fb72c
MD5 d2cc7fd6676f92612cda91c26fa46b24
BLAKE2b-256 db4272cca2c05a63043c4f8fd2bb13758f8f76bae86f7b4797ced3e15d90c02b

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