Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for cfgur, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size cfgur-0.1.3.tar.gz (2.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page