A format-preserving TOML parser and writer for Python.
Project description
tomlrt
A format-preserving TOML parser and writer for Python.
Usage
import tomlrt
# Files must be opened in binary mode.
with open("pyproject.toml", "rb") as f:
doc = tomlrt.load(f)
doc["project"]["version"] = "0.2.0"
doc["project"]["dependencies"].append("requests>=2")
print(tomlrt.dumps(doc)) # comments and layout are preserved
Structural assignment
A plain dict value installs as an inline table; a plain list installs as an
inline array.
To pick a different shape, assign a flavoured value:
from tomlrt import AoT, Array, Table
doc["tool"] = Table.section({"version": 1}) # [tool] section
doc["xy"] = {"x": 1, "y": 2} # xy = { x = 1, y = 2 }
doc["pkgs"] = AoT([{"a": 1}, {"b": 2}]) # [[pkgs]] … [[pkgs]]
doc["tags"] = Array(["a", "b"], multiline=True) # multi-line array
Use doc.install(path, value) for dotted-path placement.
Plain doc["a.b"] = … always treats "a.b" as a single literal key, so
install is the way to descend through a into b.
Pass a tuple when one of the segments itself contains a literal .:
doc.install("tool.poetry.version", "0.1.0") # [tool.poetry] version = "0.1.0"
doc.install(("tool", "weird.key"), 1) # [tool] "weird.key" = 1
Comment API
doc = tomlrt.loads("""
[server]
host = "localhost" # default
port = 8080
""")
server = doc.table("server")
server.comments["port"] = "override with $PORT"
server.comments["host"] = None # clear
print(tomlrt.dumps(doc))
# [server]
# host = "localhost"
# port = 8080 # override with $PORT
Project details
Release history Release notifications | RSS feed
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 tomlrt-0.4.0.tar.gz.
File metadata
- Download URL: tomlrt-0.4.0.tar.gz
- Upload date:
- Size: 132.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8af79f664dfe8fd9d1886c89fe46273fe527e7542acdc4cfe4874ddcaaeff2b1
|
|
| MD5 |
7a7d52e7e4fd1400ae02dbd9997f8cc3
|
|
| BLAKE2b-256 |
5e8655629895edc05628eb7fff93e58a425290f048b618ff9555979352e78f59
|
Provenance
The following attestation bundles were made for tomlrt-0.4.0.tar.gz:
Publisher:
publish.yml on dimbleby/tomlrt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tomlrt-0.4.0.tar.gz -
Subject digest:
8af79f664dfe8fd9d1886c89fe46273fe527e7542acdc4cfe4874ddcaaeff2b1 - Sigstore transparency entry: 1365836674
- Sigstore integration time:
-
Permalink:
dimbleby/tomlrt@6845a2e73fe1d10115342de9c41350eca93343a3 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/dimbleby
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6845a2e73fe1d10115342de9c41350eca93343a3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tomlrt-0.4.0-py3-none-any.whl.
File metadata
- Download URL: tomlrt-0.4.0-py3-none-any.whl
- Upload date:
- Size: 61.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d35f56b1f7061600cfe3379a9fba3fc4859db11e8dc62cceedd7e07c79ac3b0
|
|
| MD5 |
ca0abc67481282af88bbadc84e21bfd2
|
|
| BLAKE2b-256 |
cbe9147f99205768f81a168c8db6791f733c7bbf3a2da5894b5f98e44f1a7251
|
Provenance
The following attestation bundles were made for tomlrt-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on dimbleby/tomlrt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tomlrt-0.4.0-py3-none-any.whl -
Subject digest:
4d35f56b1f7061600cfe3379a9fba3fc4859db11e8dc62cceedd7e07c79ac3b0 - Sigstore transparency entry: 1365836797
- Sigstore integration time:
-
Permalink:
dimbleby/tomlrt@6845a2e73fe1d10115342de9c41350eca93343a3 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/dimbleby
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6845a2e73fe1d10115342de9c41350eca93343a3 -
Trigger Event:
push
-
Statement type: