Skip to main content

superposition_provider

Project description

Superposition Provider

Superposition provider is an openfeature provider that works with Superposition to fetch feature flags, configurations, and experiment variants from a Superposition server, store it in-memory and do configuration resolutions based on dynamic contexts. Read the docs for more details.

Installation

Install the provider

pip install openfeature-sdk
pip install superposition-provider

Note: You will need to boot up Superposition before running the client code. Check the docs on how to get started with Superposition.

Initialization

To initialize the Superposition provider, you need to create a configuration. Create the provider object and then, you can set the provider using OpenFeature's API.

from openfeature import api
from superposition_provider.provider import SuperpositionProvider
from superposition_provider.types import ExperimentationOptions, SuperpositionProviderOptions, PollingStrategy

config_options = SuperpositionProviderOptions(
  endpoint="http://localhost:8080",
  token="api-token",
  org_id="localorg", 
  workspace_id="test",
  refresh_strategy=PollingStrategy(
      interval=5,  # Poll every 5 seconds
      timeout=3    # Timeout after 3 seconds
  ),
  fallback_config=None,
  evaluation_cache_options=None,
  experimentation_options=ExperimentationOptions(
      refresh_strategy=PollingStrategy(
          interval=5,  # Poll every 5 seconds
          timeout=3    # Timeout after 3 seconds
      )
  )
)

provider = SuperpositionProvider(provider_options=config_options)
# Initialize provider
await provider.initialize(context=ctx)
api.set_provider(provider)

Usage

Once the provider is initialized, you can evaluate feature flags and configurations using the OpenFeature client.

client = api.get_client()

ctx = EvaluationContext(
  targeting_key="25",  # Using a targeting key for experiment variant decider
  attributes={'d1': 'd1'}
)

bool_val = client.get_boolean_details(
    flag_key="bool",
    default_value=True,
    evaluation_context=ctx
)
# Note: If you want the whole config, you can directly use the provider itself
resp = provider.resolve_all_config_details({}, ctx)
print(f"Response for all config: {resp}")

print("Successfully resolved boolean flag details:", bool_val)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

superposition_provider-0.101.0-py3-none-any.whl (11.5 MB view details)

Uploaded Python 3

File details

Details for the file superposition_provider-0.101.0-py3-none-any.whl.

File metadata

File hashes

Hashes for superposition_provider-0.101.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b337858ab8181574989b8b7c1e50cad32af111b137e65d3b61e9df73d2ffe3c
MD5 b887de16edd21a891755564ce047c82a
BLAKE2b-256 a2defb028eff031e5eb6c6eb4f5c859e659a117b13b9953f55b12effc7ed7824

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