Skip to main content

An argument helper used to validate environment variables

Project description


This is a simple helper that is meant to enforce and validate that environment variables are set correctly

from zonar_ds_env_arg_parser.env_arg_parser import env_arg_parser as parser

help="Message to display about the variable")

validation=lambda x: x.lower() == "test" or
x.lower() == "something" or
x.lower() == "something_else",
help="Some message about this variable")

type=bool, # Will convert ("yes", "true", "t", "1", "y", "yeah") to True
help="Another description about converting to True")

options = parser.get_options()

# This var doesn't have a default so 'SOME_EVN_VAR' needs to be set or it'll throw an exception
print("This is the type of SOME_EVN_VAR " + type(options.SOME_EVN_VAR)) # Should be int becasue we specified type
print("This is the value of SOMETHING_ELSE " + options.ENVIRONMENT) # Should be 'TEST' since that's the default
print("This is the value of TRUE " + options.TRUE) # Should be 'TEST' since that's the default

Parameters that can be passed into env_arg_parser.add_argument are as follows:

| param | required | Description |
| env_var | Yes | The environment variable to look for. This will also be the name of the attribute when retrieving it. |
| required | Yes | Can be True or False, if required=False a default must be provided. |
| help | Yes | This message is displayed if an argument doesnt exist or fails validation. It should explain to the user what the argument is for to assist them in defining it. |
| default | Conditional | The default value. Must be set if required=False, cannot be set if required=True. |
| validation | No | A function should be provided that takes a single value and should return True, False or raise an Exception. False or an exception will prevent the program from launching. |
| type | No | If the value needs to be something other than a string, specify what it should be converted to.

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 zonar-ds-env-arg-parser, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size zonar_ds_env_arg_parser-1.0.1-py3-none-any.whl (5.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size zonar_ds_env_arg_parser-1.0.1.tar.gz (4.0 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