Hyphen provider for OpenFeature Python SDK
Project description
Hyphen Toggle OpenFeature Provider
The Hyphen Toggle OpenFeature Provider is an OpenFeature provider implementation for the Hyphen Toggle platform in Python. It enables feature flag evaluation using the OpenFeature standard.
Table of Contents
Getting Started
Installation
Install the provider and the OpenFeature Python SDK:
pip install openfeature-sdk hyphen-openfeature-provider
Quick Start
from openfeature_provider_hyphen import (
HyphenUser,
HyphenEvaluationContext
)
# Create a user with all available fields
user = HyphenUser(
id="user-123",
email="user@example.com",
name="John Doe",
custom_attributes={
"role": "admin",
"subscription": "premium"
}
)
# Create an evaluation context with all available options
context = HyphenEvaluationContext(
targeting_key="user-123",
attributes={
"user": user,
"ip_address": "192.168.1.1",
"custom_attributes": {
"device": "mobile",
"platform": "ios"
}
}
)
# Evaluate different types of flags
try:
# Boolean flag
show_feature = client.get_boolean_value(
flag_key="show-new-feature",
default_value=False,
evaluation_context=context
)
# String flag
theme = client.get_string_value(
flag_key="app-theme",
default_value="light",
evaluation_context=context
)
# Integer flag
max_items = client.get_integer_value(
flag_key="max-items",
default_value=10,
evaluation_context=context
)
# Object flag
config = client.get_object_value(
flag_key="feature-config",
default_value={
"enabled": True,
"timeout": 30
},
evaluation_context=context
)
except Exception as e:
print(f"Error evaluating flags: {e}")
Configuration Options
The HyphenProviderOptions class accepts the following parameters:
| Option | Type | Required | Description |
|---|---|---|---|
application |
str | Yes | The application name or ID |
environment |
str | Yes | Environment identifier (can be environment ID or alternateId) |
horizon_urls |
List[str] | No | Custom Hyphen server URLs |
enable_toggle_usage |
bool | No | Enable/disable telemetry (default: True) |
cache_ttl_seconds |
int | No | Cache TTL in seconds |
generate_cache_key_fn |
Callable | No | Custom cache key generation function |
Evaluation Context
HyphenUser
The HyphenUser class contains user-specific information:
| Field | Type | Required | Description |
|---|---|---|---|
id |
str | Yes | Unique user identifier |
email |
str | No | User's email address |
name |
str | No | User's name |
custom_attributes |
Dict[str, Any] | No | Additional user attributes |
HyphenEvaluationContext
The HyphenEvaluationContext class wraps all evaluation context data:
| Field | Type | Required | Description |
|---|---|---|---|
targeting_key |
str | Yes | Key for evaluation targeting |
attributes |
Dict | No | Contains user, IP address, and custom attributes |
License
This project is licensed under the MIT License. See the LICENSE file for details.
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 openfeature_provider_python-1.0.0.tar.gz.
File metadata
- Download URL: openfeature_provider_python-1.0.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.1 CPython/3.12.3 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b191014443921cfdd30b41706eec6839f7566d6daacc86be27ce0bbc619bf7c
|
|
| MD5 |
6851e4dde1bba5fdfc0b489569b48655
|
|
| BLAKE2b-256 |
9eb897d21e26066e5d89d08de22a587b3c67815876ff4f7d397852de45f8b05c
|
File details
Details for the file openfeature_provider_python-1.0.0-py3-none-any.whl.
File metadata
- Download URL: openfeature_provider_python-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.1 CPython/3.12.3 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a529560b735d5805c568488d18b24f7ad72bcf5209801bb9c1561a2998b685de
|
|
| MD5 |
7b1ea46d184cc0e737e3e30485863efe
|
|
| BLAKE2b-256 |
7646c87783a3dcaaa1118ff435742dcb0defe0bcbe903f2664bfdc192c3037e5
|