Skip to main content

Purpose

Ever needed to compare two YAML files, when the keys were out of order?
Maybe you've tried cutting and pasting to move the keys around, wondering if there's a better way?
Well, now there is - yam_sort!

Okay, I may have been watching too much late-night TV. But this library was born out of frustration working with YAML files. I was using AWS API-Gateway YAML templates, which sometimes get exported in random order (especially when there are changes to it), making it hard to compare with git-checked-in copies. After the nth time moving keys around, I decided to automate it.

  • Do basic diff-ing of YAML files, while ignoring the order of keys/sub-keys.
  • Re-order a second dictionary/YAML file, to match the first file. Ignore missing keys, move extra keys to end of list.

This is a very narrowly-focussed library - it sorts one YAML file to match the key-order in another YAML file. But I don't know of any other automated way of doing this, and got tired of doing it manually.

Pip Requirements

  • PyYAML==5.1.2
  • virtualenv (optional, but highly recommended)

Installation

# activate a virtual environment
pip install yam_sort

Usage

yam_sort -h  
yam_sort -s file_one file_two  # synchronizes second file with first, 
                                 writes to stdout
yam_sort -s file_one file_two -o  # synchronizes second file with first, 
                                    overwrites second file
yam_sort -k file_one file_two  # lists key-differences between files
optional arguments:
  -h, --help                                   show this help message and exit
  -s first second, --sync file_one file_two    sync two YAML files
  -o, --overwrite                              saves output to second file
  -k first second, --keys file_one file_two    diff two YAML files by keys only

Note

Since the intent of this library is to compare YAML files that were exported from AWS API-Gateways, the resulting sorted-file has to be as similar as possible. This includes formatting of the keys/values in the file. AWS exports keys as unquoted, and all string-values as quoted. Therefore, this library copies the formatting from the original file, in the output-file. If a string was double-quoted, it will (should) be double-quoted in the output, and the same for single-quoting, etc.

Known Bugs

Some values can be multi-line, particularly in the section:

  • x-amazon-apigateway-gateway-responses:

These do not get properly copied over to the output-dict.

Metadata

Release files for yam-sort 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yam-sort 1.0
File Size Uploaded Provenance Actions
yam_sort-1.0.tar.gz 6.7 kB Without provenance Details for yam_sort-1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for yam-sort 1.0
File Interpreter ABI Platform Actions
yam_sort-1.0-py3-none-any.whl Python 3 none any Details for yam_sort-1.0-py3-none-any.whl

Total release size: 14.6 kB

Release files / yam_sort-1.0.tar.gz

Download URL yam_sort-1.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
765c986080b9d832871cb5c2c0a8efbe68353b0acd7577601b45420bcca99f71
BLAKE2b-256 checksum
How to use checksums
eb2260af1afa48397ea7d4ceb38ae0add9a6d380158911ad9ecdf785688b826d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.3

Release files / yam_sort-1.0-py3-none-any.whl

Download URL yam_sort-1.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
349c5b255b180481de04275aa14bbcc5795c8b0c5a1b97d9aca6f90e81c7d299
BLAKE2b-256 checksum
How to use checksums
cc190c2e35953f1fe28d8cfb4482751f8a62942ee3ac5238eede7426e8d54f54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.6.3

Security for yam-sort 1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page