Konf is a Python package which designed to simplify a process of variables usage in configuration files. json and yaml supported out of the box.
Project description
Konf
Designed to simplify a process of variables usage in configuration files. Importing variables to Python must be easy!
Installation:
pip install konf
Features:
Easy to use
JSON and YAML support out of the box
Require typing or validation of all input data for human factor prevention
Python 2.7, 3+ compatible
Unit-tested
Custom format of configuration files can be used
For Python data structures validation used excellent lib kolypto/py-good
For YAML parsing used great lib of Kirill Simonov PyYAML
How to use this library
It’s pretty simple. Just look at the code.
from konf import Konf
k_ = Konf('fruits.yml')
APPLE = k_('APPLE', basestring)
ORANGE = k_('ORANGE', basestring)
BASKET_OF_MANDARINS = k_('BASKET', [basestring])
NAMED_BANANAS = k_('BANANAS', {'yellow': basestring, 'banana2': basestring})
k2_ = Konf('grades.json')
DAVID_GRADE = k2_('DAVID', int)
MARIA_GRADE = k2_('MARIA', int)
You can find more details and advanced examples about natural validation on documentation of the “good” validation library
List of supporting Exceptions after abnormal situations
- ValidationError:
Raises when data from config file doesn’t match to the type_or_validator arg
- IncompleteConfig:
Raises after trying to get variable that not contained in config file
- ReadError:
Raises when config file can’t be read
- ParseError:
Raises if third-party parser can’t parse configuration file
- ReassignmentError:
Raises if variable is loading from Konf not for the first time
- FileExtensionError:
Raises if extension of the config is not .yml or .json, and parse_callback arg is not specified
That’s it!
Pull-requests are welcome.
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
File details
Details for the file konf-1.0.tar.gz
.
File metadata
- Download URL: konf-1.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
0d639c0425a37bd9f91a17d85546358a3acfb5e273009917a7e1dc8a9e8e343d
|
|
MD5 |
18c5ded11ba26a484a5406161cbc27a9
|
|
BLAKE2b-256 |
1dfb4a002b5c6e13f7ecca716c086d6c756066d64a26964c5774474968b74ec3
|