https://github.com/versada/toggler
Feature Flags Manager
https://github.com/versada/toggler
Last synced: 4 months ago
JSON representation
Feature Flags Manager
- Host: GitHub
- URL: https://github.com/versada/toggler
- Owner: versada
- Created: 2023-03-10T11:56:21.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-07-10T12:22:12.000Z (almost 2 years ago)
- Last Synced: 2026-02-13T19:29:51.484Z (5 months ago)
- Language: Python
- Size: 16.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:
```yaml
---
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
```python
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.
```python
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
...
```