22
loading...
This website collects cookies to deliver better user experience
tomli-w
for writing.pyproject.toml
.pip
has since moved to tomli
.tomlkit
supports style-preserving roundtrip parsing. Furthermore, tomlkit
was created for the express purpose of handling TOML parsing for the poetry tool. As this is one of the 2 most popular new PEP517 & PEP518 Python build systems there is some comfort to be had in the wide adoption of a very actively used tool that means a greater likelihood of continued maintenance & support, and specifically that pyproject.toml
files should parse without surprises.1.0.0rc1
compliant. Looking at the TOML spec release history delta of rc1
vs v1
, it only looks like clarifications & administrative/documentation updates -there doesn't seem to be anything notable missing or functionally different in rc1
as opposed to v1
. It's not impossible that I missed something, though - but given TOMLKit
's wide usage via poetry
, I would expect obvious out-of-date spec handling to have been noticed by someone somewhere, and I see none such in the issues list.TOMLKit
outputs custom types rather than just the standard Python built-ins like dict
. Specifically it represents tables with classes like class Table(Item,MutableMapping, dict)
or class InlineTable(Item, MutableMapping, dict)
. Mapping
type does - which may or may not fit your needs, depending on what exactly you're doing. It probably doesn't really matter for most purposes.toml
library is a largely historical artifact at this point. Not only is it well behind on implementing TOML v1, but also because of a lack of maintenance on extant functionality. pip
itself has moved from vendoring toml to tomli. This exodus from toml
to tomli
includes the very prominent:tomli
, then, seems to be where the Python community in general is coalescing for a "standard" TOML parser. tomli
is read-only. For write functionality there is the companion library tomli-w.tomli
is explicitly TOML v1.0 compliant.tomli
is significantly faster than TOMLKit. It does not, however, preserve style/whitespace like tomlkit
does. For most use-cases, arguably TOML reading is the important part...tomlkit
if you need to round-trip & preserve style + comments.tomli
if you're just after reading a config file or write some output without caring about the formatting too much.tomli
matched the requirements with the least trade-offs. And as a mini-review, it was a joy to use 😄.tomli
& tomli-w
, you can check it out in action here: https://github.com/pypyr/pypyr/blob/main/pypyr/toml.py