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) ...
Pass Config(save_on_exit=False) to disable automatic configuration saving on Python shutdown (this is useful if you only want to read the config, never write it, or if you want to call config.save() manually). Pass Config(autosave=True) to make save() run any time an assignment happens to a config object.
Links
Bugs
Please report bugs, issues, feature requests, etc. on GitHub.
License
Licensed under the terms of the Apache License, Version 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tweak-0.3.0.tar.gz
.
File metadata
- Download URL: tweak-0.3.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ca234969ae95ea35512969e09ff322d71782c989eacce36873d51323cf71c9b |
|
MD5 | c364fb2df4d6d3071c1d361b4f237aab |
|
BLAKE2b-256 | e760f4234e39a00f6230f1798d442476064fc9b39fe77d16eca7f41c8f4a567e |
File details
Details for the file tweak-0.3.0-py2.py3-none-any.whl
.
File metadata
- Download URL: tweak-0.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80a07ab46bbb3b342cc263ae85c7aee851c417a779d879480a5bb8b441c93a2b |
|
MD5 | b4a00ffa76cf936a6eee3196bfdb563e |
|
BLAKE2b-256 | 8bc1715a3ae9ffd6e23be3de173fb7a755d6e1bb463886faeae9e3ec7467a584 |