Skip to main content

Argparse wrapper that supports fallback settings in env vars and/or a yaml file.

Project description

appsettings

Sometimes you want to read a setting from the command line. Sometimes you want to read it from an environment variable. Sometimes you want to read it from a config file.

And in some very special times, you want to allow the value to be passed using some combination of the three.

The appsettings module provides an argparse subclass that allows pulling settings from the command line, environment variables, or a yaml config file.

If the same value is provided in several of those locations, then env var always beats config file, and command line always beats everything.

Usage is exactly the same as argparse, with the addition of some new kwargs on initializing the parser and adding arguments to it. Example:

from appsettings import SettingsParser

f = open('some_config_file.yaml')
parser  = SettingsParser(yaml_file=f)

parser.add_argument('--color', default='blue', env_var='FAVCOLOR')

args = parser.parse_args()

print args.color
# If you've set the FAVCOLOR environment variable you should now see its
# value printed to the console.  Otherwise you'd see 'blue'

Things to Know

Options Only

Only long form arguments like “–color” will provide env var and config file fallbacks. Positional arguments and short options like “-c” will behave just like they do in the argparse module.

APP_SETTINGS_YAML

If you don’t provide a yaml_file argument to the SettingsParser constructor, and the APP_SETTINGS_YAML environment variable is set, then that file will be read and parsed to provide settings. (Though they’ll still be overridable by environment variables and command line options.)

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

appsettings-0.6.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file appsettings-0.6.tar.gz.

File metadata

  • Download URL: appsettings-0.6.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for appsettings-0.6.tar.gz
Algorithm Hash digest
SHA256 843f9166b6765f74ff69ef78ad02f90b51c5d46c08f28a1bd69edafb03089768
MD5 da30844227fbb2a3af9e7d0ded282c7d
BLAKE2b-256 3fd28cbc00f2cd2704b443f6ae05237b427cdae6236a30c23e32d9b6affbf4ca

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