Skip to main content

yamlruff

PyPI License

A fast YAML linter and fixer, written in Rust.

  • ⚡️ Fast: about 28× faster than existing YAML linters and 13× faster than existing YAML fixers (measured on real-world files).
  • 🔧 Lint and fix in one tool: yamlruff lint reports, yamlruff fix repairs, with one shared configuration.
  • 🛡️ Safe fixes: every fix is checked to leave the loaded data unchanged; files with syntax errors are never touched.
  • 📏 23 built-in rules: whitespace, indentation, flow collections, comments, quoting, keys and anchors.
  • 🐍 Installable via pip or uv, as a prebuilt binary: no Python dependencies, no Rust toolchain.
  • 🛠️ pyproject.toml support: configure under [tool.yamlruff], or in a .yamlruff file.
  • 🧩 Shareable configs with extends, per-rule ignore, and inline # yamlruff disable comments.
  • 🤖 CI-friendly: --check for fixes, -f github annotations, and clear exit codes.

yamlruff is an independent project, not affiliated with Astral or the ruff project.


Table of Contents

Getting Started

With uv, no install needed:

uvx yamlruff lint .        # find problems
uvx yamlruff fix --diff .  # preview the fixes
uvx yamlruff fix .         # apply them

Or with pip:

pip install yamlruff
yamlruff lint .            # find problems
yamlruff fix --diff .      # preview the fixes
yamlruff fix .             # apply them

For example, given service.yml:

name:   web
enabled: yes
ports: [ 80,443 ]

yamlruff lint service.yml reports the missing ---, the extra spaces after the colon, the yes, the spaces inside the brackets and the missing space after the comma. yamlruff fix repairs the layout problems right away and leaves the yes for --unsafe-fixes, because rewriting it to true changes what some YAML loaders read.

Installation

uv tool install yamlruff     # or: pipx install yamlruff / pip install yamlruff

Run it once without installing with uvx yamlruff …. Check the install with yamlruff --version.

Prebuilt wheels exist for macOS (Intel and Apple Silicon) and Linux (glibc and musl; x86_64 and aarch64). On other platforms pip builds from the source distribution and needs Rust.

Usage

yamlruff lint [PATHS]...           # report problems ('-' reads stdin; default '.')
yamlruff fix [PATHS]...            # rewrite files, then report what is left
yamlruff rule [ID]                 # list the rules, or document one
Command / option Effect
lint -f standard|parsable|colored|github|auto Output format
lint -s, --strict Exit non-zero on warnings as well as errors
lint --no-warnings Show errors only
lint --list-files Show which files would be checked, then exit
fix --diff Show the changes, write nothing
fix --check Write nothing; exit 1 if any file would change
fix --unsafe-fixes Also apply fixes that may change what other loaders read
fix --unfixable ID Never apply the fixes of this rule
-c FILE, -d 'YAML' Use a config file, or config given inline

Configuration

yamlruff reads .yamlruff (or .yamlruff.yaml / .yamlruff.yml) from the current directory and then upward, or a [tool.yamlruff] table in pyproject.toml. Without either, it uses the default preset; extends: relaxed is more lenient.

# .yamlruff
extends: default
rules:
  line-length: {max: 120}
  truthy: {check-keys: false}     # keep `on:` as a key in GitHub Actions
  indentation: {spaces: 2, indent-sequences: true}
  trailing-spaces: disable
ignore: |
  dbt_packages/
  target/
# pyproject.toml
[tool.yamlruff.rules]
line-length = { max = 120 }

Other top-level keys: yaml-files (which files count as YAML), ignore-from-file, respect-gitignore (default false), locale, and the fix: section described under Fixing. Turn rules off inside a file with comments:

# yamlruff disable-line rule:line-length
# yamlruff disable rule:truthy
# yamlruff enable rule:truthy
# yamlruff disable-file

Rules

23 rules; yamlruff rule <id> shows the options, defaults and what the fix does.

Rule Checks Default Fix
anchors Report undeclared aliases, duplicated anchors and unused anchors error safe
braces Control the spaces inside and the number of items of flow mappings {...}, or forbid them error safe
brackets Control the spaces inside and the number of items of flow sequences [...], or forbid them error safe
colons Control the spaces before and after : in mappings error safe
commas Control the spaces before and after , in flow collections error safe
comments Require a space after # and spaces before an inline comment (a #! shebang on the first line can be allowed) warning safe
comments-indentation Require comments to be indented like the content around them warning safe
document-end Require or forbid the document end marker ... off safe
document-start Require or forbid the document start marker --- warning safe
empty-lines Limit the number of consecutive blank lines, and at the start and end of the file error safe
empty-values Forbid empty values in block mappings, flow mappings and block sequences off safe
float-values Forbid NaN, infinity, scientific notation and decimals without a leading numeral off safe
hyphens Limit the spaces after - in block sequences error safe
indentation Control the indentation of blocks, and of sequences inside mappings error safe
key-duplicates Forbid duplicated keys in a mapping (and optionally repeated << merge keys) error unsafe
key-ordering Require the keys of a mapping to be in alphabetical order (see locale) off safe
line-length Limit the length of lines error safe
new-line-at-end-of-file Require a newline at the end of the file error safe
new-lines Require a given type of line break (unix, dos or platform) error safe
octal-values Forbid implicit (0755) and explicit (0o755) octal numbers off unsafe
quoted-strings Require or forbid quotes around strings, and choose the quote type off safe
trailing-spaces Forbid spaces at the end of lines error safe
truthy Forbid values such as yes and on that are booleans for some YAML versions warning unsafe

