Skip to main content

This is a template repository for Python projects that use Poetry for their dependency management.

Project description

toml-argparse

Release Build status example workflow codecov License code style

toml-argparse is a python library and command-line-tool that allows you to use TOML configuration files with the argparse module. It provides a simple and convenient way to handle configuration for your python scripts, leveraging the strengths of both TOML and argparse.

Installation

You can install the library using pip

pip install toml-argparse

Usage

Using toml-argparse is straightforward and requires only a few extra steps compared to using argparse alone. You first define your configuration options in a TOML file, then use the toml_argparse.ArgumentParser to add those options to your argparse argument parser.

Basic Example

TOML files usually come in the following form:

# This is a TOML File

# These are parameters not part of a section
foo = 10
bar = "hello"

# This is a parameter that belongs to a section
[general]
foo = 42

Say we want to use the fields from the TOML file also for our python project. To do this we would create an ArgumentParser as usual:

from toml_argparse import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--foo", type-int, default=0)
parser.add_argumetn("--bar", type=str, default="")
parser.parse_args()

This is just a very simple example with two arguments. For large projects with a lot of hyperparameters the number of arguments usually increases quickly. In this case, we can now easily parse parameters through the TOML file from the command-line:

python experiment.py --config "example.toml"

This will replace our argparse defaults with the ones specified in the toml file.

Contributing

Please have a look at the contribution guidlines in Contributing.rst.


Repository initiated with fpgmaas/cookiecutter-poetry.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

toml_argparse-0.0.1a0.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

toml_argparse-0.0.1a0-py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page