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

Uploaded Python 3

File details

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

File metadata

  • Download URL: test_python_asdasda-17.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-17.0.0.tar.gz
Algorithm Hash digest
SHA256 976678f1a6a6b1cf731b6010e59db2ccb17f78497b77634afdd8dca828e14d14
MD5 afb5e29d69faffb6de867b22fec0410f
BLAKE2b-256 417ec1f7d9ad23a8e57bf68040ee76ba3b415e7c3d3014dc46094110c0a9a511

See more details on using hashes here.

File details

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

File metadata

  • Download URL: test_python_asdasda-17.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-17.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 97e0a28a126d4d9fb56550ee25dddbb7d6ea5105cd09fd9e392bd845a0a71f7b
MD5 1794e0e11e7d30d2b3d18ceb072d4c18
BLAKE2b-256 aeadf8ae6150e41fa8d867b02bd008d59e8807f2c07207eb032a4a86eb5a9f2b

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