Built Status ReadTheDocs Coveralls PyPI-Server Project generated with PyScaffold

ini2toml

Automatically translates .ini/.cfg files into TOML

Important

This project is experimental and under active development Issue reports and contributions are very welcome.

Description

The original purpose of this project is to help migrating setup.cfg files to PEP 621, but by extension it can also be used to convert any compatible .ini/.cfg file to TOML.

Please notice, the provided .ini/.cfg files should follow the same syntax supported by Python’s ConfigParser library (here referred to as INI syntax) and more specifically abide by ConfigUpdater restrictions (e.g., no interpolation or repeated fields).

Usage

ini2toml comes in two flavours: “lite” and “full”. The “lite” flavour will create a TOML document that does not contain any of the comments from the original .ini/.cfg file. On the other hand, the “full” flavour will make an extra effort to translate these comments into a TOML-equivalent (please notice sometimes this translation is not perfect, so it is always good to check the TOML document afterwards).

To get started, you need to install the package, which can be easily done using pipx:

$ pipx install 'ini2toml[lite]'
# OR
$ pipx install 'ini2toml[full]'

Now you can use ini2toml as a command line tool:

# in you terminal
$ ini2toml --help
$ ini2toml path/to/ini/or/cfg/file

You can also use ini2toml in your Python scripts or projects:

# in your python code
from ini2toml.api import Translator

profile_name = "setup.cfg"
toml_str = Translator().translate(original_contents_str, profile_name)

To do so, don’t forget to add it to your virtual environment or specify it as a project dependency.

Note that the class Translator will try to guess which flavour to use based on the available installed dependencies. If you need something more deterministic, consider using LiteTranslator and FullTranslator, or explicitly specifying the ini_loads_fn and toml_dumps_fn keyword arguments in the constructor.

More details about ini2toml and its Python API can be found in our docs.

Tip

If you consider contributing to this project, have a look on our contribution guides.

Note

This project was initially created in the context of PyScaffold, with the purpose of helping migrating existing projects to PEP 621-style configuration when it is made available on setuptools. For details and usage information on PyScaffold see https://pyscaffold.org/.