Skip to main content

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 piece tomllib doesn'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, no tomli/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

larztoml-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

larztoml-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

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

Hashes for larztoml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7d69abfb559d8c89b0f62b019528fd433dd675ad244f2ed82d08e9f3a01d48a5
MD5 791918549adb728ffd791e4e84f35480
BLAKE2b-256 5367a08615169aec6268f636282694baaeb95f5b27c4a4a52cdb88916c1faf0f

See more details on using hashes here.

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

Hashes for larztoml-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3432bb66cab3fcc07543fbda1219446dce08fce4749d01a5c68e02ce25fac255
MD5 78b7bd4d67d3c4dd9d6aaecf890ee0b7
BLAKE2b-256 90f5b68917ff3f3204402b3cd7eac9f8a69e1079d4e3523bc855ae9c3057e4cd

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page