Skip to main content

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

  1. Installation
  2. Quick Start
  3. Configuration Options
  4. Evaluation Context
  5. License

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hyphen_openfeature_provider-1.0.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

hyphen_openfeature_provider-1.0.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file hyphen_openfeature_provider-1.0.0.tar.gz.

File metadata

  • Download URL: hyphen_openfeature_provider-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

Hashes for hyphen_openfeature_provider-1.0.0.tar.gz
Algorithm Hash digest
SHA256 79f89c5254bcc2ff7e6c5356e4f423854281f51b425ad62e4f928cd9898e4d32
MD5 af89a429f79c5aa4a655c932f636f4b8
BLAKE2b-256 27fc6e34f96e74564a7425f99fdf5db087e1236f678f5b4eacb212b8f08fb89a

See more details on using hashes here.

File details

Details for the file hyphen_openfeature_provider-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hyphen_openfeature_provider-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 022e07c984221bdc14ca0ac8366597494e00282f9725f15c69e4d0944e8c829e
MD5 88701f19bae19bacd47baaab7b2f7cb3
BLAKE2b-256 d25bc3d66c8b52cd95946fd20f7bd66ae4a99e8e7a4ac660f7d2f85debbcc224

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