Load environment vars, and command line arguments in a predictable, standardized way
Project description
cfgur (configure)
Load environment vars, and command line arguments in a predictable, standardized way.
This package wraps argparse, loading config from environment variables as well as the usual command line arguments / flags. A config object is passed into init(), configuring argparse. The environment variables are implied from the arg name (stripped, uppercased and underscored), but can be manually defined using the key "env_var" in args config. Once args are loaded, config is accessable using a getter function "get()". To get all variables, use get_all(). The args object keys are passed to parser.add_argument().
Installation
The cfgur package is available on PyPI which means installation should be as simple as:
$ pip install cfgur
Usage
import cfgur
# Initialize once, pass in config
cfgur.init({
"parser": {
"description": "this is the service description"
},
"args": [
{
"name": "-test",
"help": "Description of test",
"default": "test-db",
"required": False,
}, {
"name": "--foo",
"required": True,
}, {
"name": "-f",
"required": False,
"env_var": "LETTER_F",
}
]
})
# Return value of config. If missing, return None
my_config = cfgur.get_all()
# Return value of config. If missing, return None
test_val = cfgur.get("test")
# Return value of config. If missing, raise KeyError
test_val = cfgur.get("test", True)
License
This software is licensed under the MIT license.
© 2018 Bray Almini.
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
File details
Details for the file cfgur-0.1.3.tar.gz
.
File metadata
- Download URL: cfgur-0.1.3.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69b9af1a241ed471646589be825b4d3291a82529898eb157fe530ad4474957cc |
|
MD5 | eadc5c0443ea3bd9232320f0574ec828 |
|
BLAKE2b-256 | d1376c900e2853451ffcdb2a255bdc24b83c259a0d08f0df7d6119dcfdcae76f |