Skip to main content

testttttttttttttttttttttttt

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

  1. Getting Started
  2. Usage
  3. Configuration
  4. Contributing
  5. License

Getting Started

Installation

Install the provider and the OpenFeature Python SDK:

pip install openfeature-sdk hyphen-openfeature-provider

Usage

Example: Feature Flag Evaluation

To evaluate a feature flag with specific user or application context, define and pass an EvaluationContext:

from openfeature_provider_hyphen import HyphenUser, HyphenEvaluationContext

# Create user details
user = HyphenUser(
    id="user-123",
    email="user@example.com",
    name="John Doe",
    custom_attributes={"role": "admin"}
)

# Create evaluation context
context = HyphenEvaluationContext(
    targeting_key="user-123",
    attributes={
        "user": user,
        "ip_address": "203.0.113.42",
        "custom_attributes": {
            "subscription_level": "premium",
            "region": "us-east"
        }
    }
)

# Evaluate the toggle with context
flag_details = await client.get_boolean_value(
    "toggle-key",
    default_value=False,
    evaluation_context=context
)

print(flag_details)  # True or False

Configuration

Options

Option Type Description Required
application str The application id or alternate id. Yes
environment str The environment in which your application is running (e.g., production, staging). Yes
horizon_urls List[str] A list of Hyphen Horizon URLs to use for fetching feature flags. No
enable_toggle_usage bool Enable or disable the logging of toggle usage (telemetry). No
cache dict Configuration for caching feature flag evaluations. No

Cache Configuration

The cache option accepts the following properties:

Property Type Default Description
ttl_seconds int 300 Time-to-live in seconds for cached flag evaluations.
generate_cache_key_fn Callable - Custom function to generate cache keys from evaluation context.

Example with cache configuration:

options = HyphenProviderOptions(
    application="your-application-name",
    environment="production",
    cache={
        "ttl_seconds": 600,  # 10 minutes
        "generate_cache_key_fn": lambda context: f"{context['targeting_key']}-{context['user']['id']}"
    }
)

# Example using an project environment id
# options = HyphenProviderOptions(
#     application="your-application-name",
#     environment="pevr_abc123",
#     cache={
#         "ttl_seconds": 600,  # 10 minutes
#         "generate_cache_key_fn": lambda context: f"{context['targeting_key']}-{context['user']['id']}"
#     }
# )

Context

The SDK provides two main classes for structuring evaluation context:

HyphenEvaluationContext

The main context class that wraps all evaluation context data.

Field Type Description
targeting_key str The key used for caching the evaluation response.
attributes dict Dictionary containing user details, IP address, and custom attributes.

HyphenUser

Class for structuring user information within the context.

Field Type Description
id str The unique identifier of the user.
email str (Optional) The email address of the user.
name str (Optional) The name of the user.
custom_attributes dict (Optional) Custom attributes specific to the user.

The attributes dictionary in HyphenEvaluationContext can contain:

  • user: Instance of HyphenUser
  • ip_address: str - The IP address of the user making the request
  • custom_attributes: dict - Additional contextual information

Contributing

We welcome contributions to this project! If you'd like to contribute, please follow the guidelines outlined in CONTRIBUTING.md. Whether it's reporting issues, suggesting new features, or submitting pull requests, your help is greatly appreciated!

License

This project is licensed under the MIT License. See the LICENSE file for full details.

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

test_python_asdasda-7.7.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

test_python_asdasda-7.7.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file test_python_asdasda-7.7.0.tar.gz.

File metadata

  • Download URL: test_python_asdasda-7.7.0.tar.gz
  • Upload date:
  • Size: 10.6 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

Hashes for test_python_asdasda-7.7.0.tar.gz
Algorithm Hash digest
SHA256 05a73d9077db723f7059d328e55307e33cb1fda73351e87bf0341c531d733fcc
MD5 3e5a0e93f32d1debdde20639685d5904
BLAKE2b-256 1b2b9e536ce87187a67d106e6965e1efab1107f9f0d74adb4c013b99c564bc15

See more details on using hashes here.

File details

Details for the file test_python_asdasda-7.7.0-py3-none-any.whl.

File metadata

  • Download URL: test_python_asdasda-7.7.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 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

Hashes for test_python_asdasda-7.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5f35f483c4164cfeb92750233f89bed07110252635f15a99051b77bc74e0a5a
MD5 0ecd7490f753cb1978fdac739808cded
BLAKE2b-256 7976c231d14ad9e68dae74476d42190e64824463236d40d25b932cdd8a181fe7

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