Skip to main content

Confidence provider for the OpenFeature SDK

Project description

Python Confidence SDK

This repo contains the Confidence Python SDK and the Confidence OpenFeature provider. We recommend using the OpenFeature Python SDK to access Confidence feature flags.

To learn more about the basic concepts (flags, targeting key, evaluation contexts), the OpenFeature reference documentation or the getting started guide can be useful.

Install

pip install

pip install spotify-confidence-sdk==3.0.1

This installs the full SDK including telemetry support and is the suggested .

Minimal installation (without telemetry)

For environments where you cannot use protobuf, you can install without protobuf (which disables telemetry):

pip install spotify-confidence-sdk==3.0.1 --no-deps
pip install requests==3.0.1 openfeature-sdk==0.4.2 typing_extensions==4.9.0 httpx==0.27.2

requirements.txt

# Full installation (recommended)
spotify-confidence-sdk==3.0.1

pip install -r requirements.txt

Usage

Creating the SDK

The OpenFeature provider is created by using the SDK. More details on how to setup the SDK can be found here.

from confidence.confidence import Confidence
from openfeature import api
from confidence.openfeature_provider import ConfidenceOpenFeatureProvider

provider = ConfidenceOpenFeatureProvider(Confidence(api_client, timeout_ms=500))
api.set_provider(provider)

Resolving flags

Flag values are evaluated remotely and returned to the application by using the OpenFeature client:

from openfeature import api

client = api.get_client()
user_identifier = "" # your identifier for a specific user

flag_value = client.get_string_value("flag-name.property-name", "my-default-value", api.EvaluationContext(attributes={"user_id": user_identifier}))
print(f"Flag value: {flag_value}")

Configuration options

The SDK can be configured with several options:

from confidence.confidence import Confidence, Region

confidence = Confidence(
    client_secret="CLIENT_TOKEN",
    region=Region.EU,  # Optional: defaults to GLOBAL
    timeout_ms=5000,  # Optional: specify timeout in milliseconds for network requests (default: 10000ms)
    custom_resolve_base_url="https://my-custom-endpoint.org" # we will append /v1/flags:resolve to this for the resolve endpoint.
)

Logging

The SDK includes built-in logging functionality to help with debugging and monitoring. By default, the SDK creates a logger named confidence_logger that outputs to the console with DEBUG level logging enabled.

Default logging behavior

When you create a Confidence client without specifying a logger, debug-level logging is automatically enabled:

from confidence.confidence import Confidence

# Debug logging is enabled by default
confidence = Confidence("CLIENT_TOKEN")

This will output log messages such as flag resolution details, error messages, and debug information to help troubleshoot issues.

Using a custom logger

You can provide your own logger instance to customize the logging behavior:

import logging
from confidence.confidence import Confidence

# Create a custom logger with INFO level (less verbose)
custom_logger = logging.getLogger("my_confidence_logger")
custom_logger.setLevel(logging.INFO)

confidence = Confidence("CLIENT_TOKEN", logger=custom_logger)

Disabling debug logging

To reduce log verbosity, you can configure a logger with a higher log level:

import logging
from confidence.confidence import Confidence

# Create a logger that only shows warnings and errors
quiet_logger = logging.getLogger("quiet_confidence_logger")
quiet_logger.setLevel(logging.WARNING)

confidence = Confidence("CLIENT_TOKEN", logger=quiet_logger)

Telemetry

The SDK includes telemetry functionality that helps monitor SDK performance and usage. By default, telemetry is enabled and collects metrics (anonymously) such as resolve latency and request status. This data is used by the Confidence team to improve the product, and in certain cases it is also available to the SDK adopters.

Telemetry behavior

  • Default installation: Telemetry is enabled automatically when protobuf dependencies are available
  • Minimal installation: Telemetry is automatically disabled when protobuf is not installed (see minimal installation)
  • Manual control: You can explicitly disable telemetry even when dependencies are available

Disabling telemetry

You can explicitly disable telemetry by setting disable_telemetry=True when initializing the Confidence client:

confidence = Confidence("CLIENT_TOKEN",
    disable_telemetry=True
)

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

spotify_confidence_sdk-3.0.1.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

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

spotify_confidence_sdk-3.0.1-py3-none-any.whl (58.7 kB view details)

Uploaded Python 3

File details

Details for the file spotify_confidence_sdk-3.0.1.tar.gz.

File metadata

  • Download URL: spotify_confidence_sdk-3.0.1.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spotify_confidence_sdk-3.0.1.tar.gz
Algorithm Hash digest
SHA256 2a50f63d7749288e548dac0ce13a906d8a66dd8ed5108bbb262db8bab41ef40a
MD5 447e51ddb2cdb328c416c0f903a7fc24
BLAKE2b-256 23aa80e3221fb4646dc687714c8bb1fcc4a01f476b5affa99df96d4c12be8599

See more details on using hashes here.

Provenance

The following attestation bundles were made for spotify_confidence_sdk-3.0.1.tar.gz:

Publisher: release-please.yaml on spotify/confidence-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spotify_confidence_sdk-3.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for spotify_confidence_sdk-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 134be0b53bdba03faea28f235d91cadecfb23a399a0e7b4b6776407a406b87c9
MD5 91182aecd03494998983b1c547223d87
BLAKE2b-256 7dd2f1c29fc9553587d7e3a9c7832c52e00cf9185c22a617280235fa128b793b

See more details on using hashes here.

Provenance

The following attestation bundles were made for spotify_confidence_sdk-3.0.1-py3-none-any.whl:

Publisher: release-please.yaml on spotify/confidence-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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