Skip to main content

Toml sorting library

Project description

toml-sort

pypi-version license python-versions readthedocs-status

A command line utility to sort and format your toml files. Requires Python 3.6+.

Read the latest documentation here: https://toml-sort.readthedocs.io/en/latest/

Installation

# With pip
pip install toml-sort

# With poetry
poetry add toml-sort

Motivation

This library sorts TOML files, providing the following features:

  • Sort tables and Arrays of Tables (AoT)
  • Option to sort non-tables / non-AoT's, or not
  • Preserve inline comments
  • Option to preserve top-level document comments, or not
  • Standardize whitespace and indentation

I wrote this library/application because I couldn't find any "good" sorting utilities for TOML files. Now, I use this as part of my daily workflow. Hopefully it helps you too!

Usage

This project can be used as either a command line utility or a Python library.

Command line interface

Stdin -> Stdout : cat input.toml | toml-sort

Disk -> Disk    : toml-sort -o output.toml input.toml

Linting         : toml-sort --check input.toml

Inplace Disk    : toml-sort --in-place input.toml

Example

The following example shows the input, and output, from the CLI with default options.

Unformatted, unsorted input

# My great TOML example

  title = "The example"

[[a-section.hello]]
ports = [ 8001, 8001, 8002 ]
dob = 1979-05-27T07:32:00Z # First class dates? Why not?



  [b-section]
  date = "2018"
  name = "Richard Stallman"

[[a-section.hello]]
ports = [ 80 ]
dob = 1920-05-27T07:32:00Z # Another date!

                          [a-section]
                          date = "2019"
                          name = "Samuel Roeca"

Formatted, sorted output

# My great TOML example

title = "The example"

[a-section]
date = "2019"
name = "Samuel Roeca"

[[a-section.hello]]
ports = [ 8001, 8001, 8002 ]
dob = 1979-05-27T07:32:00Z # First class dates? Why not?

[[a-section.hello]]
ports = [ 80 ]
dob = 1920-05-27T07:32:00Z # Another date!

[b-section]
date = "2018"
name = "Richard Stallman"

Local Development

Local development for this project is quite simple.

Dependencies

Install the following tools manually.

Recommended

Set up development environment

make setup

Run Tests

make test

Written by

Samuel Roeca, samuel.roeca@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

toml-sort-0.18.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

toml_sort-0.18.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file toml-sort-0.18.0.tar.gz.

File metadata

  • Download URL: toml-sort-0.18.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/4.15.0-1079-oem

File hashes

Hashes for toml-sort-0.18.0.tar.gz
Algorithm Hash digest
SHA256 93c8ba23c540f9029d20b4a3d6b9ec650fc32d1586d701939e6614390820b3f0
MD5 7f7fb26528e849c6742d46b52a3c339c
BLAKE2b-256 7247870c600d245dfe3e5ad18f9ef07496dfc52131de0074e56e558fc464e9f4

See more details on using hashes here.

File details

Details for the file toml_sort-0.18.0-py3-none-any.whl.

File metadata

  • Download URL: toml_sort-0.18.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/4.15.0-1079-oem

File hashes

Hashes for toml_sort-0.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bb460111e2d9e275c4b80ebbc57b4153d4cd24d0ac1d875126d6f86e032da13
MD5 9869a8e8ac14289f22675142dd63157f
BLAKE2b-256 e1d076baa446dccf372607a09e703b28fc934937ac99943cc2e8b436ba5daa03

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page