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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plain_flags_sdk-1.0.2.tar.gz.
File metadata
- Download URL: plain_flags_sdk-1.0.2.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5115b49ac3f161c1a84c1c7d00c64d10e95d9c612d9808551bdbf98d873f3e6
|
|
| MD5 |
98965a17c29be5b5e5d7c77be2381f0b
|
|
| BLAKE2b-256 |
2215d6b66637f44ccf57cc2fbb8b8fbcbc468899fe5ab461c58728df2f2afed4
|
File details
Details for the file plain_flags_sdk-1.0.2-py3-none-any.whl.
File metadata
- Download URL: plain_flags_sdk-1.0.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a88516f8cd8f84d1becb30d74e0dbbb1f8289c30ad0779e5e881747199e2a76e
|
|
| MD5 |
0c88708de1e8abd246c62294266facdc
|
|
| BLAKE2b-256 |
820eaed72c4652c86aaadca9ed4cab6c6668b687c978596badf2314ed9f6d78d
|