ploomber.Env

class ploomber.Env(source=None)

Return the current environment

NOTE: this API is experimental and subject to change, it is recommmended to use @with_env and @load_env decorators instead

Env provides a clean and consistent way of managing environment and configuration settings. Its simplest usage provides access to settings specified via an env.yaml.

Settings managed by Env are intended to be runtime constant (they are NOT intended to be used as global variables). For example you might want to store database URIs. Storing sensitive information is discouraged as yaml files are plain text. Use keyring for that instead.

All sections are optional, but if there is a path section, all values inside that section will be casted to pathlib.Path objects, expanduser() is applied so “~” can be used. Strings with a trailing “/” will be interpreted as directories and they will be created if they do not exist

There are a few placeholders available: * {{user}} expands to the current user (by calling getpass.getuser()) * {{version}} expands to module.__version__ if _module is defined * {{git}} expands to branch name if at the tip, otherwise to the current commit hash (_module has to be defined)

Examples

>>> from ploomber import Env
>>> env = Env({'db': {'uri': 'my_uri'}, 'path': {'raw': '/path/to/raw'}})
>>> env.db.uri
'my_uri'
>>> env.path.raw
PosixPath('/path/to/raw')

Notes

Envs are intended to be short-lived, the recommended usage is to start and end them only during the execution of a function that builds a DAG by using the @with_env and @load_env decorators

Methods

end()

End environment.

load()

classmethod end()

End environment. Usage is discouraged, a single environment is expected to exist during the entire Python process lifespan to avoid inconsistencies, use it only if you have a very strong reason to

classmethod load()

Attributes

name