Skip to main content

Toml sorting library

Project description

toml-sort

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

Installation

# With pip
pip install toml-sort

# With poetry
poetry add toml-sort

Motivation

This library strives to sort TOML files by 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 because I couldn't find any "good" sorting utilities for TOML files.

Usage

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

Command line interface

Print detailed help

toml-sort --help

Read from stdin, write to stdout:

cat input.toml | toml-sort

Read from file on disk, write to file on disk:

toml-sort -o output.toml input.toml

Read from file on disk, write to stdout

toml-sort input.toml

Read from stdin, write to file on disk

cat input.toml | toml-sort -o output.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.15.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

toml_sort-0.15.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toml-sort-0.15.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Linux/4.15.0-58-generic

File hashes

Hashes for toml-sort-0.15.0.tar.gz
Algorithm Hash digest
SHA256 7db52845f48c2619708c5ff7e3ee0e7cd9becc5742180c05abb1f4208fbe0697
MD5 64164b5b40f6c9464b2c97630d65c0f8
BLAKE2b-256 446fdb166179dd27e45639a4d20b1f783e89341a43d9169ad76a028e58ac3cfa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: toml_sort-0.15.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Linux/4.15.0-58-generic

File hashes

Hashes for toml_sort-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce58fe56abd509578164e2a4ccc46bf103c75e4c4f6bdf653965eeb200cf4cc3
MD5 6ff950d350fca7a241f729795ca6bd8f
BLAKE2b-256 889f2d5dfe4edd08edda241876f105e17e5df74070c0db82bc67d95d38e0613b

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