Yet another configuration library
Project description
# yaconf
yet another Python configuration library
## Features
No frills, no fuss:
* Python 3.6+ and no external dependencies.
* Single file implementation: Import the package or just copy `yaconf.py` into your project.
* Use any configuration source: any function that returns a `dict` will do.
* Reads JSON files by default, but `configparser` or any other parser can be dropped in with a keyword argument.
* Hierarchical configuration: Look for configuration keys in one config source after another, e.g.,
- first check `.myappconf` file,
- then `~/.config/myapp/.myappconf`,
- finally fall back on defaults.
* Sane defaults for config file paths:
- `~/.config/myapp/.myappconf` on Linux and MacOS
- `%LOCALAPPDATA%\myapp\.myappconf` on Windows
* Optionally register a modifier function to arbitrarily change values after loading (e.g., change datatypes, check consistency, etc).
## Examples
### Basic setup
```python
import yaconf
conf = yaconf.get_file_reader('myapp')
conf.load()
# reading from .myappconf if available, then ~/.config/myapp/.myappconf
conf['ready to go']
conf.get('ready to go', default='fallback')
```
### Add more configuration sources
```python
def get_default_config():
return {'i': 123, 'b': 'default string'}
# Add this configuration with lowest priority
conf.loaders.append(get_default_config)
def get_top_priority_config():
return {'b': 'other string'}
# And this one with highest priority
conf.loaders.push(get_top_priority_config)
# To include the new configuration source
conf.load()
assert conf['i'] == 123
assert conf['b'] == 'other string'
```
### The ConfigReader is a Mapping
```python
assert dict(conf) == {'i': 123, 'b': 'other string'}
```
### Add a modify function
```python
def modify(d):
d['i'] += 3
del d['b']
d['x'] = 'new'
conf.modify = modify
conf.load()
assert dict(conf) == {'i': 126, 'x': 'new'}
```
## License
Free software: MIT license
## Credits
This package was created with [Cookiecutter][1] and the [`audreyr/cookiecutter-pypackage`][2] project template.
[1]: https://github.com/audreyr/cookiecutter
[2]: https://github.com/audreyr/cookiecutter-pypackage
=======
History
=======
0.2.0 (2019-04-10)
------------------
* Allow for a modify function to be added to ConfigReader.
* Remove the levels property on ConfigReader.
* Make ConfigReader follow the Mapping protocol.
* Rename Decoder -> Parser.
0.1.0 (2019-04-09)
------------------
* First release on PyPI.
yet another Python configuration library
## Features
No frills, no fuss:
* Python 3.6+ and no external dependencies.
* Single file implementation: Import the package or just copy `yaconf.py` into your project.
* Use any configuration source: any function that returns a `dict` will do.
* Reads JSON files by default, but `configparser` or any other parser can be dropped in with a keyword argument.
* Hierarchical configuration: Look for configuration keys in one config source after another, e.g.,
- first check `.myappconf` file,
- then `~/.config/myapp/.myappconf`,
- finally fall back on defaults.
* Sane defaults for config file paths:
- `~/.config/myapp/.myappconf` on Linux and MacOS
- `%LOCALAPPDATA%\myapp\.myappconf` on Windows
* Optionally register a modifier function to arbitrarily change values after loading (e.g., change datatypes, check consistency, etc).
## Examples
### Basic setup
```python
import yaconf
conf = yaconf.get_file_reader('myapp')
conf.load()
# reading from .myappconf if available, then ~/.config/myapp/.myappconf
conf['ready to go']
conf.get('ready to go', default='fallback')
```
### Add more configuration sources
```python
def get_default_config():
return {'i': 123, 'b': 'default string'}
# Add this configuration with lowest priority
conf.loaders.append(get_default_config)
def get_top_priority_config():
return {'b': 'other string'}
# And this one with highest priority
conf.loaders.push(get_top_priority_config)
# To include the new configuration source
conf.load()
assert conf['i'] == 123
assert conf['b'] == 'other string'
```
### The ConfigReader is a Mapping
```python
assert dict(conf) == {'i': 123, 'b': 'other string'}
```
### Add a modify function
```python
def modify(d):
d['i'] += 3
del d['b']
d['x'] = 'new'
conf.modify = modify
conf.load()
assert dict(conf) == {'i': 126, 'x': 'new'}
```
## License
Free software: MIT license
## Credits
This package was created with [Cookiecutter][1] and the [`audreyr/cookiecutter-pypackage`][2] project template.
[1]: https://github.com/audreyr/cookiecutter
[2]: https://github.com/audreyr/cookiecutter-pypackage
=======
History
=======
0.2.0 (2019-04-10)
------------------
* Allow for a modify function to be added to ConfigReader.
* Remove the levels property on ConfigReader.
* Make ConfigReader follow the Mapping protocol.
* Rename Decoder -> Parser.
0.1.0 (2019-04-09)
------------------
* First release on PyPI.
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
yaconf-0.2.0.tar.gz
(9.9 kB
view details)
Built Distribution
File details
Details for the file yaconf-0.2.0.tar.gz
.
File metadata
- Download URL: yaconf-0.2.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 120852eb5f67cee683c059646c52ff21eb769a3183e609b0d1155347f3154369 |
|
MD5 | d72de6cd84421b463a11697d15662bff |
|
BLAKE2b-256 | fb8a6368d1b522bad3190f12141c0702d5145395e1ca72cb561533b2a0e05e62 |
File details
Details for the file yaconf-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: yaconf-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f15f65d89b0ae19766fa85386f3d3eec304cf0036bc1d8d0edb36a53c637df3 |
|
MD5 | a95a31abf7954031c0c7cb936959fc71 |
|
BLAKE2b-256 | 96b2304b97ab527978517aa5ac4bfd63258db264032e8b263dbb56f0218df2a9 |