TOML configuration loader with include/merge/interpolation
Project description
tomlstack
tomlstack is a lightweight TOML config loader for Python 3.11+ with:
- top-level
includeloading - deterministic merge by include order
${path}interpolation with cycle/undefined checks- node-level provenance (
origin,explain,history)
tomlstack does not try to be a configuration framework. It address two missing pieces to TOML: file composition and safe interpolation — while keeping files self-contained and explainable.
Install
pip install tomlstack
Quick Start
main.toml:
include = [
"./base.toml",
"./prod.toml",
]
[db]
url = "postgres://${db.user}:${db.pass}@${db.host}:${db.port}"
base.toml:
[db]
user = "alice"
pass = "secret"
host = "localhost"
port = 5432
Python:
from tomlstack import load
cfg = load("main.toml")
print(cfg["db"]["url"].raw) # raw interpolation string
cfg.resolve()
print(cfg["db"]["url"].value) # resolved value
print(cfg["db"]["url"].origin)
print(cfg["db"]["url"].history)
print(cfg.to_dict())
Include Semantics
- top-level
includeonly; nestedincludeis treated as normal data - syntax: string or list of strings
- valid include path forms:
./...or../...@label/...(label from__meta__.include.anchors)- absolute path
- any other form raises error with hint:
Use ./ or ../ or @label/
Meta Include Directives
[__meta__]
version = 1
[__meta__.include]
root = "../.."
[__meta__.include.anchors]
proj = "./shared"
__meta__.include.rootis sugar foranchors.root- if both
rootandanchors.rootexist and resolve differently, error - anchor/root path values must be absolute or start with
./or../ - if any file explicitly sets
__meta__.version, all files in include chain must share one supported version (1)
Merge Rules
Load order for current file:
- merge first include
- merge second include
- ...
- merge current file (highest priority)
Conflict behavior:
- dict: recursive merge, later wins on key conflict
- list: later value replaces whole list
- scalar: later value replaces earlier
Interpolation Semantics
- interpolation happens on
cfg.resolve() - path syntax supports dot and list index:
${db.apps[0]} - full-string interpolation (
"${db.port}") keeps source type - embedded interpolation (
"postgres://${db.host}:${db.port}") allows only: str,int,float,date,time,datetime- formatting syntax:
${path:spec} - for
date/time/datetime, formatting usesstrftime - otherwise uses Python
format(value, spec) - undefined reference raises
InterpolationUndefinedError - interpolation cycle raises
InterpolationCycleError
Public API
cfg = load("f.toml")cfg.resolve()cfg.to_dict()node = cfg["proj"][0]["path"]["foo"]node.rawnode.valuenode.originnode.historynode.preview()cfg.to_toml()->NotImplementedError
Current Limitations
- interpolation path parser supports unquoted dot keys and numeric list indices
- no nested interpolation expressions
to_toml()is not implemented yet
TODO
- review the details of interpolation
- explain history with interpolation
Release To PyPI
Build package:
uv run --with build python -m build
Upload to TestPyPI first:
uv run --with twine python -m twine upload --repository testpypi dist/*
Verify install from TestPyPI:
python -m pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple tomlstack
Upload to PyPI:
uv run --with twine python -m twine upload dist/*
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 tomlstack-0.1.2.tar.gz.
File metadata
- Download URL: tomlstack-0.1.2.tar.gz
- Upload date:
- Size: 66.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a2f9e8713290d277c7476353333e82d11633b429ccebab2b375183f497601df
|
|
| MD5 |
0f55c7e0f960f7a70c02a8328a3e4d80
|
|
| BLAKE2b-256 |
feb1ff0cb1abfafd6bc91781339504bcaad640b8ad8b69ddaf831ba69908014a
|
Provenance
The following attestation bundles were made for tomlstack-0.1.2.tar.gz:
Publisher:
publish-pypi.yml on WXZhao7/tomlstack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tomlstack-0.1.2.tar.gz -
Subject digest:
5a2f9e8713290d277c7476353333e82d11633b429ccebab2b375183f497601df - Sigstore transparency entry: 1006537000
- Sigstore integration time:
-
Permalink:
WXZhao7/tomlstack@5b504958d8e9741c09ebb21fd1432aba5e1331fb -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/WXZhao7
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@5b504958d8e9741c09ebb21fd1432aba5e1331fb -
Trigger Event:
push
-
Statement type:
File details
Details for the file tomlstack-0.1.2-py3-none-any.whl.
File metadata
- Download URL: tomlstack-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.9 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 |
1f27e070f7ee2214409a222373a52c8af70b652b01a792f2f52d662a9a612ff7
|
|
| MD5 |
efdf5b53ae6bad5aee7394f5cbbc6a91
|
|
| BLAKE2b-256 |
3e05295eb681c6c1db185137218556f7dd6107cfc8e0877a5fc878fb9d64d9ad
|
Provenance
The following attestation bundles were made for tomlstack-0.1.2-py3-none-any.whl:
Publisher:
publish-pypi.yml on WXZhao7/tomlstack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tomlstack-0.1.2-py3-none-any.whl -
Subject digest:
1f27e070f7ee2214409a222373a52c8af70b652b01a792f2f52d662a9a612ff7 - Sigstore transparency entry: 1006537002
- Sigstore integration time:
-
Permalink:
WXZhao7/tomlstack@5b504958d8e9741c09ebb21fd1432aba5e1331fb -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/WXZhao7
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@5b504958d8e9741c09ebb21fd1432aba5e1331fb -
Trigger Event:
push
-
Statement type: