Skip to main content

Toml sorting library

Project description

toml-sort

image-version image-license image

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

Stdin -> Disk : 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.16.0.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distribution

toml_sort-0.16.0-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

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