TOML Sort

0.24.4 · active · verified Sun Apr 12

toml-sort is a Python library and command-line utility for sorting and formatting TOML files. It provides features like sorting tables and arrays of tables, preserving comments, and standardizing whitespace and indentation. The library is actively maintained, with frequent releases, and is currently at version 0.24.4.

Warnings

Install

Imports

Quickstart

Demonstrates how to sort a TOML string programmatically using the `sort_toml_string` function.

from toml_sort.tomlsort_tool import sort_toml_string

unsorted_toml = '''
[database]
ports = [8000, 8001, 8002]
enabled = true

[owner]
name = "Tom"
dob = 1979-05-27T07:32:00-08:00
'''

sorted_toml = sort_toml_string(unsorted_toml)
print(sorted_toml)

view raw JSON →