Skip to main content

A configuration library.

Project description

profig is a configuration library for Python.

https://travis-ci.org/dhagrow/profig.svg?branch=master

Motivation

Why another configuration library? The simple answer is that none of the available options gave me everything I wanted, with an API that I enjoyed using. This library is as close to my ideal as I have been able to come. It tries to provide some (but not too much) powerful functionality, without sacrificing simplicity.

Features

  • Automatic value conversion.

  • Section nesting.

  • Dict-like access.

  • Extensible input/output formats.

  • Built-in support for INI files and the Windows registry.

  • Preserves ordering and comments of INI files.

  • Full Unicode support.

  • Supports Python 2.7+ and 3.2+.

Installation

profig installs using easy_install or pip:

$ pip install profig

Example

Basic usage is cake. Let’s assume our config file looks like this:

[server]
host = 192.168.1.1
port = 9090

First, we specify the defaults and types to expect:

>>> cfg = profig.Config('server.cfg')
>>> cfg.init('server.host', 'localhost')
>>> cfg.init('server.port', 8080)

Then, we sync our current state with the state of the config file:

>>> cfg.sync()

As expected, we can access the values directly without any extra effort, either directly:

>>> cfg['server.host']
'192.168.1.1'

Or by section. Notice that the type of the port option is preserved:

>>> server_cfg = cfg.section('server')
>>> server_cfg['port']
9090

Resources

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

profig-0.4.0.tar.gz (17.4 kB view hashes)

Uploaded Source

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