Skip to main content

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; call set_config_suffix() to use any name (e.g. "myapp.toml").
  • Source tracking – every TOML node is monkey-patched with a .source back-pointer to the Repo that loaded it.
  • HTTP caching – HTTP repos use requests-cache so 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.

Metadata

Release files for toml-repo 0.1.7

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-repo 0.1.7
File Size Uploaded
toml_repo-0.1.7.tar.gz 27.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for toml-repo 0.1.7
File Interpreter ABI Platform
toml_repo-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 55.6 kB

Release files / toml_repo-0.1.7.tar.gz

Download URL toml_repo-0.1.7.tar.gz
Size 27.5 kB
Tags Source
SHA-256 checksum
How to use checksums
474c6db8a74e65520d8ee5076b94647b9bf9c4023985529c49475ee397923c41
BLAKE2b-256 checksum
How to use checksums
31a7e79d000a7617a0668ba2845c2e6de7e336924b67d32ff453172803d46553
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 15, 2026.

Transparency log

Release files / toml_repo-0.1.7-py3-none-any.whl

Download URL toml_repo-0.1.7-py3-none-any.whl
Size 28.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bac4e0a504d0957fb510e58125adbb4c185dfc99f420ec5cc9ce840471ead4a2
BLAKE2b-256 checksum
How to use checksums
4159a80aa1c49c66cd2de9630978fde7fec48b5c5849791c140b05d8cbeebd8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 15, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.8

2 release files

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

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