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). - 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
tomlarg-0.1.0.tar.gz
(7.6 kB
view details)
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
tomlarg-0.1.0-py3-none-any.whl
(10.5 kB
view details)
File details
Details for the file tomlarg-0.1.0.tar.gz.
File metadata
- Download URL: tomlarg-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
887f99dc50d11c30ff7619d01c63f0f5daf8adb66c0e953226e16b1b8a0273cf
|
|
| MD5 |
b879098b1fee2573adecf8d86eb82290
|
|
| BLAKE2b-256 |
076f7a6cc2bed00b0e08f67d77c1b20c0962871ce5828dc4c383c5dbb235a534
|
File details
Details for the file tomlarg-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tomlarg-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad51d423fcd9521b904213d74228dbb037f4cbec2a0acd739a1e63ecf6d32ec2
|
|
| MD5 |
84ec7f2203b154c8afc01294bdb75722
|
|
| BLAKE2b-256 |
b0582aa819bf7f5e85cfb57d7a90fa8bb5cae836b433dc0c11b9d17da90e01b7
|