CLI tool
kislyuk/yq avatar
kislyuk/yq

kislyuk/yq: a jq wrapper for YAML, XML and TOML

Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents

3,004 stars90 forksPythonApache-2.0

At a glance

What is it?
The Python yq converts YAML, XML and TOML into JSON, hands it to jq, and converts the result back. It is a thin adapter, and its roundtrip mode is where the real trade-offs live.
Who is it for?
Adopt kislyuk/yq if you already write jq filters and want them to work on YAML, XML or TOML without learning a second query language, and if you can install both the Python package and the jq binary. Do not adopt it for comment-preserving edits to ordinary YAML files, or if you need a single self-contained binary with no Python runtime: -Y only roundtrips tags and styles, and comments fail on scalar-rooted documents.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 43 days ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • kislyuk/yq3,004 ★ · +20
Star history
Repository2026-09-242026-11-22
kislyuk/yq3k3k

20 Stars in the last 59 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

What kislyuk/yq actually solves

jq is a JSON processor. Most configuration that engineers edit by hand is YAML, and a fair amount of enterprise data arrives as XML. Converting between them by hand, or writing a bespoke script per format, is the problem this project targets. The README describes yq as taking YAML input, converting it to JSON, and piping it to jq. The same package installs two more entry points: xq for XML and tomlq for TOML, declared in pyproject.toml under [project.scripts].

The audience is narrow and specific. You already know jq's filter language, you work with YAML or XML on the command line, and you want one mental model instead of three. If you have never written a jq filter, the value proposition is weaker, because yq does not abstract jq away. It forwards arguments to jq and hands back jq's exit code, except when YAML parsing fails, in which case the exit code is 1.

The pipeline: YAML in, JSON through jq, YAML out

The mechanism is a transcoding layer, not a YAML engine of its own. Input is parsed with PyYAML, serialized to JSON, and passed to the jq binary. Whatever jq prints is what you get, unless you ask for a conversion back. The README is explicit that by default no conversion of jq output is done, and that --yaml-output or -y turns the result back into YAML. Mapping key order is preserved.

XML support follows the same shape through a different parser. The package installs xq, which transcodes XML to JSON using xmltodict and pipes it to jq. Roundtrip transcoding is available with xq --xml-output or xq -x. For large documents, --xml-item-depth descends into the tree and streams contents without loading the full document into memory; the README gives a Wikipedia dump pipeline as the example. Entity expansion and DTD resolution are mentioned in the README, but the text available here cuts off before explaining how they are handled, so treat that area as undocumented in what I can verify.

The interesting part is -Y, the --yaml-roundtrip option. It preserves custom YAML tags and styles by representing them as extra items inside their enclosing mappings and sequences while the data is in JSON. On the way back, yq parses that metadata, reapplies the tags and styles, and discards the extra pairs and values. The README's CloudFormation example shows the difference: a plain -y pass drops !Ref tags and the folded style of a Description field, while -Y keeps both.

Installing yq and running a first filter

There are two things to install, and the README is clear that the second is not optional: yq itself, and jq, which is a separate binary. The README points to the jq installation instructions for platform-specific directions. On macOS, the README notes that yq is available through Homebrew as python-yq.

The Python package installs three console scripts: yq, xq and tomlq.

bash
pip install yq

Before running anything, confirm jq is on your PATH. yq shells out to it; a missing jq is a runtime failure, not an install-time one.

bash
cat input.yml | yq .foo.bar

A first real use is a query against a file rather than a pipe. The README shows both forms, and the file argument is usually the one you want in a script.

bash
yq .foo.bar input.yml

That prints JSON, because no output conversion happens by default. Add -y when you want YAML back, which is the form most people reach for when editing configuration.

bash
cat input.yml | yq -y .foo.bar

For in-place edits, the README shows the module form with sed -i semantics. This example rewrites the current context in a kubeconfig:

bash
python -m yq -Y --indentless --in-place '.["current-context"] = "staging-cluster"' ~/.kube/config

Two formatting options are worth knowing early. --width or -w sets the line wrap width for string literals, and --width 0 disables wrapping. --explicit-start and --explicit-end emit YAML start and end markers even for a single document. YAML output preserves an explicit leading --- from the input and emits one for multidocument streams.

Where -Y breaks your jq filter

This is the limitation the README states most plainly, and it deserves more attention than the feature it accompanies. Because -Y injects metadata into the JSON document, any jq filter that does not expect that extra information can produce wrong answers. The README's own example: a filter that counts entries in an Instances array will report 4 instead of 2. A filter that assumes every array entry is a mapping can break outright, because string metadata keys now sit alongside real values.

The practical consequence is that -Y is not a drop-in upgrade from -y. It changes the shape of the data your filter sees. If your filter aggregates, counts, or validates structure, you have to check it for compatibility before trusting the output. The README says exactly this: check your jq filter for compatibility and semantic validity when using -Y.

A second, narrower failure mode concerns comments. YAML comment metadata is attached to entries in mappings and sequences. A document whose root is a scalar (string, number, boolean, or null) has no enclosing collection to carry that metadata through jq, so comments cannot roundtrip. The README's example is a Markdown heading after a YAML document separator, which is treated as a comment on a root string and is lost. The suggested workaround is --yaml-frontmatter or -F, which preserves the entire body. That option has its own constraints: only the first document is sent to jq, the filter must produce exactly one document, and each invocation accepts one input file unless you use --in-place.

