Feature flag server SDK for python
Project description
Feature Flag Server SDK
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for harness-featureflags-1.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a37450f25a26a2e64268ccc238d93cf9610d112c6b609343bbe3144800316d4 |
|
MD5 | 50f96210088eaf3165692e4713271612 |
|
BLAKE2b-256 | 2e830295ba5f1b33b5c8088d3e2654ab3d5f95c06bbebdd622ccf66d2197e508 |
Hashes for harness_featureflags-1.0.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcd692bef894588cf03aef16e80ff0accd9467816ca8633ff3c85d5654e45686 |
|
MD5 | 29d55222a58dc0920fc5e2cbe5778cb8 |
|
BLAKE2b-256 | 6a1c79a9b8621124f2744c5292c437cd1d7ec59454fb1c62ff5152ae85a4a4ed |