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 flagr import FlagrProvider
provider = FlagrProvider(sdk_key="sdk_live_xxx")
# One-shot evaluation
enabled = provider.is_enabled("new-checkout", tenant_id="user-123")
# Reactive — callback fires immediately and on every flag change.
# .wait() blocks until Ctrl+C, then unsubscribes automatically.
provider.on_change(
"new-checkout",
tenant_id="user-123",
callback=lambda enabled: print(f"new-checkout is now {enabled}"),
).wait()
# Or keep a reference to unsubscribe manually
sub = provider.on_change("new-checkout", tenant_id="user-123", callback=my_callback)
sub.unsubscribe()
tenant_id is any entity identifier in your product — user ID, org ID, account ID, etc.
OpenFeature
If you use the OpenFeature standard, FlagrProvider is fully compatible:
from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from flagr import FlagrProvider
api.set_provider(FlagrProvider(sdk_key="sdk_live_xxx"))
client = api.get_client()
enabled = client.get_boolean_value(
"new-checkout",
default_value=False,
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 GitLab CI using PyPI's OIDC trusted publishing — no API token required.
-
Bump the version in
pyproject.toml:[project] version = "0.1.4"
-
Commit, tag, and push:
git add pyproject.toml git commit -m "bump version to 0.1.4" git tag v0.1.4 git push origin v0.1.4
The tag must match the pattern
v*. -
GitLab CI runs
.gitlab-ci.yml, builds withhatch, and publishes to PyPI via trusted publishing. No credentials needed locally.
PyPI setup (one-time): The PyPI project must have trusted publishing configured for the GitLab repository and the
pypiGitLab CI/CD 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flagr_sdk-0.1.7.tar.gz.
File metadata
- Download URL: flagr_sdk-0.1.7.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c04da865f1032ca154bcedbe5c3b6b7d8e11b5a4907ed0fce2a76a73536d6c66
|
|
| MD5 |
2d448a1561255ea940c10d6dc544d01d
|
|
| BLAKE2b-256 |
1042a7670f8dbfaa5416b8bff0d5055c64d01919e9c901f4fe3a1e9bec3f7614
|
File details
Details for the file flagr_sdk-0.1.7-py3-none-any.whl.
File metadata
- Download URL: flagr_sdk-0.1.7-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31771f48ff8b9069a88787a958b16a1aef4aa909dcaa9e7fd26d2ba9c97255a1
|
|
| MD5 |
7ce2e15b48d51438d19888500ee456dc
|
|
| BLAKE2b-256 |
cd4e1abe68a6ee3812d39e3089732e1d5037ff4006d1b159d0e42eff05de566e
|