Skip to main content

Parse, verify and merge all ini files in a single directory

Project description

CONFINI

Configuration parser that process all sections and values in all ini files in a directory.

Usage

import confini

c = confini.Config('/path/to/config/dir')
c.process()

print(c.get('FOO_BAR_BAZ'))

Value storage

The values are stored in a single key/value dictionary, with section and name separated by underscore and all letters transformed to uppercase.

Consider this value in an ini section:

[foO]
bar_baz = 42

This will be stored in the confini store with FOO_BAR_BAZ as the key.

Environment overrides

By default, the value of any environment variable matching a store key will overwrite the corresponding value in the store.

A prefix can be provided on instantiation to define a separate namespace for environment variable overrides:

>>> os.environ.set('FOO_BAZ_BAZ', 666)
>>> c = config.Config('/path/to/config/dir')
>>> c.process()
>>> print(c.get('FOO_BAR_BAZ'))
666
>>> c = config.Config('/path/to/config/dir', 'XXX')
>>> c.process()
>>> print(c.get('FOO_BAR_BAZ'))
42
>>> os.environ.set('XXX_FOO_BAZ_BAZ', 13)
>>> c = config.Config('/path/to/config/dir', 'XXX')
>>> c.process()
>>> print(c.get('FOO_BAR_BAZ'))
13

Required values

Keys can be set as required, and after processing independently validated:

>>> c = config.Config('/path/to/config/dir')
>>> c.require('BAR_BAZ', 'FOO')
>>> c.process()
>>> c.validate()
True
>>> c = config.Config('/path/to/config/dir')
>>> c.require('BAR_BAZ_BAZ', 'FOO')
>>> c.process()
>>> c.validate()
False

Censoring logs

The string representation of the confini object is a list of all stored values, one on each line.

Display of individual values can be suppressed:

>>> c = config.Config('/path/to/config/dir')
>>> c.process()
>>> print(c)
FOO_BAR_BAZ = 666
>>> c.censor('BAR_BAZ', 'FOO')
>>> print(c)
***

Encryption

Values can be GNUPG encrypted by saving them in individual encrypted files providing the filename as value argument wrapped in a gpg directve:

[foo]
BAR_BAZ = !gpg(foo_bar_baz.asc)

Decryption mode is on by default, and can be deactivated on instantiation:

>>> c = config.Config('/path/to/config/dir')
>>> c.process()
>>> c.get()
666
>>> c = config.Config('/path/to/config/dir', decrypt=False)
>>> c.process()
>>> c.get()
!gpg(foo_bar_baz.asc)

The user keyring in the default location is used for decryption, which may be overridden as usual with the GNUPGHOME environment variable.

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

confini-0.3.6b2.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

confini-0.3.6b2-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file confini-0.3.6b2.tar.gz.

File metadata

  • Download URL: confini-0.3.6b2.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for confini-0.3.6b2.tar.gz
Algorithm Hash digest
SHA256 f6923be409426258f9fb22fce96aff44d12c886970f32021356202e4c2e8f878
MD5 0acc2c50d9ad5d160f2bd300c02040c1
BLAKE2b-256 3068cdd4877f4d19a2a611b1806693219a36582ca9cdc34d1c10e820c273da9a

See more details on using hashes here.

File details

Details for the file confini-0.3.6b2-py3-none-any.whl.

File metadata

  • Download URL: confini-0.3.6b2-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for confini-0.3.6b2-py3-none-any.whl
Algorithm Hash digest
SHA256 98007897b09c9b156c8916837b915614f505cc37ff141e9957eeff9a12c811b7
MD5 f6309f9891ec236c2e9bf40ff2cccc80
BLAKE2b-256 b7c90ef0557dc3fb645435feb50de636b2a1eed090f37d26a70854629ab1df63

See more details on using hashes here.

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