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 import api
from openfeature_provider_hyphen import (
    HyphenProvider,
    HyphenProviderOptions,
    HyphenEvaluationContext
)

# Initialize provider options
options = HyphenProviderOptions(
    application="your-app-name",
    environment="production"
)

# Create and set the provider
provider = HyphenProvider(
    public_key="your-public-key",
    options=options
)
api.set_provider(provider)

# Create a client
client = api.get_client()

# 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.1.0.tar.gz (10.0 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.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hyphen_openfeature_provider-1.1.0.tar.gz
  • Upload date:
  • Size: 10.0 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.1.0.tar.gz
Algorithm Hash digest
SHA256 895946c6943f646f96dbb9a58562d168b8e1ee6284ed5d39e25dbaf94bed4aba
MD5 e6e322072bb2482281d337c76abe3e4a
BLAKE2b-256 09f667d5dda04772005e5c9edc8f1ca2b29a85efe083e4e3b4b48efa1da2ff3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hyphen_openfeature_provider-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ec4e5f50fbe09b13c04b3a83f88766ec7a06dfc51d2c76aa079f592376e11b8
MD5 de8f0adde3103f7c97fa968dc5a6e080
BLAKE2b-256 450253594a650bd1f75e0bf3fd6f0c75d317ff2ce61f7a82da109a609d9b64e0

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