FlagBox SDK for Python
Project description
FlagBox Python SDK
A lightweight Python SDK for managing feature flags with FlagBox. This SDK provides both synchronous and asynchronous methods for evaluating feature flags, with support for global and per-flag contexts.
Installation
pip install flagboxsdk
Quick Start
from flagboxsdk import Client
# Initialize the client
client = FlagBoxClient(
api_url="https://api.flagbox.io",
api_key="your-api-key"
)
# Get a feature flag value
is_new_feature_enabled = client.get_flag("new-feature", False)
if is_new_feature_enabled:
# Feature is enabled
pass
else:
# Feature is disabled
pass
Using Context
The SDK supports both global context (set during client initialization) and per-flag context:
# Initialize client with global context
client = FlagBoxClient(
api_url="https://api.flagbox.io",
api_key="your-api-key",
global_context={
"userId": "user123",
"plan": "premium"
}
)
# Get flag with additional per-flag context
result = client.get_flag(
flag_key="new-feature",
default_value=False,
context={
"country": "Spain"
}
)
Async Support
For asynchronous applications, use the async version of the client:
import asyncio
from flagbox import FlagBoxClient
async def main():
client = FlagBoxClient(
api_url="https://api.flagbox.io",
api_key="your-api-key"
)
# Get a feature flag value asynchronously
is_new_feature_enabled = await client.get_flag_async(
"new-feature",
False
)
asyncio.run(main())
Error Handling
The SDK handles errors gracefully by returning the default value in case of:
- Network errors
- Invalid API responses
- Unsupported flag types
- Missing flags
- Rate limit exceeded
Requirements
- Python 3.7 or higher
- requests>=2.25.0
- aiohttp>=3.8.0
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 flagboxsdk-0.0.1.tar.gz.
File metadata
- Download URL: flagboxsdk-0.0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d34f02bb89010ebd7166f6772b0f64c30b394f8f26b291fe31ab0cebedec4cc1
|
|
| MD5 |
f96bfaa4cdd980b62864f12907f97dcf
|
|
| BLAKE2b-256 |
c6e0bf312c3981a6b0f26535428b58a23ed34b78a2241318457d459b546adcec
|
File details
Details for the file flagboxsdk-0.0.1-py3-none-any.whl.
File metadata
- Download URL: flagboxsdk-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
881b6b816f13c30bd047cb5aa8bec92f140743d9739dfabe6dcee2728a4949af
|
|
| MD5 |
520ef8e56a6abb9f09232d334a24a660
|
|
| BLAKE2b-256 |
c49194cb4be5875611bb4092a0d5d8edc6d78703b27ee06658019bd764f9dc4d
|