Toggler
Toggler allows to set up feature toggles (flags) on a YAML file and validate whether specific flag is ON or OFF on specific environment.
How to Use
Configure Feature Toggles
Feature toggles are configured in yaml file:
---
feature1:
modes: [prod, stage]
date: 2023-01-01
days_to_expire: 10
ref: r123
feature2:
modes: [stage]
date: 2023-01-01
feature3:
modes: [other]
date: 2023-01-01
Structure:
- modes (e.g prod, stage), defines features enabled on specific mode.
- features (e.g feature1, feature2) are feature names used to identify which
feature is used or not:
- active: whether feature is enabled or not. If feature is not defined on specific mode, it is implicitly treated as disabled. This is the only required field.
- ref: reference to feature or ticket (for convenience).
- date: when feature flag was added.
- days_to_expire: how many days feature flag is to stay. Warning logs will be written after deadline.
Define mode and config file path
You can either explicitly initialize Toggler with its optional arguments, mode and path (or stream) or you can use environment variables TOGGLER_MODE and TOGGLER_CFG.
For example:
TOGGLER_MODE=prod TOGGLER_CFG=/path/to/tog.yml my-app
Initialize Toggler and check features activity
from toggler.toggler import Toggler
tog = Toggler() # expecting specified env variables
if tog.is_active("feature1"):
# feature1 logic
...
else:
# old logic
...
Using toggler in tests
You can force toggle feature to make it easier to test.
from toggler.services.env import toggle_feature
def test_feature1_on():
with toggle_feature("feature1", True): # Force enable
# test if feature1 logic works as expected
...
def test_feature1_off():
with toggle_feature("feature1", False): # Force disable
# test if logic without feature1 works as expected
...
Metadata
Release files for toggler 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| toggler-0.3.0.tar.gz | 9.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| toggler-0.3.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 18.1 kB
Release files / toggler-0.3.0.tar.gz
| Download URL | toggler-0.3.0.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6a33eb0b67c4e5f193c01e3b3fede285bdef8aa8d8e4a07684ee196b521a422
|
|
BLAKE2b-256 checksum How to use checksums |
e8b62feb83a33c267a99e2fdb908bbf9807497e774536695a13074f0af018c98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / toggler-0.3.0-py2.py3-none-any.whl
| Download URL | toggler-0.3.0-py2.py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c628430ab3b5e8e892734b413c76de278873a05d594b1a5c019cfe847ddb05c3
|
|
BLAKE2b-256 checksum How to use checksums |
1d6c809283c3cdfbb2dc72867c8b08b8720e2adf4fb986a4e273a7efb61c7855
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|