Yapconf

https://img.shields.io/pypi/v/yapconf.svg https://img.shields.io/travis/loganasherjones/yapconf.svg https://codecov.io/gh/loganasherjones/yapconf/branch/master/graph/badge.svg Documentation Status Updates

Yet Another Python Configuration. A simple way to manage configurations for python applications.

Yapconf allows you to easily manage your python application’s configuration. It handles everything involving your application’s configuration. Often times exposing your configuration in sensible ways can be difficult. You have to consider loading order, and lots of boilerplate code to update your configuration correctly. Now what about CLI support? Migrating old configs to the new config? Yapconf can help you.

Features

Yapconf helps manage your python application’s configuration

  • JSON/YAML config file support
  • Etcd config support
  • Kubernetes ConfigMap support
  • Argparse integration
  • Environment Loading
  • Configuration watching
  • Migrate old configurations to new configurations
  • Generate documentation for your configuration

Quick Start

To install Yapconf, run this command in your terminal:

$ pip install yapconf

Then you can use Yapconf yourself!

Load your first Config

from yapconf import YapconfSpec

# First define a specification
my_spec = YapconfSpec({"foo": {"type": "str", "default": "bar"}}, env_prefix='MY_APP_')

# Now add your sources (order does not matter)
my_spec.add_source('environment', 'environment')
my_spec.add_source('config.yaml', 'yaml', filename='/path/to/config.yaml')

# Then load the configuration in whatever order you want!
# load_config will automatically look for the 'foo' value in
# '/path/to/config.yml', then the environment, finally
# falling back to the default if it was not found elsewhere
config = my_spec.load_config('config.yaml', 'environment')

print(config.foo)
print(config['foo'])

Add CLI arguments based on your configuration

import argparse

parser = argparse.ArgumentParser()

# This will add --foo as an argument to your python program
my_spec.add_arguments(parser)

cli_args = vars(parser.parse_args(sys.argv[1:]))

# Now you can load these via load_config:
config = my_spec.load_config(cli_args, 'config.yaml', 'environment')

Watch your config for changes

def my_handler(old_config, new_config):
    print("TODO: Something interesting goes here.")

my_spec.spawn_watcher('config.yaml', target=my_handler)

Generate documentation for your config

# Show me some sweet Markdown documentation
my_spec(spec.generate_documentation())

# Or write it to a file
spec.generate_documentation(output_file_name='configuration_docs.md')

For more detailed information and better walkthroughs, checkout the documentation!

Documentation

Documentation is available at https://yapconf.readthedocs.io

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.