Multi-profile supported, flexible config library
Project description
octoconf
Multi-profile supported, flexible config library for Python 2 & 3.
Features
Allow multiple config profiles in one YAML file
Overridable profile selection from code for special use-cases (e.g. config for testing)
Inheritable config profiles, what makes profile merges by dictionaries. (the native YAML bookmarking is also available)
Can use variables in the config file
Installation
pip install octoconf
Config format
An octoconf YAML file have two restricted keywords:
- USED_CONFIG>: <node_name> in the file root
you can specify the name of default config profile
- <BASE: <node_name> in the 2nd level
this will used for making (merge based) inheritance between profiles
The profile nodes should be on 1st level!
Usage
There is an example YAML for demonstration
USED_CONFIG>: Fruits
Fruits:
RED: 1
YELLOW: $VAR1/2
SmallFruits:
<BASE: Fruits
RED: 3
ExtraSmallFruits:
<BASE: SmallFruits
RED: 4
Basic case
Read a multiple config contained YAML, and get profile which was selected by default.
- Example YAML:
USED_CONFIG>: Fruits Fruits: Small: RED: 1 YELLOW: 2 Vegetables: Big: RED: 3 YELLOW: 4
- Reader code:
import octoconf yaml = octoconf.read('/test/foo.yaml') print(yaml)
- Results:
{ 'Small': { 'RED': 1, 'YELLOW': 2 } }
Variables
Read a YAML file which contains variables.
- Example YAML:
USED_CONFIG>: Fruits Fruits: Small: RED: 1 YELLOW: XXX${VAR1}XXX Vegetables: GREEN: 2
- Reader code:
import octoconf yaml = octoconf.read('/test/foo.yaml', variables={'VAR1': '/test1'}) print(yaml)
- Results:
{ 'Small': { 'RED': 1, 'YELLOW': 'XXX/test1XXX' } }
Inheritance
Read a multiple config contained YAML, where the selected config is inherited from another config.
ExtraSmallFruits >> SmallFruits >> Fruits
- Example YAML:
USED_CONFIG>: ExtraSmallFruits Fruits: Small: RED: 1 YELLOW: 2 GREEN: 3 SmallFruits: <BASE: Fruits Small: RED: 4 YELLOW: 5 ExtraSmallFruits: <BASE: SmallFruits Small: RED: 6
- Reader code:
import octoconf yaml = octoconf.read('/test/foo.yaml') print(yaml)
- Results:
{ 'Small': { 'RED': 6, 'YELLOW': 5 'GREEN': 3, } }
More example
Please check the examples directory.
Bugs
Bugs or suggestions? Visit the issue tracker.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.