Skip to main content

testtttttttttttttttttttttttt

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-1.1.0.tar.gz (10.5 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-1.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: test_python_asdasda-1.1.0.tar.gz
  • Upload date:
  • Size: 10.5 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-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a40d724b2007dfdc27e3127f39205663427a1fcb58a90193eaad1c0d28fe5845
MD5 267bdd8301ccc92a1731cfe216753d5b
BLAKE2b-256 4c64e2ff74e630d6ee7d38f1e2d9951db03f9e6fd262eceed83e59bf65dd5368

See more details on using hashes here.

File details

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

File metadata

  • Download URL: test_python_asdasda-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 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-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1dffea184cabd67600a6725187850cf237f3bb967c04a464c114cbb7e5379182
MD5 0de7f7ae31238a3653ad87703f2ad768
BLAKE2b-256 56d2e189a0f795c4fa3a8c630cf613474313d6020627bf6c14c696e6a596c1b4

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