Skip to main content

Kameleoon OpenFeature provider for Python

The Kameleoon OpenFeature provider for Python allows you to connect your OpenFeature Python implementation to Kameleoon without installing the Python Kameleoon SDK.

Supported Python versions

This version of the SDK is built for the following targets:

  • Python 3.8 and above.

Get started

This section explains how to install, configure, and customize the Kameleoon OpenFeature provider.

Install dependencies

First, install the required dependencies in your application.

  • Run pip install -r requirements.txt

Usage

The following example shows how to use the Kameleoon provider with the OpenFeature SDK.

from openfeature import api
from openfeature.evaluation_context import EvaluationContext
from kameleoon_openfeature.kameleoon_provider import KameleoonProvider, KameleoonClientConfig


client_config = KameleoonClientConfig(
    'clientId',
    'clientSecret',
    top_level_domain='topLevelDomain'
)

provider = KameleoonProvider('siteCode', config=client_config)

api.set_provider(provider)
client = api.get_client()

values = {
    'variableKey': 'variableKey'
}

eval_context = EvaluationContext(attributes=values, targeting_key='visitorCode')

number_of_recommended_products = client.get_integer_value(flag_key='featureKey', default_value=5,
                                               evaluation_context=eval_context)

print(f"Number of recommended products: {number_of_recommended_products}")

Customize the Kameleoon provider

You can customize the Kameleoon provider by changing the KameleoonClientConfig object that you passed to the constructor above. For example:

from kameleoon_openfeature.kameleoon_provider import KameleoonProvider, KameleoonClientConfig

client_config = KameleoonClientConfig(
    'clientId',
    'clientSecret',
    top_level_domain='topLevelDomain',
    refresh_interval_minute=1,    # Optional field
    session_duration_minute=5,    # Optional field
)

provider = KameleoonProvider('siteCode', config=client_config)

EvaluationContext and Kameleoon Data

Kameleoon uses the concept of associating Data to users, while the OpenFeature SDK uses the concept of an EvaluationContext, which is a dictionary of string keys and values. The Kameleoon provider maps the EvaluationContext to the Kameleoon Data.

from openfeature.evaluation_context import EvaluationContext

eval_context = EvaluationContext(targeting_key='userId')

The Kameleoon provider provides a few predefined parameters that you can use to target a visitor from a specific audience and track each conversion. These are:

Parameter Description
Data.Type.CUSTOM_DATA The parameter is used to set CustomData for a visitor.
Data.Type.CONVERSION The parameter is used to track a Conversion for a visitor.

Data.Type.CUSTOM_DATA

Use Data.Type.CUSTOM_DATA to set CustomData for a visitor. The Data.Type.CUSTOM_DATA field has the following parameters:

Parameter Type Description
Data.CustomDataType.INDEX int Index or ID of the custom data to store. This field is mandatory.
Data.CustomDataType.VALUES str Value of the custom data to store. This field is mandatory.

Example

from openfeature.evaluation_context import EvaluationContext
from kameleoon_openfeature.types import Data

custom_data_dictionary = {
    Data.Type.CUSTOM_DATA: {
        Data.CustomDataType.INDEX: 1,
        Data.CustomDataType.VALUES: '10'
    }
}

eval_context = EvaluationContext(attributes=custom_data_dictionary , targeting_key='userId')

Data.Type.CONVERSION

Use Data.Type.CONVERSION to track a Conversion for a visitor. The Data.Type.CONVERSION field has the following parameters:

Parameter Type Description
Data.ConversionType.GOAL_ID int Identifier of the goal. This field is mandatory.
Data.ConversionType.REVENUE float Revenue associated with the conversion. This field is optional.

Example

from openfeature.evaluation_context import EvaluationContext
from kameleoon_openfeature.types import Data

conversion_dictionary = {
    Data.Type.CONVERSION: {
        Data.ConversionType.GOAL_ID: 1,
        Data.ConversionType.REVENUE: 200
    }
}

eval_context = EvaluationContext(attributes=conversion_dictionary, targeting_key='userId')

Use multiple Kameleoon Data types

You can provide many different kinds of Kameleoon data within a single EvaluationContext instance.

For example, the following code provides one Data.Type.CONVERSION instance and two Data.Type.CUSTOM_DATA instances.

from openfeature.evaluation_context import EvaluationContext
from kameleoon_openfeature.types import Data

data_dictionary = {
    Data.Type.CONVERSION: {
        Data.ConversionType.GOAL_ID: 1,
        Data.ConversionType.REVENUE: 200
    },
    Data.Type.CUSTOM_DATA: [
        {
            Data.CustomDataType.INDEX: 1,
            Data.CustomDataType.VALUES: ['10', '30']
        },
        {
            Data.CustomDataType.INDEX: 2,
            Data.CustomDataType.VALUES: '20'
        }
    ]
}

eval_context = EvaluationContext(attributes=data_dictionary, targeting_key='userId')

Metadata

Release files for kameleoon-openfeature 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kameleoon-openfeature 0.0.1
File Size Uploaded Provenance Actions
kameleoon-openfeature-0.0.1.tar.gz 12.7 kB Without provenance Details for kameleoon-openfeature-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kameleoon-openfeature 0.0.1
File Interpreter ABI Platform Actions
kameleoon_openfeature-0.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for kameleoon_openfeature-0.0.1-py2.py3-none-any.whl

Total release size: 21.0 kB

Release files / kameleoon-openfeature-0.0.1.tar.gz

Download URL kameleoon-openfeature-0.0.1.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
20192af1dd923b94f34e9ec572d869befc5fc7a6971696438ae2d24d2904e3bb
BLAKE2b-256 checksum
How to use checksums
7139e1f4c717f153dfc409c8aed0875b9e5f51e1cc1b547186f0d5e56abfdee9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / kameleoon_openfeature-0.0.1-py2.py3-none-any.whl

Download URL kameleoon_openfeature-0.0.1-py2.py3-none-any.whl
Size 8.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
42af54bbe8866431ff3869a6ca12756a480fa46a88b0783e26aa025e98fb4fcd
BLAKE2b-256 checksum
How to use checksums
7460bda0e84e339e63b8eff021078086e89e53371538f8efcf7ee6d378feea89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Security for kameleoon-openfeature 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page