larztoml
TOML read and write. Pure Python (back to 3.8), zero dependencies.
The standard library gained tomllib in 3.11 — but it only reads, and only on
new Pythons. larztoml both parses and serializes TOML, on any supported Python,
with no dependency.
from larztoml import loads, dumps
cfg = loads("""
title = "myapp"
[server]
host = "localhost"
port = 8080
tags = ["a", "b"]
[[user]]
name = "Ada"
""")
dumps(cfg) # back to TOML text
Why
- It writes.
dumps()is the piecetomllibdoesn't have — generate config files, not just read them. - Works everywhere. Python 3.8+, not just 3.11+.
- Real TOML.
[tables],[[arrays of tables]], nested and dotted keys, typed values (strings incl. literal/multiline, ints/floats with_and hex/oct/bin,inf/nan, bools, dates and datetimes), arrays (including multi-line), inline tables, and comments. - Zero dependencies. No
toml, notomli/tomli-w.
Install
pip install larztoml
Usage
from larztoml import loads, dumps
data = loads(open("pyproject.toml").read())
text = dumps({"tool": {"app": {"port": 8080, "hosts": ["a", "b"]}}})
Dates parse to datetime/date/time; numbers keep their type. Round-trips:
loads(dumps(obj)) == obj for the supported subset.
Tests
python -m unittest discover -s tests -v # 21 tests incl. dump round-trips
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter — pairs with larzconf and larzyaml.
License
MIT © larz-scripter
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file larztoml-0.1.0.tar.gz.
File metadata
- Download URL: larztoml-0.1.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d69abfb559d8c89b0f62b019528fd433dd675ad244f2ed82d08e9f3a01d48a5
|
|
| MD5 |
791918549adb728ffd791e4e84f35480
|
|
| BLAKE2b-256 |
5367a08615169aec6268f636282694baaeb95f5b27c4a4a52cdb88916c1faf0f
|
File details
Details for the file larztoml-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larztoml-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3432bb66cab3fcc07543fbda1219446dce08fce4749d01a5c68e02ce25fac255
|
|
| MD5 |
78b7bd4d67d3c4dd9d6aaecf890ee0b7
|
|
| BLAKE2b-256 |
90f5b68917ff3f3204402b3cd7eac9f8a69e1079d4e3523bc855ae9c3057e4cd
|