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)
Metadata
Release files for toml-env-conf 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| toml_env_conf-0.1.3.tar.gz | 2.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| toml_env_conf-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.1 kB
Release files / toml_env_conf-0.1.3.tar.gz
| Download URL | toml_env_conf-0.1.3.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c1fbf844aa8ad190481d23b7b8342de60b6bab704bbbc2841f654aa2224aad9
|
|
BLAKE2b-256 checksum How to use checksums |
a90e98049e8fd857ea56132d3cc23772a6e95003e5feaadb493a786f38b605cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.15
|
Release files / toml_env_conf-0.1.3-py3-none-any.whl
| Download URL | toml_env_conf-0.1.3-py3-none-any.whl |
|---|---|
| Size | 2.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d16aa52d304dae05e6d1cfa257a7e2377586b7a5690249003fc9623af56aca1f
|
|
BLAKE2b-256 checksum How to use checksums |
4dd677b521681f99f01d0d17f352a5da2386d467d4122051fdec96d2f46cb515
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.15
|
Security for toml-env-conf 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.