Environment specific application configuration with TOML
Project description
toml-env-conf
pip install toml-env-conf
A minimal library for environment-specific (dev/prod) application configuration using TOML
Useful if you want different values in some environments (local/test/prod). e.g. all environments use
the values base_conf.toml, but you only want some values to be different when
env == "prod"
As easy as
import toml_env_conf
toml_env_conf.load_as_dict(path)
# or
toml_env_conf.load_as_dataclass(
path=path,
data_class=MyConfigType,
env="prod"
)
Where the path has the following toml files
├── base_conf.toml
└── env_prod.toml
Convention
- There must be a file named
base_conf.toml - For environment overrides, the file must be called
env_[name].tomle.g. for an environment calledprod, the file is calledenv_prod.toml. For an environment calleddev, the file is calledenv_dev.toml.
Example
Step 1: Create some configs
base_conf.toml
name = "Regular name"
hobby_name = "laundry"
is_fun = false
scores = [-10, -20]
env_prod.toml
hobby_name = "music"
is_fun = true
Step 2: Load em up
main.py
from dataclasses import dataclass
from pathlib import Path
from typing import List
import toml_env_conf
@dataclass(frozen=True) # freeze for immutability
class MyConfigType:
name: str
hobby_name: str
is_fun: bool
scores: List[int]
if __name__ == "__main__":
conf_dir_path = Path(__file__).parent.joinpath("/path/to/config")
config: MyConfigType = toml_env_conf.load_as_dataclass(
conf_dir_path, MyConfigType, env="prod"
)
print(config)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file toml_env_conf-0.1.3.tar.gz.
File metadata
- Download URL: toml_env_conf-0.1.3.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c1fbf844aa8ad190481d23b7b8342de60b6bab704bbbc2841f654aa2224aad9
|
|
| MD5 |
80bfc8892951385e00ee1c68ec4b0709
|
|
| BLAKE2b-256 |
a90e98049e8fd857ea56132d3cc23772a6e95003e5feaadb493a786f38b605cf
|
File details
Details for the file toml_env_conf-0.1.3-py3-none-any.whl.
File metadata
- Download URL: toml_env_conf-0.1.3-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d16aa52d304dae05e6d1cfa257a7e2377586b7a5690249003fc9623af56aca1f
|
|
| MD5 |
f6384b199fa4b689f4b609c7e5983f98
|
|
| BLAKE2b-256 |
4dd677b521681f99f01d0d17f352a5da2386d467d4122051fdec96d2f46cb515
|