Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

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 `` 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

import yaconf

conf = yaconf.get_file_reader('myapp')

# reading from .myappconf if available, then ~/.config/myapp/.myappconf
conf['ready to go']
conf.get('ready to go', default='fallback')

### Add more configuration sources

def get_default_config():
return {'i': 123, 'b': 'default string'}

# Add this configuration with lowest priority

def get_top_priority_config():
return {'b': 'other string'}

# And this one with highest priority

# To include the new configuration source
assert conf['i'] == 123
assert conf['b'] == 'other string'


### The ConfigReader is a Mapping

assert dict(conf) == {'i': 123, 'b': 'other string'}

### Add a modify function

def modify(d):
d['i'] += 3
del d['b']
d['x'] = 'new'

conf.modify = modify

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.



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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for yaconf, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size yaconf-0.2.0-py2.py3-none-any.whl (4.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size yaconf-0.2.0.tar.gz (9.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page