Skip to main content

Feature flag server SDK for python

Project description

Feature Flag Server SDK

https://img.shields.io/pypi/v/harness-featureflags.svg Documentation Status Updates

Overview

Harness is a feature management platform that helps teams to build better software and to test features quicker.

Setup

using terminal install lib with:

pip install harness-featureflags

After package has been added, the SDK elements, primarily CfClient should be accessible in the main application.

Initialization

CfClient is a base class that provides all features of SDK.

"""
Put the API Key here from your environment
"""
api_key = "YOUR_API_KEY";

cf = CfClient(api_key);

"""
Define you target on which you would like to evaluate
the featureFlag
"""
target = Target(identifier="user1")
target = Target(name="User1")

target represents the desired target for which we want features to be evaluated.

"YOUR_API_KEY" is an authentication key, needed for access to Harness services.

Your Harness SDK is now initialized. Congratulations!

Public API Methods

The Public API exposes a few methods that you can utilize:

  • bool_variation(key: str, target: Target, default: bool) -> bool

  • string_variation(key: str, target: Target, default: str) -> str

  • number_variation(key: str, target: Target, default: float) -> float

  • json_variation(String key, Target target, default: dict) -> dict

  • close()

Fetch evaluation’s value

It is possible to fetch a value for a given evaluation. Evaluation is performed based on a different type. In case there is no evaluation with provided id, the default value is returned.

Use the appropriate method to fetch the desired Evaluation of a certain type.

Bool variation

result = cf.bool_variation("sample_boolean_flag", target, False);

Number variation

result = cf.number_variation("sample_number_flag", target, 0);

String variation

result = cf.string_variation("sample_string_flag", target, "");

Using feature flags metrics

Metrics API endpoint can be changed like this:

cf = CfClient(api_key, with_events_url('METRICS_API_EVENTS_URL'));

Otherwise, the default metrics endpoint URL will be used.

Shutting down the SDK

To avoid potential memory leak, when SDK is no longer needed (when the app is closed, for example), a caller should call this method:

cf.close();

History

1.0.1 (2021-07-07)

  • First release on PyPI.

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

harness-featureflags-1.0.5.tar.gz (40.8 kB view hashes)

Uploaded Source

Built Distribution

harness_featureflags-1.0.5-py2.py3-none-any.whl (53.1 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page