Skip to main content

TOML-decouple

GitHub Workflow Status PyPI - Version Pypi - Python Version PyPI - Downloads License

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.

Metadata

Release files for toml-decouple 0.11.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for toml-decouple 0.11.3
File Size Uploaded Provenance Actions
toml_decouple-0.11.3.tar.gz 6.1 kB With provenance Details for toml_decouple-0.11.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for toml-decouple 0.11.3
File Interpreter ABI Platform Actions
toml_decouple-0.11.3-py3-none-any.whl Python 3 none any Details for toml_decouple-0.11.3-py3-none-any.whl

Total release size: 13.8 kB

Release files / toml_decouple-0.11.3.tar.gz

Download URL toml_decouple-0.11.3.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
15e008c33db45a6274e0a8f8b07013f3222dcccb97ac2889f78c733bb5309c76
BLAKE2b-256 checksum
How to use checksums
30b826ad433a6af42ca66ccd648bc5cce2a06708c41f4a976b59f103058f59a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 22, 2026.

Transparency log

Release files / toml_decouple-0.11.3-py3-none-any.whl

Download URL toml_decouple-0.11.3-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dffe7e8c26d397269815bfcb4ddc17603d027a35b306828f36e91961eb8bf88d
BLAKE2b-256 checksum
How to use checksums
2344bffc936f345ecd90b043549a024e1d7064a1328b8be813975e345d265fd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 22, 2026.

Transparency log

Security for toml-decouple 0.11.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for toml_decouple-0.11.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 22, 2026.

Transparency log

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page