An argument helper used to validate environment variables
Project description
zonar_ds_env_arg_parser
Overview
This is a simple helper that is meant to enforce and validate that environment variables are set correctly
Usage
from zonar_ds_env_arg_parser.env_arg_parser import env_arg_parser as parser
parser.add_argument(env_var="SOME_EVN_VAR",
required=True,
type=int,
help="Message to display about the variable")
parser.add_argument(env_var="SOMETHING_ELSE",
required=False,
default="TEST",
validation=lambda x: x.lower() == "test" or
x.lower() == "something" or
x.lower() == "something_else",
help="Some message about this variable")
parser.initialize()
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
Arguments
Parameters that can be passed into env_arg_parser.add_argument are as follows:
env_var: The environment variable to look for. This will also be the name of the attribute when retrieving it.
required: can be true or false, if required=False a default must be provided.
default: The default value. Must be set if required=False, cannot be set if required=True.
help: 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.
validation: Optional, 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: Optional, if the value needs to be something other than a string, specify what it should be converted to.
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
Hashes for zonar_ds_env_arg_parser-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ecfbc3842d3dc2c366cdedef10d2e539aae3fd417e44ff20580255d837ddc70 |
|
MD5 | f00e3ecf7286b612d7d6fac2b5b56ba9 |
|
BLAKE2b-256 | 66f73800acc6a0bd8b6779274f6de6af6d23262fc56bd276aa1e0c5e5b5b91b9 |
Hashes for zonar_ds_env_arg_parser-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a93131aa8948068213c50e0f85ef4254865b1096cc0405a0a85211850b519ffa |
|
MD5 | 576515f0645c3833e59804acd275cf20 |
|
BLAKE2b-256 | d6fe685586a49c17007a46bac180c64c5ade29015bba694023e587b93585f475 |