Unleash Yggdrasil Engine

1.3.0 · active · verified Sat Apr 11

yggdrasil-engine is a Python package that provides the core evaluation logic for Unleash feature flags. Implemented in Rust and exposed to Python via PyO3, it offers a high-performance, consistent, and cross-language engine for feature flag evaluation. It is primarily an internal dependency of the UnleashClient Python SDK, ensuring fast and reliable local flag evaluation. The current version is 1.3.0. Releases are typically tied to updates in the Unleash feature flag system.

Warnings

Install

Imports

Quickstart

The `yggdrasil-engine` library serves as a low-level, high-performance evaluation engine. End-users typically interact with the higher-level `UnleashClient` Python SDK, which abstracts away the complexities of the underlying engine. This quickstart demonstrates how to use `UnleashClient` to evaluate feature flags, which implicitly utilizes `yggdrasil-engine`.

import os
from UnleashClient import UnleashClient

# NOTE: yggdrasil-engine is an internal dependency of UnleashClient.
# Most users will interact with UnleashClient, which leverages yggdrasil-engine
# for high-performance feature flag evaluation.

# Configure UnleashClient (using environment variables for sensitive data)
unleash_url = os.environ.get('UNLEASH_URL', 'http://localhost:4242/api')
unleash_app_name = os.environ.get('UNLEASH_APP_NAME', 'my-python-app')
unleash_instance_id = os.environ.get('UNLEASH_INSTANCE_ID', 'my-instance')
unleash_api_token = os.environ.get('UNLEASH_API_TOKEN', '')

client = UnleashClient(
    url=unleash_url,
    app_name=unleash_app_name,
    instance_id=unleash_instance_id,
    custom_headers={'Authorization': unleash_api_token} if unleash_api_token else None
)

# Initialize the client. This will fetch feature flags from the Unleash server.
client.initialize_client()

# Check if a feature flag is enabled
feature_name = "my-awesome-feature"
is_enabled = client.is_enabled(feature_name)

if is_enabled:
    print(f"Feature '{feature_name}' is enabled!")
else:
    print(f"Feature '{feature_name}' is disabled.")

# Get a variant for a feature flag
variant = client.get_variant("my-variant-feature", context={'userId': 'user123'})
print(f"Variant for 'my-variant-feature': {variant['name']}")

# Clean up resources when done
client.destroy()

view raw JSON →