Port variant | py38 |
Summary | Lil' TOML parser (PY38) |
Package version | 1.2.2 |
Homepage | No known homepage |
Keywords | python |
Maintainer | Python Automaton |
License | Not yet specified |
Other variants | py39 |
Ravenports | Buildsheet | History |
Ravensource | Port Directory | History |
Last modified | 28 OCT 2021, 11:26:46 UTC |
Port created | 18 JUL 2021, 04:13:17 UTC |
single | [Build Status] [![codecov.io]](https://codecov.io/gh/hukkin/tomli) [PyPI version] # Tomli > A lil' TOML parser **Table of Contents** *generated with [mdformat-toc]* - [Intro] - [Installation] - [Usage] - [Parse a TOML string] - [Parse a TOML file] - [Handle invalid TOML] - [Construct `decimal.Decimal`s from TOML floats] - [FAQ] - [Why this parser?] - [Is comment preserving round-trip parsing supported?] - [Is there a `dumps`, `write` or `encode` function?] - [How do TOML types map into Python types?] - [Performance] ## Intro Tomli is a Python library for parsing [TOML]. Tomli is fully compatible with [TOML v1.0.0]. ## Installation `bash pip install tomli ` ## Usage ### Parse a TOML string ```python import tomli toml_str = """ gretzky = 99 [kurri] jari = 17 """ toml_dict = tomli.loads(toml_str) assert toml_dict == {"gretzky": 99, "kurri": {"jari": 17}} ``` ### Parse a TOML file ```python import tomli with open("path_to_file/conf.toml", "rb") as f: toml_dict = tomli.load(f) ``` The file must be opened in binary mode (with the `"rb"` flag). Binary mode will enforce decoding the file as UTF-8 with universal newlines disabled, both of which are required to correctly parse TOML. Support for text file objects is deprecated for removal in the next major release. ### Handle invalid TOML ```python import tomli try: toml_dict = tomli.loads("]] this is invalid TOML [[") except tomli.TOMLDecodeError: print("Yep, definitely not valid.") ``` Note that while the `TOMLDecodeError` type is public API, error messages of raised instances of it are not. Error messages should not be assumed to stay constant across Tomli versions. ### Construct `decimal.Decimal`s from TOML floats ```python from decimal import Decimal import tomli toml_dict = tomli.loads("precision-matters = 0.982492", parse_float=Decimal) assert toml_dict["precision-matters"] == Decimal("0.982492") ``` |
Build (only) |
python-pip:single:py38 autoselect-python:single:standard |
Build and Runtime | python38:single:standard |
main | mirror://PYPIWHL/6d/6c/9908d4db66488217c665a9a5744319406e41f3c46fa5929a8886f2fe1090 |
python-black:py38 | Uncompromising code formatter (PY38) |
python-setuptools-scm:py38 | Package to manage versions by scm tags (PY38) |