Environment wrapped TOML.
Package available in PyPI.
Using pip:
$ pip install tomlenv
Using pipenv:
$ pipenv install tomlenv
Using poetry:
$ poetry add tomlenv
Tomlenv takes advantage of modern Python features such as dataclasses
and
tomllib
to create a simple yet powerful configuration library.
By default, tomlenv looks for a config.toml
file in your project root:
token = "dev"
debug = false
Assuming this environment variable is set:
TOMLENV_DEBUG=true
Create your configuration dataclass and parse config and env into it:
import tomlenv
from dataclasses import dataclass
@dataclass
class Config:
token: str = ''
debug: bool = False
config = Config()
parser = tomlenv.Parser()
parser.load(config)
# You can now access the fields of your fully typed config Class
# that contains values from a TOML config file and the environment.
# For example:
token = config.token
debug = config.debug
print(token) # prints "dev"
print(debug) # prints True
To configure the location of your toml file, set TOMLENV_CONF_FILEPATH
.
For example if your config file is in configs/config.toml
relative to the project root, then set TOMLENV_CONF_FILEPATH=configs/config.toml
This project uses Poetry and GNU Make.
Run tests from the project root with:
$ make test
To get a coverage report:
$ make cov
Feel free to send issues or suggestions to https://github.com/joaonsantos/tomlenv/issues.