Package: tomlparse
tomlparsetomlparse is a Python library and command-line tool that allows you to useTOMLconfiguration files in conjunction with theargparse module. It provides a simple and convenient way to handle your python projects, leveraging the strengths of both TOML and argparse.Table of ContentsInstallationUsageBasic ExampleExtended ExampleContributingInstallationYou can install the library using pippipinstalltomlparseUsageUsing tomlparse is straightforward and requires only a few extra steps compared to using argparse alone.Basic ExampleYou first define your configuration options in a TOML file. TOML files are highly flexible and include a lot of native types. Have lookherefor an extensive list.  TOML files usually come in the following form:# This is a very basic TOML filefoo=10bar="hello"At the core of this module is theTOML ArgumentParser, a simple wrapper of the original argparse module. To use the TOML arguments for our project, we we would create anArgumentParseras usual:fromtomlparseimportargparseparser=argparse.ArgumentParser()parser.add_argument("--foo",type-int,default=0)parser.add_argumetn("--bar",type=str,default="")parser.parse_args()This is just a simple example with two arguments. But for larger projects with many hyperparameters, the number of arguments can quickly grow, and the TOML file provides an easy way to collect and store different hyperparameter configurations. Every TOML ArgumentParser has aconfigargument defined that we can pass using the following command-line syntax:pythonexperiment.py--config"example.toml"This will replace the default values from the ArgumentParser with the TOML values.Extended ExampleTOML files have the ability to separate arguments into different sections (calledtables), which are represented by nested dictionaries:# This is a TOML File# Parameters without a prededing [] are not part of a table (called root-table)foo=10bar="hello"# These arguments are part of the table [general][general]foo=20# These arguments are part of the table [root][root]bar="hey"If we would load this TOML file as usual this would return a dict{"foo": 10, "bar": "hello", "general": {"foo": 20}, "root" : {"bar": "hey"}}. Note thatfooandbarare overloaded and defined twice. To specify the values we wish to take each TOML ArgumentParser has two arguments defined:tableroot-tableWe can use these directly from the command-line:pythonexperiment.py--config"example.toml"--table"general"Here theroot-tableis not defined. In this case the arguments at the top of the file without a table are taken and parsing would return the following dict{"foo": 20, "bar": "hello"}. Note thattablearguments override arguments from theroot-table.We can also specify the root-table:pythonexperiment.py--config"example.toml"--table"general"--root-table"root"which would return the following dict{"foo: 20", "bar": "hey"}and override the arguments from the top of the TOML file.In general, we have the following hierarchy of arguments:Arguments passed through the command line are selected over TOML
arguments, even if both are passedArguments from the TOML file are preferred over the default argumentsArguments from the TOML with a section override the arguments without a sectionThis means that we can also override arguments in the TOML file from the command-line:pythonexperiment.py--config"example.toml"--table"general"--foo100ContributingPlease have a look at the contribution guidlines inContributing.rst.Repository initiated withfpgmaas/cookiecutter-poetry.