Skip to main content

A quick and extensible configuration management system

Project description

Pyning

A quick and extensible configuration management library

https://pypi.org/project/pyning/

Pyning lets you take configuration entries in key/value pairs, and query by key. For example, you might just use a dict (or any Mapping type):

args = { 'stop-on-error': True }
registry = pyning.config.Registry()
config = registry.add( args ).resolve()

print( config[ 'stop-on-error' ] )
# True

Keys are used as attributes on the resolved object, and can be used in the usual way:

args = { 'stop_on_error': True }
registry = pyning.config.Registry()
config = registry.add( args ).resolve()

print( config.stop_on_error )
# True

NB: keys with spaces, or other python syntax elements (like '-') will cause this syntax to fail, but such keys can still be found with the dictionary-key lookup.

Multiple levels of handler are possible, with later handlers override same-key settings in earlier handlers.

args = { 'stop_on_error': True }
overrides = { 'stop_on_error': False }
registry = pyning.config.Registry()
config = registry.add( args ).add( overrides ).resolve()

print( config.stop_on_error )
# False

You might use this to have some configuration in a file, and override with the argparse.ArgumentParser values.

args = { 'stop_on_error': True }
parser = argparse.ArgumentParser()
parser.add_argument( '--stop_on_error' ) 

cmdline = parser.parse_args()
registry = pyning.config.Registry()
config = registry.add( args ).add( vars( cmdline ) ).resolve()

print( config.stop_on_error )
# False

Values can use a limited variable substitution to swap in values from different keys. This is especially useful when using the overrides feature. At present, it only works for strings.

public_args = { 'password': '${private_password}' }
overrides = { 'private_password': 'a good strong password' }
registry = pyning.config.Registry()
config = registry.add( public_args ).add( overrides ).resolve()

print( config.password )
# a good strong password

The syntax used to match a variable substitution can be changed by passing in a different regular expression pattern to the Registry constructor. The default is '${variable name}', matched against r'(\$\{(.*?)\})'

Values don't have to be single items: they can be sequences or even nested Mapping objects. A convenient short-hand can be used to refer to nested keys, and works with variable substitution, too.

    import json

    args = { 'url': '${remotes.endpoint}' }
    overrides = json.loads( '''
        { "remotes": {
            "endpoint": "http://nowhere"
        } } '''
                            )

    cfg = Registry().add( args ).add( overrides ).resolve()
    print( cfg.url )

Also, nested mapping objects can still use a nested attribute lookup, too:

    import json

    args = { 'url': '${remotes.endpoint}' }
    overrides = json.loads( '''
        { "remotes": {
            "endpoint": "http://nowhere"
        } } '''
                            )

    cfg = Registry().add( args ).add( overrides ).resolve()
    print( cfg.remotes.endpoint )

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

pyning-0.1a10.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyning-0.1a10-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file pyning-0.1a10.tar.gz.

File metadata

  • Download URL: pyning-0.1a10.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for pyning-0.1a10.tar.gz
Algorithm Hash digest
SHA256 9aa0ea6d42ad0916d203cb605e0e4ebbabc019f3d766032f2f759fff22cd0685
MD5 cfa043366139346948071bcc0946f399
BLAKE2b-256 a257649757e2ab32241b1afaba511cadcfb9f3537d2f3d03ca759a26a2518103

See more details on using hashes here.

File details

Details for the file pyning-0.1a10-py3-none-any.whl.

File metadata

  • Download URL: pyning-0.1a10-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for pyning-0.1a10-py3-none-any.whl
Algorithm Hash digest
SHA256 ba4bfa763c0e237891015e150456bb26eef7454cb9632f9a59c605d337a7bc38
MD5 31ba62bb0eff5209e68699cdbc8a1309
BLAKE2b-256 da0e1f7097e169fa5f355ca61509645a71ddab983545cd56e67a91d85cf37a52

See more details on using hashes here.

Supported by

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