Fix: safe changes layout only; unsafe needs --unsafe-fixes. A few cases within a rule (for example .nan in float-values, or undeclared aliases) have no fix and only report. Rules that report as error fail the run, warning rules only with --strict.

Fixing

yamlruff fix applies the fix that belongs to each problem, using the rule's own options, so after a fix lint has nothing left to report that could have been fixed automatically. After every round it checks that the document still loads to the same data, and drops any fix that would change it. Some problems have no safe automatic fix (a duplicated key with different values, a line that cannot be wrapped) and stay in the report.

Pure style choices that no rule expresses go in a fix: section:

fix:
  sequence-style: flow         # keep | flow | block
  none-representation: empty   # keep | empty | null | '~' | Null | NULL
  whitelines: 1                # blank lines between content
  comments-whitelines: 1       # blank lines before a comment
  section-whitelines: 1        # blank lines around top-level sections
  join-multiline: false        # put multi-line scalars on one line when they fit
  simplify-block-headers: false
  unsafe-fixes: false
  unfixable: []                # rule ids whose fixes are never applied

Continuous integration

yamlruff lint --strict .       # fail the build on any problem
yamlruff fix --check .         # fail if formatting would change anything
yamlruff lint -f github .      # annotate the pull request in GitHub Actions

Exit codes for lint: 0 clean, 1 errors, 2 warnings only (with --strict).

Contributing

Bug reports, ideas and pull requests are welcome. See CONTRIBUTING.md for how to build, test and release.

Support

Open an issue on the repository with the yamlruff --version, the command you ran, and a minimal YAML file that shows the problem.

License

This repository is licensed under the GPL-3.0-or-later License.

Metadata

Release files for yamlruff 0.0.3

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

Source distribution (sdist)

Source distribution for yamlruff 0.0.3
File Size Uploaded Provenance
yamlruff-0.0.3.tar.gz 512.5 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for yamlruff 0.0.3
File
yamlruff-0.0.3-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details
yamlruff-0.0.3-py3-none-musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64 Details
yamlruff-0.0.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
yamlruff-0.0.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details
yamlruff-0.0.3-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl Python 3 none macOS 11.0+ ARM64, macOS 10.12+ x86-64, macOS 10.12+ universal2 (ARM64, x86-64) Details

Total release size: 9.1 MB

Release files / yamlruff-0.0.3.tar.gz

Download URL yamlruff-0.0.3.tar.gz
Size 512.5 kB
Tags Source
SHA-256 checksum
How to use checksums
28384e2b04bddeada070e173630868a586f96dc32f61efd30c5cd90c6be90b99
BLAKE2b-256 checksum
How to use checksums
8a87572d0f53f0a6e4c2b8efb5416a90deb4d129ed3dd01063b0850834356409
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.11.5

Release files / yamlruff-0.0.3-py3-none-musllinux_1_2_x86_64.whl

Download URL yamlruff-0.0.3-py3-none-musllinux_1_2_x86_64.whl
Size 1.5 MB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
79c02ebf9d4557c8d9f97f1cab90b1baab39da9591aa9dab25393f29e55e06dd
BLAKE2b-256 checksum
How to use checksums
85cac780feec84304f655d915676b1cff5dd4e43589bcc8acee9203dadf89b45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.11.5

Release files / yamlruff-0.0.3-py3-none-musllinux_1_2_aarch64.whl

Download URL yamlruff-0.0.3-py3-none-musllinux_1_2_aarch64.whl
Size 1.4 MB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
1deac294f17f7b850b8aa70a0738456bb0203243c8533d4bb7cd70e3ebc57ac7
BLAKE2b-256 checksum
How to use checksums
2a5e790706a962cdc59b1e3ccc2688f3b9ee1e9b7e9e5cc1e3a28784056ce0b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.11.5

Release files / yamlruff-0.0.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL yamlruff-0.0.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.5 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
2e08b9d8cc6c7b7e3a5e56963f8dc8e3c4c7e5a0f4e83220ce96289e3f3af8c7
BLAKE2b-256 checksum
How to use checksums
366c79c008b8b9fab9473a0f98e117724cee7919db61ad92ef05509b2c08738c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.11.5

Release files / yamlruff-0.0.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL yamlruff-0.0.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.4 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
e6066ee77ab0c915db939a1e6c17f20875fa308791e15e208f7c83a4a0c0564d
BLAKE2b-256 checksum
How to use checksums
37621675c883c21f5cd29fdc3b9fc9a4cadd40199af35982c3b9fcb81ce8fed2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.11.5

Release files / yamlruff-0.0.3-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL yamlruff-0.0.3-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 2.7 MB
Tags Python 3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d4ff7696afa5e6fe6b393762fb9bbad4bdc89b7978ec8baf5ed897d93849acfe
BLAKE2b-256 checksum
How to use checksums
311b7b85d8f0a5cd1752d28db0d9620daf53585745cbe02225908c7c593e9974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.11.5

Security for yamlruff 0.0.3

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

0.0.3 This release

6 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