Skip to main content

Feature flag server SDK for python

Project description

Harness Feature Flag Python SDK

pypi

Table of Contents

Intro
Requirements
Quickstart
Further Reading
Build Instructions

Intro

Harness Feature Flags (FF) is a feature management solution that enables users to change the software’s functionality, without deploying new code. FF uses feature flags to hide code or behaviours without having to ship new versions of the software. A feature flag is like a powerful if statement.

FeatureFlags

Requirements

Python 3.7 or newer (python --version)
pip

For Mac users if you don't already have pyenv or something similar installed for managing python version

Quickstart

The Feature Flag SDK provides a client that connects to the feature flag service, and fetches the value of featue flags. The following section provides an example of how to install the SDK and initalize it from an application. This quickstart assumes you have followed the instructions to setup a Feature Flag project and have created a flag called harnessappdemodarkmode and created a server API Key.

Install the SDK

Install the python SDK using pip

python -m pip install harness-featureflags

A Simple Example

Here is a complete example that will connect to the feature flag service and report the flag value every 10 seconds until the connection is closed.
Any time a flag is toggled from the feature flag service you will receive the updated value.

import time

from featureflags.client import CfClient
from featureflags.config import *
from featureflags.evaluations.auth_target import Target
from featureflags.util import log


def main():
    # API Key
    apiKey = "c9b3f14f-6336-4d23-83b4-73f29d1ebeeb"

    # Create a Feature Flag Client
    client = CfClient(apiKey)

    # Create a target (different targets can get different results based on rules)
    target = Target(identifier='mytarget', name="FriendlyName")

    # Loop forever reporting the state of the flag
    while True:
        result = client.bool_variation('harnessappdemodarkmode', target, False)
        log.info("Flag variation %s", result)
        time.sleep(10)

    close()


if __name__ == "__main__":
    main()

Running the example

$ python3 examples/basic_example/basic.py

Additional Reading

Further examples and config options are in the further reading section:

Further Reading


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


======= 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.6.tar.gz (139.8 kB view hashes)

Uploaded Source

Built Distribution

harness_featureflags-1.0.6-py2.py3-none-any.whl (53.4 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