This is a template repository for Python projects that use Poetry for their dependency management.
Project description
toml-argparse
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for toml_argparse-0.0.1a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 087ba9c11e23fb624b5c0aa1db7effcf8ed211d1dc01df4fa32b0224f351d751 |
|
MD5 | 871c418621623e90016e00cb4bfd7de2 |
|
BLAKE2b-256 | 50362eb49ea5d94db6d34e949b91f9dfcb8c2cba797869374d5d8cc148b6f4c5 |