Mikefarah/yq versus kislyuk/yq

The name collision is the first thing most people hit, and the related searches confirm it: Mikefarah/yq and Yq mikefarah come up alongside kislyuk yq. They are separate projects with the same name and different approaches.

Mikefarah/yq is a Go binary that implements its own YAML query language, so it does not need jq installed and does not transcode through JSON. Kislyuk/yq is a Python wrapper that delegates all query semantics to jq. The difference in approach matters in three places. First, installation: the Python version needs both pip install yq and a separate jq binary, while a Go binary is typically a single download. Second, the filter language: with kislyuk/yq you write jq, which means the jq manual is your reference and every jq idiom transfers. Third, roundtrip fidelity: kislyuk/yq's -Y carries metadata through JSON to restore tags and styles, which is an unusual design and the source of the filter-compatibility warning above.

If you already have jq filters in scripts and CI, the wrapper is the smaller migration. If you want one binary and no Python runtime, or you want YAML-native operations without a JSON intermediate, the Go implementation is the more direct fit. The related searches also surface Yq strenv, a jq environment-variable function; that is a jq feature reached through the wrapper, not something yq defines.

Maintenance, licence and the cost of upgrading

The repository is not archived, and the last push was on 2026-09-19, the same day as the v4.2.0 release. That is a recent push, so the project is being maintained at the time of writing. Releases in the log are v4.2.0, v4.1.2 and v4.1.1, spaced across July and September 2026.

Upgrade cost is mostly the jq dependency, not the Python package. Because yq forwards arguments to jq and returns jq's exit code, the behaviour of your filters is tied to whichever jq version is installed on the machine. A CI image that bumps jq independently of yq can change filter results without any change to yq itself. Pinning both is the safer arrangement, though the README does not document a version constraint on jq.

On Python versions, pyproject.toml declares requires-python >= 3.8 and classifies support through 3.13, on both CPython and PyPy. Runtime dependencies are PyYAML >= 5.3.1, xmltodict >= 0.11.0, tomlkit >= 0.11.6 and argcomplete >= 1.8.1. The licence is Apache-2.0, both in the repository and in the pyproject.toml metadata. Apache-2.0 is permissive and includes an explicit patent grant, which is a different posture from a copyleft licence. It also carries notice and attribution obligations; if you redistribute yq inside a product, read the LICENSE file rather than relying on a summary. Nothing here is legal advice.

Choosing between -y, -Y and -F

Three output modes cover most real work, and picking the wrong one is the most common way to lose data.

Use -y when you want YAML out and do not care about custom tags, comment placement or block-scalar styles. It is the fast path, and it is what you want for generating fresh YAML from JSON or from a query result.

Use -Y when the document carries custom tags or styles that must survive the trip. CloudFormation templates are the README's example: !Ref, !GetAZs and folded scalars all come back intact. Accept the cost that your jq filter now sees injected metadata, and test the filter against a real document before putting it in a pipeline.

Use -F when the YAML is a frontmatter header in front of Markdown or other text. The README gives two forms, one writing to stdout and one editing several files in place:

bash
yq -Y --yaml-frontmatter '.draft = false' post.md
yq -iYF '.draft = false' post.md another-post.md

Note the constraint: without --in-place, each invocation takes one input file. And the -f flag still means jq's --from-file, so it is not a frontmatter shorthand. For plain queries where you only want the JSON result, the README notes you can drop -y and -Y entirely, as in yq -F .title post.md.

Editorial conclusion

Adopt kislyuk/yq if you already write jq filters and want them to work on YAML, XML or TOML without learning a second query language, and if you can install both the Python package and the jq binary. Do not adopt it for comment-preserving edits to ordinary YAML files, or if you need a single self-contained binary with no Python runtime: -Y only roundtrips tags and styles, and comments fail on scalar-rooted documents. Before committing, verify that jq is on PATH, that your filter survives -Y's injected metadata, and that --yaml-frontmatter handles one file per invocation unless you pass --in-place.

Frequently asked questions

What does the yq command do?

It takes YAML input, converts it to JSON, and pipes that JSON to jq. By default the jq output is printed as JSON; use -y to convert it back to YAML. The same package also installs xq for XML and tomlq for TOML.

What is the difference between jq and yq?

jq processes JSON and is a separate binary. yq is a wrapper that transcodes YAML, XML or TOML into JSON, delegates the query to jq, and optionally converts the result back. yq forwards its arguments to jq and returns jq's exit code unless YAML parsing failed.

How do I install yq on RHEL?

The README gives pip install yq as the installation command and states that you also have to install jq as a dependency, pointing to the jq installation instructions for platform-specific directions. It does not document an RHEL-specific package, so the Python package plus a separately installed jq binary is the path the documentation supports.

How do I validate a YAML file in yq?

The README does not describe a validation mode or a schema check. Running a filter such as yq . file.yml does force the input through YAML parsing, and a parsing error makes yq exit with code 1, but that only confirms the document parses, not that it is semantically correct.

Official sources

  1. kislyuk/yq on GitHub
  2. License: Apache-2.0
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/kislyuk-yq.svg)](https://hysenlabs.com/projects/kislyuk-yq)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/kislyuk-yq.svg)](https://hysenlabs.com/projects/kislyuk-yq)

Was this useful?