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-16.0.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-16.0.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: test_python_asdasda-16.0.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-16.0.0.tar.gz
Algorithm Hash digest
SHA256 b5f7b2149a9e01888ce1b733cccc6a7997a8fc032478e1d06aa5d169e1903810
MD5 255bd07cd60adebc1fb49cdbe1b672e6
BLAKE2b-256 9e3c4c65a5e03319d00cc79e6c90cb1c894fd7a0a0091121309255fe3af6abb5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: test_python_asdasda-16.0.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-16.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d496a70652d058006c3d8e3f182fd194c42f043cdf8ffc06e843ef774036658
MD5 0f61a99fafb619720fe367300f3381d0
BLAKE2b-256 5b99976213647dc1b16f93a23b5d0a7ea3fab6a7d73b35819abc524c085bdbff

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