Skip to main content

Python SDK for the Plain Flags free feature flag system

Project description

Plain Flags Python SDK

This module facilitates your software's connection to the Plain Flags feature flag system.

Requirements

You must host an installation of the Plain Flags feature flag back end services.

More about Plain Flags at plainflags.dev

The Plain Flags back end must run in an environment where your software can make http requests.

Installation

pip install plain-flags-sdk

Usage

Import the Plain Flags SDK package:

from plainflags import PlainFlags, PlainFlagsConfig

Create and configure an object of type PlainFlags at the start of your software's execution:

    config = PlainFlagsConfig(
        service_url="http://my-plainflags-states.dev",
        api_key="mySharedSecret",
        timeout_ms=10000,
        poll_interval_ms=30000)  # Poll every 30 seconds, or set to 0 to disable polling

    feature_flags = PlainFlags(config,
                              infoFunc=logging.info,  # Optional: provide custom logging functions
                              errorFunc=logging.error)

Initialize the object. The init() method is a coroutine:

    await feature_flags.init()

When your application is shutting down, stop the background polling if enabled:

    await feature_flags.stop_updates()

Any feature code you wish to enable and disable with feature flags will be within conditions like this:

if feature_flags.is_on("My feature"):
    # Your feature code here
    pass

You can provide a default value to return if the flag is not found:

if feature_flags.is_on("My feature", default=False):
    # Your feature code here
    pass

If your features are constrained to subsets of your users, you must specify which user is currently using the software (and other context you constrain your feature for, if applicable).

if feature_flags.is_on("My Feature", default=False, context={
    "userId": current_user().id,
    "countryCode": current_country_code(),
}):
    # Your feature code here
    pass

The keys userId and countryCode must match the constraint keys you created in the dashboard

Source code

github link

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

plain_flags_sdk-1.0.3.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

plain_flags_sdk-1.0.3-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file plain_flags_sdk-1.0.3.tar.gz.

File metadata

  • Download URL: plain_flags_sdk-1.0.3.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for plain_flags_sdk-1.0.3.tar.gz
Algorithm Hash digest
SHA256 7be845aef58788ac78b7daaa204702265ffb22bcd19d228495c916670b7be0f7
MD5 c6c342e94dd04d7f58bd781e82f304f7
BLAKE2b-256 2404e214805146b6fcd047e8e7f9c9459fc86b426af25e61686eb37d65ca927b

See more details on using hashes here.

File details

Details for the file plain_flags_sdk-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for plain_flags_sdk-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0c25cd0c54e181e81efe0da5ea2f16e7351fd8bf0bfc101c160d853ec5c270ef
MD5 bb2df2cee563bc6423ed7751bcd2fbed
BLAKE2b-256 3eb24aa65d6ffb8607c7100621cb77b39fc565356fc0bca7505e21bc6cbf2987

See more details on using hashes here.

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