Metadata-Version: 2.1
Name: toml-argparse
Version: 0.0.1a0
Summary: This is a template repository for Python projects that use Poetry for their dependency management.
Home-page: https://github.com/florianmahner/toml-argparse
Author: florianmahner
Author-email: fflorian.mahner@gmail.com
Requires-Python: >=3.8,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: toml (>=0.10.2,<0.11.0)
Requires-Dist: types-toml (>=0.1.3,<0.2.0)
Project-URL: Documentation, https://florianmahner.github.io/toml-argparse/
Project-URL: Repository, https://github.com/florianmahner/toml-argparse
Description-Content-Type: text/markdown

# toml-argparse

[![Release](https://img.shields.io/github/v/release/florianmahner/toml-argparse)](https://img.shields.io/github/v/release/florianmahner/toml-argparse)
[![Build status](https://img.shields.io/github/actions/workflow/status/florianmahner/toml-argparse/main.yml?branch=main)](https://github.com/florianmahner/toml-argparse/actions/workflows/main.yml?query=branch%3Amain)
![example workflow](https://github.com/florianmahner/toml-argparse/actions/workflows/main.yml/badge.svg)
[![codecov](https://codecov.io/gh/florianmahner/toml-argparse/branch/main/graph/badge.svg)](https://codecov.io/gh/florianmahner/toml-argparse)
[![License](https://img.shields.io/github/license/florianmahner/toml-argparse)](https://img.shields.io/github/license/florianmahner/toml-argparse)
![code style](https://img.shields.io/badge/code%20style-black-black)



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

```bash
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](https://github.com/florianmahner/toml-argparse/blob/main/toml_argparse/argparse.py) to add those options to your argparse argument parser. 


### Basic Example
[TOML](https://toml.io/en/) files usually come in the following form:

```toml
# 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:

```python
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:


```bash
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](https://github.com/fpgmaas/cookiecutter-poetry).

