Skip to main content

Practical configuration system

Project description

A practical configuration system for Python.

With fitb, you specify a collection of configuration options that your program/library/whatever needs. fitb then helps you construct configuration objects and merge them together.

A configuration object is simply a dict, so fitb is helping you build dicts. A configuration option specifies a path into the dict - that is, a sequence of keys into the dict and subdicts - along with a description of the option and a default value.

Quick start

The first thing you do with fitb is define a collection of config options:

options = [(('my-app', 'screen'), fitb.Option('width', 'Width of screen', 100)),
           (('my-app', 'screen'), fitb.Option('height', 'Height of screen', 200))]

Each entry in the list specifies a prefix path and the option itself. From this we can build a default config option:

config = fitb.build_default_config(options)

This gives us an object like this:

{'my-app': {'screen': {'width': 100, 'height': 200}}}

with which can do things like this:

print(config['my-app']['screen']['width']

or work with subconfigs:

screen_config = config['my-app']['screen']
print(screen_config['width'])

You can also merge configs together, putting entries from one config into another, possibly overwriting exiting options. That looks like this:

fitb.merge(dest=config, src={'my-app': {'screen': {'width': 400}}})

# The `dest` config has been updated
assert config['my-app']['screen']['width'] == 400

This ability to merge is useful because you can do things like:

  1. Create a default config

  2. Load user configs from files (e.g. TOML, ini, or whatever)

  3. Merge user configs into the default config.

Project details


Download files

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

Source Distribution

fitb-1.0.1.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

fitb-1.0.1-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page