Python SDK for EdgeFlags feature flag service
Project description
edgeflags
Python SDK for EdgeFlags — a high-performance feature flag and configuration service.
Supports both async and sync interfaces.
Installation
pip install edgeflags
Requires Python 3.10+.
Quick Start
Async
import asyncio
from edgeflags import EdgeFlags
async def main():
ef = EdgeFlags(
token="ff_production_abc123",
base_url="https://edgeflags.net",
context={"user_id": "user-42", "plan": "pro"},
)
await ef.init()
if ef.flag("dark_mode", False):
print("Dark mode enabled")
theme = ef.config("theme", "default")
print(f"Theme: {theme}")
ef.destroy()
asyncio.run(main())
Sync
from edgeflags import EdgeFlagsSync
ef = EdgeFlagsSync(
token="ff_production_abc123",
base_url="https://edgeflags.net",
context={"user_id": "user-42", "plan": "pro"},
)
ef.init()
if ef.flag("dark_mode", False):
print("Dark mode enabled")
ef.destroy()
API Reference
EdgeFlags / EdgeFlagsSync
| Parameter | Type | Default | Description |
|---|---|---|---|
token |
str |
required | API token (ff_env_...) |
base_url |
str |
required | EdgeFlags service URL |
context |
EvaluationContext |
{} |
Initial evaluation context |
polling_interval |
float |
60.0 |
Polling interval in seconds |
bootstrap |
Bootstrap |
None |
Fallback data if init fails |
debug |
bool |
False |
Enable debug logging |
Methods
| Method | Async | Sync | Description |
|---|---|---|---|
init() |
await ef.init() |
ef.init() |
Fetch initial data and start polling |
flag(key, default?) |
sync | sync | Get flag value from cache |
config(key, default?) |
sync | sync | Get config value from cache |
all_flags() |
sync | sync | Get all flags |
all_configs() |
sync | sync | Get all configs |
identify(context) |
await ef.identify(ctx) |
ef.identify(ctx) |
Update context and refresh |
refresh() |
await ef.refresh() |
ef.refresh() |
Manually refresh from server |
on(event, fn) |
sync | sync | Subscribe to events (returns unsubscribe fn) |
destroy() |
sync | sync | Stop polling and clear state |
is_ready |
property | property | Whether client is initialized |
Events
ef.on("ready", lambda: print("Ready"))
ef.on("change", lambda event: print(f"Changed: {event}"))
ef.on("error", lambda err: print(f"Error: {err}"))
The change event payload is a ChangeEvent dict with flags and configs lists, each containing key, previous, and current values.
Bootstrap
Provide fallback data in case the initial fetch fails:
ef = EdgeFlags(
token="...",
base_url="...",
bootstrap={
"flags": {"dark_mode": False, "beta": False},
"configs": {"theme": "default"},
},
)
Testing
Use create_mock_client / create_mock_client_sync for tests — no network required:
from edgeflags import create_mock_client_sync
def test_feature():
ef = create_mock_client_sync(
flags={"new_checkout": True},
configs={"max_items": 50},
)
assert ef.is_ready
assert ef.flag("new_checkout") is True
assert ef.config("max_items") == 50
assert ef.flag("missing", False) is False
Types
All types are exported and support type checking (PEP 561):
from edgeflags import (
FlagValue, # bool | str | int | float | dict[str, Any]
EvaluationContext, # TypedDict with user_id, email, plan, etc.
EvaluationResponse, # TypedDict with flags + configs
ChangeEvent, # TypedDict with flag/config change lists
Bootstrap, # TypedDict with optional flags + configs
EdgeFlagsEvent, # Literal["ready", "change", "error"]
EdgeFlagsError, # Exception with optional status_code
)
License
MIT
Project details
Release history Release notifications | RSS feed
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 edgeflags-0.1.0.tar.gz.
File metadata
- Download URL: edgeflags-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdb106bbd8848b636bfd1ee305acedf36445b68cedeb2ca7af7c350e78c308ad
|
|
| MD5 |
6f925ac9cd48ca930b87d39db06eeab6
|
|
| BLAKE2b-256 |
cf96316f8d56259c0f760ba988114d2a56c332d1a94203bb6908967ec135639d
|
Provenance
The following attestation bundles were made for edgeflags-0.1.0.tar.gz:
Publisher:
publish-python.yml on edgeflags/sdks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
edgeflags-0.1.0.tar.gz -
Subject digest:
fdb106bbd8848b636bfd1ee305acedf36445b68cedeb2ca7af7c350e78c308ad - Sigstore transparency entry: 962538131
- Sigstore integration time:
-
Permalink:
edgeflags/sdks@a07756a0d6696e335118e6627e0806f366365510 -
Branch / Tag:
refs/tags/python-v0.1.0 - Owner: https://github.com/edgeflags
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@a07756a0d6696e335118e6627e0806f366365510 -
Trigger Event:
push
-
Statement type:
File details
Details for the file edgeflags-0.1.0-py3-none-any.whl.
File metadata
- Download URL: edgeflags-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
702f0235a830facfdc8802dcaa32644a95162ca0a30950829b90e01de4aad7fa
|
|
| MD5 |
c8acee3745506c75eac91211036aaaa5
|
|
| BLAKE2b-256 |
e38b1170ddcc1866c0d8530531f72cd40ac715c80b9dc61f24d2546778434e96
|
Provenance
The following attestation bundles were made for edgeflags-0.1.0-py3-none-any.whl:
Publisher:
publish-python.yml on edgeflags/sdks
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
edgeflags-0.1.0-py3-none-any.whl -
Subject digest:
702f0235a830facfdc8802dcaa32644a95162ca0a30950829b90e01de4aad7fa - Sigstore transparency entry: 962538134
- Sigstore integration time:
-
Permalink:
edgeflags/sdks@a07756a0d6696e335118e6627e0806f366365510 -
Branch / Tag:
refs/tags/python-v0.1.0 - Owner: https://github.com/edgeflags
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@a07756a0d6696e335118e6627e0806f366365510 -
Trigger Event:
push
-
Statement type: