Skip to main content

xconf - Dataclasses and TOML for command configuration

Demo

An example of how to use xconf.Command, xconf.field, and xconf.config is in xconf_demo.py. Run it to see its configuration keys.

$ python xconf_demo.py demo_command -h
demo_command: Demo command
usage: xconf_demo.py demo_command [-c CONFIG_FILE] [-h] [-v] [--dump-config] [vars ...]

positional arguments:
  vars                  Config variables set with 'key.key.key=value' notation

optional arguments:
  -c CONFIG_FILE, --config-file CONFIG_FILE
                        Path to config file (default: demo_command.conf)
  -h, --help            Print usage information
  -v, --verbose         Enable debug logging
  --dump-config         Dump final configuration state as TOML and exit

configuration keys:
  collections
      dict[str, ExtendedThingie]
  collections.<str>.name
      str
     <ExtendedThingie>
  collections.<str>.extended
      bool
     <ExtendedThingie>
  either_one
      [int, str]
  should_bar
      bool
     (default: False)
  should_foo
      bool
    Whether demo should foo
  number_list
      list[int]
    List of favorite numbers
  float_list
      list[float]
    List of favorite floating-point numbers
  str_list
      list[str]
    List of favorite strings
  sequence
      list[ExtendedThingie]
     (default: [])
  sequence[#].name
      str
     <ExtendedThingie>
  sequence[#].extended
      bool
     <ExtendedThingie>

Default config file

The command name, demo_command, is generated from the class name and used to find a default configuration file (demo_command.conf) in the current directory.

Providing arguments at the command line

Any configuration key from the help output can be supplied on the command line in a dotted.name=value format.

For lists of primitive types (str, int, float), you can just use commas to separate the values on the right hand side of the =. Example: number_list=1,2,3.

To override a single entry in a list, use some_name[#] or dotted[#].name=value where # is an integer index will work. Example: number_list[0]=99

String values are bare (i.e. no quotation marks around value). Boolean values are case-insensitive true, t, or 1 for True, false, f, or 0 for False.

Structuring the command

See xconf_demo.py for an example. Note that commands must subclass xconf.Command and apply the @xconf.config decorator. Options are defined by a hierarchy of dataclasses. (For uninteresting reasons, they aren't strictly speaking import dataclass dataclasses.)

License

All code outside xconf/vendor/ is provided under the terms of the MIT License, except for xconf_demo.py and demo_command.conf, which are released into the public domain for you to build off of.

Note that code under xconf/vendor/ is used under the terms of the licenses listed there.

Metadata

Release files for xconf 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xconf 0.0.2
File Size Uploaded Provenance Actions
xconf-0.0.2.tar.gz 32.6 kB Without provenance Details for xconf-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xconf 0.0.2
File Interpreter ABI Platform Actions
xconf-0.0.2-py3-none-any.whl Python 3 none any Details for xconf-0.0.2-py3-none-any.whl

Total release size: 66.7 kB

Release files / xconf-0.0.2.tar.gz

Download URL xconf-0.0.2.tar.gz
Size 32.6 kB
Tags Source
SHA-256 checksum
How to use checksums
591f9acc1690ba5b5915e5d49af00a9f5c0d200ce9b443bface0196827697d71
BLAKE2b-256 checksum
How to use checksums
6d670aa8ba63bbf7016187b9793c505286ca082bfc95dd63fd9d14c0c57beb2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.9

Release files / xconf-0.0.2-py3-none-any.whl

Download URL xconf-0.0.2-py3-none-any.whl
Size 34.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e11c8d61b1d1aea93bb32cfaaeb599bf08506f2bb31a60606bfed05e2cfd570a
BLAKE2b-256 checksum
How to use checksums
5d26be5d6394c3756a5383f2e76584d177a9e2506b655ccfeccca00fcf9c2b81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.9

Security for xconf 0.0.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

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