Usage

Accessing namespaces

Environment namespaces, or sets of environment variables that share a common prefix, are grouped into Habitat objects. For example, the following environment variables are part of the YOURAPP namespace:

YOURAPP_HOST="server.com"
YOURAPP_PORT=8000
YOURAPP_DEBUG="true"

biome dynamically populates namespaces on attribute access to the biome “module”, which is actually a class injected into sys.modules. This results in a slightly magical, but extremely convenient drop-in configuration provider for your application.

>>> import biome
>>> biome.YOURAPP.host
"server.com"

Note

biome expects that your environment variable prefixes always carry a trailing underscore, separating them from the suffix, or variable name. For instance, the variable YOURAPPDEBUG must be changed to YOURAPP_DEBUG if you want it included in the YOURAPP namespace.

Accessing variables

Namespaced environment variables can be accessed in the way you’d expect (via attributes), and are automatically converted to int, bool, and pathlib.Path objects whenever possible.

# YOURAPP_SECRET_KEY='~/.secret_key'
secret_key = biome.YOURAPP.secret_key.read_text()

You can also use any of the getters in the Habitat class to explicitly coerce types, or if you want to provide default values.

debug = biome.YOURAPP.get_bool("debug", False)