Skip to main content

Application configuration engine

Project description

Python helper class to ingest and serialize app-specific configuration

Provides a self-contained (no dependencies outside the standard library), Python 2 and 3 compatible configuration manager. Automatically saves and restores your application’s configuration in your user home directory. Uses JSON or (optionally) YAML for serialization. Supports dict-like methods and access semantics.

Installation

If your package does not permit dependency management, you can copy the Config class directly into your application from https://github.com/kislyuk/tweak/blob/master/tweak/__init__.py. Otherwise:

pip install tweak

Synopsis

from tweak import Config

config = Config()
config.host, config.port = "example.com", 9000
config.nested_config = {}
config.nested_config.foo = True

After restarting your application:

config = Config()
print(config)
>>> {'host': 'example.com', 'port': 9000, 'nested_config': {'foo': True}}

Using an argparse.Namespace object returned by argparse.parse_args():

parser = argparse.ArgumentParser()
...
args = parser.parse_args()
if args.foo is not None:
    config.foo = args.foo
elif "foo" not in config:
    raise Exception("foo unconfigured")

config.update(vars(args))

Using YAML:

config = Config(use_yaml=True)
...

Authors

  • Andrey Kislyuk

License

Licensed under the terms of the Apache License, Version 2.0.

https://travis-ci.org/kislyuk/tweak.png https://img.shields.io/coveralls/kislyuk/tweak.svg https://img.shields.io/pypi/v/tweak.svg https://img.shields.io/pypi/dm/tweak.svg https://img.shields.io/pypi/l/tweak.svg https://readthedocs.org/projects/tweak/badge/?version=latest

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

tweak-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

tweak-0.1.1-py2.py3-none-any.whl (6.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file tweak-0.1.1.tar.gz.

File metadata

  • Download URL: tweak-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tweak-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4e892c9ecae1cbade56ff2d88813d8a4252261850d41ddfc6ba5bdebaa918207
MD5 dbb4618357f42a16a8a6d51c1f5a3e41
BLAKE2b-256 4aa4acb964c6813602cdba937e98c62a1216db8bddf4ef6018e8d6099f9d4088

See more details on using hashes here.

File details

Details for the file tweak-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for tweak-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5566e0c4b1a364528773377b94cfbde4a633d615251bcfe9b2f049f6a280205c
MD5 b7dc6ef3081601de8bd68f8c0cd2abaf
BLAKE2b-256 07435b87da522236147e723999802a4fcc50543ab4de648c8ddac5274892a706

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