Simple config parser with evaluator library.
Project description
Simple config parser with evaluator library.
Why Another Config Parser Module?
This project inspired of the necessity complex config in a project. By means complex:
Reusability
Import values from file
Reference values from other object
Secure
Encrypt/decrypt sensitive values
Flexible
Make logical expression to derive values
Powerful
Add custom functions in Python
Link name data from Python
TODO
[X] Setup basic necessity
[X] Stop procrastinating
[X] Project registration in pypi
[X] Create unit tests
[X] Setup travis
[X] Setup coveralls
[ ] Add more support on Python versions
[ ] 2.7
[ ] 2.8
[ ] 3.0
[ ] 3.1
[ ] 3.2
[ ] 3.3
[ ] 3.4
[ ] 3.5
[X] 3.6
[ ] Features
[ ] Test on multilanguage
[ ] Add better exception handling
[ ] Add circular dependencies error
[ ] Ensure this is good on production environment
[ ] Improve docs
[ ] Make github layout code into two left -> right
[ ] Put more examples
[ ] Setup readthedocs
Install
[sudo] pip install conff
Basic Usage
To get very basic parsing:
import conff
r = conff.parse({'math': '1 + 3'})
r = {'math': '4'}
load YAML file
import conff
r = conff.load('path_of_file.yaml')
import files
import conff
## y1.yml
# shared_conf: 1
## y2.yml
# conf: F.inc('y1.yml')
r = conff.load('y2.yml')
r = {'conf': {'shared_conf': 1}}
Examples
More advances examples:
Parse with simple expression
import conff
r = conff.parse('1 + 2')
r = 3
Parse object
import conff
r = conff.parse({"math": "1 + 2"})
r = {'math': 3}
Ignore expression (declare it as string)
import conff
r = conff.parse('"1 + 2"')
r = '1 + 2'
Parse error behaviours
import conff
errors = []
r = conff.parse({"math": "1 / 0"}, errors=errors)
r = {'math': '1 / 0'}
errors = [['1 / 0', ZeroDivisionError('division by zero',)]]
Parse with functions
import conff
def fn_add(a, b):
return a + b
r = conff.parse('F.add(1, 2)', fns={'add': fn_add})
r = 3
Parse with names
import conff
r = conff.parse('a + b', names={'a': 1, 'b': 2})
r = 3
Parse with extends
import conff
data = {
't1': {'a': 'a'},
't2': {
'F.extend': 'R.t1',
'b': 'b'
}
}
r = conff.parse(data)
r = {'t1': {'a': 'a'}, 't2': {'a': 'a', 'b': 'b'}}
Parse with updates
import conff
data = {
't1': {'a': 'a'},
't2': {
'b': 'b',
'F.update': {
'c': 'c'
},
}
}
r = conff.parse(data)
r = {'t1': {'a': 'a'}, 't2': {'b': 'b', 'c': 'c'}}
Parse with extends and updates
import conff
data = {
't1': {'a': 'a'},
't2': {
'F.extend': 'R.t1',
'b': 'b',
'F.update': {
'a': 'A',
'c': 'c'
},
}
}
r = conff.parse(data)
r = {'t1': {'a': 'a'}, 't2': {'a': 'A', 'b': 'b', 'c': 'c'}}
Test
To test this project:
nose2
Other Open Source
This project uses other awesome projects:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.