Skip to content

Yamlfix

Yamlfix is a simple opinionated yaml formatter that keeps your comments.

Install

pip install yamlfix

Usage

Imagine we've got the following source code:

book_library:
- title: Why we sleep
  author: Matthew Walker
- title: Harry Potter and the Methods of Rationality
  author: Eliezer Yudkowsky

It has the following errors:

  • There is no --- at the top.
  • The indentation is all wrong.

After running yamlfix the resulting source code will be:

---
book_library:
  - title: Why we sleep
    author: Matthew Walker
  - title: Harry Potter and the Methods of Rationality
    author: Eliezer Yudkowsky

yamlfix can be used both as command line tool and as a library.

  • As a command line tool:

    $: yamlfix file.yaml
    
  • As a library:

    from yamlfix import fix_files
    
    fix_files(['file.py'])
    

References