Skip to main content

python INI configuration library

Project description

version-badge coverage-badge

conficus is a python toml configuration wrapper. providing some extra type coercions (e.g. str -> Path) easier access and section inheritance.

conficus python 3.6+.

Installation

Install conficus with pip.

pip install conficus

Quick Start

Basic usage

>>>
>>> import conficus
>>>

Configurations can be loaded directly from a string variable or read via file path string or Path object:

>>> config = conficus.load('/Users/mgemmill/config.ini', toml=True)
>>>

conficus will also read a path from an environment variable:

>>> config = conficus.load('ENV_VAR_CONFIG_PATH')
>>>

Easier Selection

Accessing nested sections is made easier with chained selectors:

>>> # regular dictionary access:
...
>>> config['app']['debug']
True
>>>
>>> # chained selector access:
...
>>> config['app.debug']
True

Inheritance

Inheritance pushes parent values down to any child section:

# config.ini

[app]
debug = true

[email]
_inherit = 0
host = "smtp.mailhub.com"
port = 2525
sender = "emailerdude@mailhub.com"

[email.alert]
to = ["alert-handler@service.com"]
subject = "THIS IS AN ALERT"
body = "Alerting!"

It is turned on via the inheritance option:

>>> config = conficus.load("config.ini", inheritance=True)

Sub-sections will now contain parent values:

>>> alert_config = config["email.alert"]
>>> alert_config["host"]
>>> "smtp.mailhub.com"
>>> alert_config["subject"]
>>> "THIS IS AN ALERT"

Inheritence can be controled per section via the _inherit option. _inherit = 0 will block the section from inheriting parent values. _inherit = 1 would only allow inheritance from the sections immediate parent; _inherit = 2 would allow both the immediate parent and grandparent inheritance.

_inherit values are stripped from the resulting configuration dictionary.

Additional Conversion Options

In addition to toml’s standard type conversions, conficus has two builtin conversion options and also allows for adding custom conversions.

Conversions only work with string values.

Path Conversions

The pathlib option will convert any toml string value that looks like a path to a python pathlib.Path object:

>>> config = conficus.load("path = '/home/user/.dir'", pathlib=True)
>>> isinstance(config["path"], Path)
>>> True

Decimal Conversions

The decimal option will convert any toml string value that matches \d+\.\d+ to a python Decimal object:

>>> config = conficus.load("number = '12.22'", decimal=True)
>>> isinstance(config["number"], Decimal)
>>> True

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

conficus-0.6.2.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

conficus-0.6.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file conficus-0.6.2.tar.gz.

File metadata

  • Download URL: conficus-0.6.2.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.5 Linux/5.4.0-65-generic

File hashes

Hashes for conficus-0.6.2.tar.gz
Algorithm Hash digest
SHA256 42bf110b3e8011c7e54c63a67968f3c149f250a64a56ee88547caedf1bead770
MD5 bdbbab4df6fa5afed10dc3dbaee90143
BLAKE2b-256 9ecd670ec94c5d357aa28640ae39f9eada876742e95fd1d9df53d3b9def873b7

See more details on using hashes here.

File details

Details for the file conficus-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: conficus-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.5 Linux/5.4.0-65-generic

File hashes

Hashes for conficus-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 080e2d6a59505416bfa48e3d98ed8a595bfd23eb0a7ddb5abe1c84e67dc7856c
MD5 2d1fd81081b4de08c56730a9a0cc4dfc
BLAKE2b-256 7ddc65159b2f163792ebbc219f76deb4db93fb485ca7b32efa8025e337725fbe

See more details on using hashes here.

Supported by

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