env_var
- class env_var.env(var_name: str)
Utility to validate and type cast environment variables. All methods return an instance of the
_envclass.- as_bool()
Parses env var as a boolen
- as_date()
Parses env var using
dateutil.parser.parse()
- as_email()
Makes sure env var is a valid email string
- as_enum(enum: Type[env_var.env.EnumType]) env_var.env._env[env_var.env.EnumType]
Parses env var as an Enum
- as_float(min: Optional[float] = None, max: Optional[float] = None)
Parses env var as a float
- Parameters
min – min acceptable value
max – max acceptable value
- as_float_list(split_on: str = ',', min_item_value: Optional[float] = None, max_item_value: Optional[float] = None)
Parses env var as a list of floats
- Parameters
split_on – string on which env var should be split
base – the base defaults to 10; valid bases are 0 and 2-36
min_item_value – min acceptable value for a single list item
max_item_value – max acceptable value for a single list item
- as_float_negative()
Parses env var as a negative float
- as_float_positive()
Parses env var as a positive float (0 included)
- as_hostname()
Makes sure env var is a valid hostname string
- as_int(base: Optional[int] = 10, min: Optional[int] = None, max: Optional[int] = None)
Parses env var as an int
- Parameters
base – the base defaults to 10; valid bases are 0 and 2-36
min – min acceptable value
max – max acceptable value
- as_int_list(split_on: str = ',', base: Optional[int] = 10, min_item_value: Optional[int] = None, max_item_value: Optional[int] = None)
Parses env var as a list of ints
- Parameters
split_on – string on which env var should be split
base – the base defaults to 10; valid bases are 0 and 2-36
min_item_value – min acceptable value for a single list item
max_item_value – max acceptable value for a single list item
- as_int_negative(base: Optional[int] = None)
Parses env var as a negative int
- Parameters
base – the base defaults to 10; valid bases are 0 and 2-36
- as_int_positive(base: Optional[int] = None)
Parses env var as a positive int (0 included)
- Parameters
base – the base defaults to 10; valid bases are 0 and 2-36
- as_ip_address()
Parses env var using
ipaddress.ip_address()
- as_ip_interface()
Parses env var using
ipaddress.ip_interface()
- as_ip_network()
Parses env var using
ipaddress.ip_network()
- as_iso_date()
Parses env var using
dateutil.parser.isoparse()
- as_iso_date_string()
Makes sure env var is as a valid rfc3339 string
- as_iso_duration()
Parses env var using
isoduration.parse_duration()
- as_list(item_transformer: Callable[[str], env_var.env.T], split_on: str = ',') env_var.env._env[List[env_var.env.T]]
Parses env var as a list
- Parameters
item_transformer – function called with every value of the split string
split_on – string on which env var should be split
- as_port_number()
Parses env var as a port number (int between 1-65535)
- as_string()
Literally does nothing with the env var
- as_string_list(split_on: str = ',')
Parses env var as a list of strings
- Parameters
split_on – string on which env var should be split
- as_uri()
Makes sure env var is a valid uri string
- as_url()
Makes sure env var is a valid url string
- as_urlparse()
Parses env var using
urllib.parse.urlparse()
- as_uuid()
Makes sure env var is a valid uuid string
- custom_transformer(transformer: Callable[[str], env_var.env.T]) env_var.env._env[env_var.env.T]
Parse/validate env var using custom transformer
- should_match(pattern: Union[Pattern[str], str])
Makes sure env var is matching given pattern
- class env_var.env._env(_env__var_name: str, _env__transformer: Callable[[str], env_var.env.T], _env__default: Optional[env_var.env.T] = None)
Helper generic class that is actually returned by all methods of the
envclass. It’s not supposed to be instantiated directly by the user of the library.- default(val: env_var.env.T)
Sets the default value to return in case the environment variable is not defined. Note, this value will be returned as is, without any validation the value from the environment variable might go through.
- Parameters
val – default value to use
- Returns
self
- optional() Optional[env_var.env.T]
- Returns
the parsed environment variable, if it’s set; if not, the default value if it was defined or None
- Raises
- required() env_var.env.T
- Returns
the parsed environment variable
- Raises
- exception env_var.errors.EnvVarNotDefinedError(var_name: str)
Exception raised when env var is not set
- exception env_var.errors.EnvVarValidationError(var_name: str, *args)
Exception raised when env var is not valid