A TOML-based repository manager with precedence-based configuration merging, imports, and multi-scheme URL support.
Project description
toml-repo
A TOML-based repository manager for Python applications. Provides precedence-based
configuration merging, cross-file imports, and multi-scheme URL support (file://, pkg://, http://). You can have trees
of toml (and other data files) with auto resolved links between them.
Features
- Multi-scheme repositories – load TOML configs from local directories (
file://), Python package resources (pkg://), or HTTP(S) URLs. - Precedence-based merging – later-added repos override earlier ones; query across all repos
with a single
get()call. - TOML imports –
[section.import]tables let you pull nodes from other files or repos, eliminating duplication. - Configurable config filename – defaults to
repo.toml; callset_config_suffix()to use any name (e.g."myapp.toml"). - Source tracking – every TOML node is monkey-patched with a
.sourceback-pointer to theRepothat loaded it. - HTTP caching – HTTP repos use
requests-cacheso previously fetched configs work offline.
Installation
pip install toml-repo
Or with Poetry:
poetry add toml-repo
Quick start
from toml_repo import RepoManager, set_config_suffix
# Optional: change the filename looked up inside repo directories
set_config_suffix("myapp.toml")
manager = RepoManager()
manager.add_repo("file:///path/to/base-config")
manager.add_repo("file:///path/to/user-overrides")
# Last repo wins
value = manager.get("section.key", default="fallback")
Using pkg:// URLs
If your application ships default configs as package data you can load them via importlib resources:
from toml_repo import set_pkg_resource_root
# Tell toml-repo which installed package contains the resources
set_pkg_resource_root("myapp")
manager.add_repo("pkg://defaults") # reads myapp/defaults/myapp.toml
TOML imports
Inside any TOML file managed by toml-repo you can import nodes from other files to reduce duplication:
[repo]
kind = "recipe"
# Import the "base_stage" table from a library file
[my_stage.import]
file = "library.toml"
node = "base_stage"
Imports support:
- Same-file references (
node = "some.path") - Cross-file references (
file = "relative/path.toml") - Cross-repo references (
repo = "file:///other/repo") - Recursive resolution (imported files can themselves contain imports)
API reference
Module-level configuration
| Function | Description |
|---|---|
set_config_suffix(name) |
Set the TOML filename for directory repos (default: "repo.toml") |
get_config_suffix() |
Get the current config suffix |
set_pkg_resource_root(pkg) |
Set the Python package for pkg:// URL resolution |
RepoManager
| Method | Description |
|---|---|
add_repo(url) |
Add a repo by URL; returns the Repo instance |
get(key, default=None) |
Get a value with last-repo-wins precedence |
get_repo_by_url(url) |
Find a repo by its URL |
get_repo_by_kind(kind) |
Find the first repo matching a repo.kind value |
dump() |
Log all merged key-value pairs (debug) |
Repo
| Method | Description |
|---|---|
get(key, default=None) |
Get a dot-separated key from this repo's config |
set(key, value) |
Set a dot-separated key in this repo's config |
kind() |
Return the repo.kind value |
read(filepath) |
Read a file relative to the repo root |
resolve_path(filepath) |
Resolve a relative path to an absolute Path |
write_config() |
Write modified config back to disk (file repos only) |
add_repo_ref(manager, dir) |
Add a [[repo-ref]] entry and load it |
Development
cd toml-repo
poetry install --with dev
poetry run pytest
License
GPL-3.0 — see LICENSE for details.
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_repo-0.1.4.tar.gz.
File metadata
- Download URL: toml_repo-0.1.4.tar.gz
- Upload date:
- Size: 25.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 |
2cee66542dc95cddc98f5cc0d775ef2ad7a2a8f9377d44c126e054e3d43dd428
|
|
| MD5 |
c6ce259df1bdde6d3ffd08a3045d1a26
|
|
| BLAKE2b-256 |
c4c2ff276b5d07c96e25679f60b82458a14bfc607b6e1ddbb01fe2dcf7b2b6c6
|
Provenance
The following attestation bundles were made for toml_repo-0.1.4.tar.gz:
Publisher:
publish.yml on geeksville/toml-repo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
toml_repo-0.1.4.tar.gz -
Subject digest:
2cee66542dc95cddc98f5cc0d775ef2ad7a2a8f9377d44c126e054e3d43dd428 - Sigstore transparency entry: 927460272
- Sigstore integration time:
-
Permalink:
geeksville/toml-repo@45df9bc618e71144e42323116cb21e2590d7fa60 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/geeksville
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@45df9bc618e71144e42323116cb21e2590d7fa60 -
Trigger Event:
push
-
Statement type:
File details
Details for the file toml_repo-0.1.4-py3-none-any.whl.
File metadata
- Download URL: toml_repo-0.1.4-py3-none-any.whl
- Upload date:
- Size: 25.7 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 |
f39b86aaf4cf2cb5bbdddbf7fc35b8072a00b74b954763cace240ad0d86582cb
|
|
| MD5 |
910767073a161db6ff49dabdcddaca3a
|
|
| BLAKE2b-256 |
02d1b5f7457315395097d27a65ba425f67674f6a025855dabb8c4725a1db2c96
|
Provenance
The following attestation bundles were made for toml_repo-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on geeksville/toml-repo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
toml_repo-0.1.4-py3-none-any.whl -
Subject digest:
f39b86aaf4cf2cb5bbdddbf7fc35b8072a00b74b954763cace240ad0d86582cb - Sigstore transparency entry: 927460325
- Sigstore integration time:
-
Permalink:
geeksville/toml-repo@45df9bc618e71144e42323116cb21e2590d7fa60 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/geeksville
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@45df9bc618e71144e42323116cb21e2590d7fa60 -
Trigger Event:
push
-
Statement type: