env

env

This module contains all of the tools used to get information from the environment. It also contains command line tools to inspect the the environment, which are a great aid in debugging.

Functions

Name Description
create_logger Create a logger.
create_logging_config Create the uvicorn logging config.
create_validator Make a validator for varname.
get Get an environment variable value for variable name.
name Calculate the evironment variable name for a variable.
require Require a setting from the environment using its short name.
require_path Require a setting from environment that is an existing path.

create_logger

env.create_logger(name)

Create a logger.

Parameters

Name Type Description Default
name str Name of the logger. required

Returns

Name Type Description
logging.Logger A configured logger.

create_logging_config

env.create_logging_config()

Create the uvicorn logging config.

.. This could be kept in a file. But if I decide to package this it can be a real pain to keep such files in the package. Further I do not want to maintain two configs.

create_validator

env.create_validator(varname, default=None)

Make a validator for varname.

get

env.get(varname, default=None, *, required=False)

Get an environment variable value for variable name.

Parameters

Name Type Description Default
default str | None The default value to use if nothing is found. None
required bool Raise an error to make the command line tool exit if no value is ascertained. False

Returns

Name Type Description
str | None The environment variable value or the default if provided.

name

env.name(varname)

Calculate the evironment variable name for a variable.

For example, if we have a variable called thing then we should expect that it has the environment variable name ACEDERBERG_IO_THING.

Parameters

Name Type Description Default
varname str The variable name. For clarity, this should match the name the value is assigned to. required

Returns

Name Type Description
str The environment variable name for the variable.

require

env.require(varname, default=None)

Require a setting from the environment using its short name.

Parameters

Name Type Description Default
varname str (Short) variable name. required
default str | None Optional default value. None

Returns

Name Type Description
str The environment variable value or the default provided.

Raises

Name Type Description
ValueError When no value is ascertained.

require_path

env.require_path(varname, default=None, *, strict=True, ensure_dir=False)

Require a setting from environment that is an existing path.

Resolves path to be absolute and ensures existance.

Parameters

Name Type Description Default
varname str (Short) variable name. required
default pathlib.Path | None Default pathlib|None`

Returns

Name Type Description
pathlib.Path Path from env (as specified by :param:varname or :param:default.

Raises

Name Type Description
ValueError When no value can be ascertained.