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.6

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.6
File Size Uploaded
toml_repo-0.1.6.tar.gz 25.6 kB Details

Built distribution (wheel)

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

Total release size: 51.3 kB

Release files / toml_repo-0.1.6.tar.gz

Download URL toml_repo-0.1.6.tar.gz
Size 25.6 kB
Tags Source
SHA-256 checksum
How to use checksums
808ccc2ef1464a5e007ac46a4100c7cac6f645f07895ab6829db0bd65aca7777
BLAKE2b-256 checksum
How to use checksums
7a13b7d0bd278f9622394d420160ce7723a8e9825152f4f59a907de6ede9f9f4
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 Aug 23, 2026.

Transparency log

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

Download URL toml_repo-0.1.6-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a98eca3d65a93794cd7ed34553cba71e4994cb67dc5975947a5d23a375a16d91
BLAKE2b-256 checksum
How to use checksums
727ad6d71b8cf0851b994cd824b363b4a3a6d6ce365a3df3da0fbe5aa978b982
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 Aug 23, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.8

2 release files

0.1.7

2 release files

This release

0.1.6 This release

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