Skip to content

Quickstart

Save this as example.toml:

[project]
name = "my-app"
version = "1.0.0"
# Search terms for the package index
keywords = ["python", "toml"]

Read the file with load, edit the document like a dictionary, and write it back with dump:

from pathlib import Path

from tomledit import dump, load

path = Path("example.toml")
with path.open("rb") as f:
    doc = load(f)

project = doc["project"]

project["version"] = "2.0.0"
project["keywords"].append("important-keyword")

with path.open("wb") as f:
    dump(doc, f)
[project]
name = "my-app"
version = "2.0.0"
# Search terms for the package index
keywords = ["python", "toml", "important-keyword"]

Use loads and dumps when working with strings instead of files.