TOML powered .env file configuration and secrets
Project description
TOML-decouple
TOML powered .env file configuration and secrets
Package available in PyPI.
Getting Started
Install the library
Using pip:
pip install toml-decouple
Using uv:
uv add toml-decouple
Basic Usage
# my_project/.env
SECRET_KEY = "S3cre7"
DEBUG = true
DB = postgresql://USER:PASSWORD@HOST:PORT/NAME
import dj_database_url
from toml_decouple import config
SECRET_KEY = config.SECRET_KEY
DEBUG = config("DEBUG", false)
DATABASES["default"] = config("DB", to=dj_database_url.parse)
Assuming this environment variable is set:
MY_PROJECT_DEBUG=true
Create your configuration dataclass and parse config and env into it:
from dataclasses import dataclass
from toml_decouple import TomlDecouple
@dataclass
class Config:
SECRET_KEY: str = ""
DEBUG: bool = False
config: Config = TomlDecouple().load_dataclass(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:
SECRET_KEY = config.SECRET_KEY
DEBUG = config("DEBUG", False)
print(SECRET_KEY) # prints "S3cre7"
print(DEBUG) # prints True
print(config.DB) # raise AttributeError: 'Config' object has no attribute 'DB'
Configuration
To configure, you have to use TomlDecouple(**options).load(), like:
from toml_decouple import TomlDecouple
config = TomlDecouple(
env_files=[".env.docker"],
secrets=["/run/secrets"], # this is the default
initial={"DEBUG": True}
prefix="BACKEND_", # to use env variables BACKEND_ENV_VAR=value
).load()
Tests
Run tests from the project root with:
make test
Issues
Feel free to send issues or suggestions to https://github.com/blfpd/toml-decouple/issues.
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_decouple-0.6.0.tar.gz.
File metadata
- Download URL: toml_decouple-0.6.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d932a19c2c1fd945d400018876d478d14ade22fe166e27f6bc54748689fab70
|
|
| MD5 |
518fe52883553f5248de721c01393e5f
|
|
| BLAKE2b-256 |
9af56bacbc6635075883fd260f90b14c38b86a8b196c8bf07a77e84cf5d4a4f5
|
Provenance
The following attestation bundles were made for toml_decouple-0.6.0.tar.gz:
Publisher:
publish.yaml on blfpd/toml-decouple
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
toml_decouple-0.6.0.tar.gz -
Subject digest:
5d932a19c2c1fd945d400018876d478d14ade22fe166e27f6bc54748689fab70 - Sigstore transparency entry: 618954348
- Sigstore integration time:
-
Permalink:
blfpd/toml-decouple@87f6e4eb21cbb98d9be9e55d41e45376c217d407 -
Branch / Tag:
refs/tags/0.6.0 - Owner: https://github.com/blfpd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@87f6e4eb21cbb98d9be9e55d41e45376c217d407 -
Trigger Event:
release
-
Statement type:
File details
Details for the file toml_decouple-0.6.0-py3-none-any.whl.
File metadata
- Download URL: toml_decouple-0.6.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e618111e538ecaa78a03d3c6473f7e2cfe099f867c60f7f6d92e3fc08a5f6fd
|
|
| MD5 |
e17e917bab65f4f1b25adff14630cee1
|
|
| BLAKE2b-256 |
bff99862b8b5077058e5116e63451f4bec951dbb78311dabd5565901b7137205
|
Provenance
The following attestation bundles were made for toml_decouple-0.6.0-py3-none-any.whl:
Publisher:
publish.yaml on blfpd/toml-decouple
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
toml_decouple-0.6.0-py3-none-any.whl -
Subject digest:
3e618111e538ecaa78a03d3c6473f7e2cfe099f867c60f7f6d92e3fc08a5f6fd - Sigstore transparency entry: 618954352
- Sigstore integration time:
-
Permalink:
blfpd/toml-decouple@87f6e4eb21cbb98d9be9e55d41e45376c217d407 -
Branch / Tag:
refs/tags/0.6.0 - Owner: https://github.com/blfpd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@87f6e4eb21cbb98d9be9e55d41e45376c217d407 -
Trigger Event:
release
-
Statement type: