Skip to main content

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_argument defaults.
  • 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: --debug and --no-debug.
  • Arrays take a comma-separated value (--tags a,b,c), with --tags= or a bare --tags giving an empty one.
  • --help lists 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.2.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tomlarg-0.2.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

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

Hashes for tomlarg-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fbd2267675f2291b445c9e50ae38c563bea0bb8a4e0b0933dfb440002745b1b8
MD5 bdda27048f305c2d0e41a627f7ab0f1c
BLAKE2b-256 469ec805c5096f118774e26bd8ad04e266f6bf0070f92b68f6b28f9efcbec5d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for tomlarg-0.2.0.tar.gz:

Publisher: release.yml on tuppl/tomlarg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for tomlarg-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 80e9cedc5b8a33a270f3ef742e2452a1ae95444dd1044af92fe05be84968d498
MD5 2d2a48173d0bad2d6141caee303ccb9a
BLAKE2b-256 05c1b38b0e372f3323fa0f03fa0c0add7eec0ff34179957922979dff3bc9af4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tomlarg-0.2.0-py3-none-any.whl:

Publisher: release.yml on tuppl/tomlarg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page