TomlArg
A unified TOML + CLI parser for configurable Python projects. Every TOML key-value pair becomes a command-line flag with a default value.
Features
- Drop-in replacement for
argparse.ArgumentParser. - Flag precedence is command line, then TOML, then
add_argumentdefaults. - Multiple TOML sources can be specified from file, string, or already-parsed dict.
- TOML sources merge in the order added, where a later source overrides only the keys it names.
- Tables are flattened into dotted flags (
--db.pool.size) at any depth. - Arrays of tables are index-addressable (
--servers.1.port,--servers.2.port). - Custom delimiter (
ArgumentParser(delimiter="__")gives--db__pool__size). - Values are typed as hinted from the TOML: strings, integers, floats, booleans, datetimes, dates, times and arrays.
- Boolean keys generate affirmative and negated flags:
--debugand--no-debug. - Arrays take a comma-separated value (
--tags a,b,c), with--tags=or a bare--tagsgiving an empty one. --helplists TOML-derived flags alongside declared ones.- No dependencies beyond Python 3.12+.
Install
pip install tomlarg
Example Code
# import argparse
import tomlarg
# TOML can be given via constructor.
parser = tomlarg.ArgumentParser(toml_file="config.toml")
parser.add_argument("--port", type=int)
# Or TOML can be given via add_toml* methods.
parser.add_toml("profile.toml")
parser.add_toml_str("""
[user]
name = "User"
""")
args = parser.parse_args()
args.db.host # from [db] host
args.servers[1].port # from the second [[servers]]
data = dict(args) # to plain dict
Example Usage
Simple example:
python3 examples/basic --db.host db.internal --servers.1.port 9999
Example showing multiple TOML sources:
python3 examples/layered
See examples.
Todo
- TOML comment parser to attach argument parameters e.g. choices, required, deprecated.
- Subparsers.
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 tomlarg-0.2.0.tar.gz.
File metadata
- Download URL: tomlarg-0.2.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbd2267675f2291b445c9e50ae38c563bea0bb8a4e0b0933dfb440002745b1b8
|
|
| MD5 |
bdda27048f305c2d0e41a627f7ab0f1c
|
|
| BLAKE2b-256 |
469ec805c5096f118774e26bd8ad04e266f6bf0070f92b68f6b28f9efcbec5d4
|
Provenance
The following attestation bundles were made for tomlarg-0.2.0.tar.gz:
Publisher:
release.yml on tuppl/tomlarg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tomlarg-0.2.0.tar.gz -
Subject digest:
fbd2267675f2291b445c9e50ae38c563bea0bb8a4e0b0933dfb440002745b1b8 - Sigstore transparency entry: 2334975660
- Sigstore integration time:
-
Permalink:
tuppl/tomlarg@b275dadddf74a8658425edabdc3028ffeb4539e2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/tuppl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b275dadddf74a8658425edabdc3028ffeb4539e2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tomlarg-0.2.0-py3-none-any.whl.
File metadata
- Download URL: tomlarg-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80e9cedc5b8a33a270f3ef742e2452a1ae95444dd1044af92fe05be84968d498
|
|
| MD5 |
2d2a48173d0bad2d6141caee303ccb9a
|
|
| BLAKE2b-256 |
05c1b38b0e372f3323fa0f03fa0c0add7eec0ff34179957922979dff3bc9af4b
|
Provenance
The following attestation bundles were made for tomlarg-0.2.0-py3-none-any.whl:
Publisher:
release.yml on tuppl/tomlarg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tomlarg-0.2.0-py3-none-any.whl -
Subject digest:
80e9cedc5b8a33a270f3ef742e2452a1ae95444dd1044af92fe05be84968d498 - Sigstore transparency entry: 2334975687
- Sigstore integration time:
-
Permalink:
tuppl/tomlarg@b275dadddf74a8658425edabdc3028ffeb4539e2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/tuppl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b275dadddf74a8658425edabdc3028ffeb4539e2 -
Trigger Event:
push
-
Statement type: