Skip to main content

yaml_pipe

CLI utility for extracting YAML or JSON data. GitHub Repo

Overview

You can use YAML_Pipe as a CLI utility to access and/or search for the key of specific data nodes in a YAML or JSON file. This may help with data processing by not requiring you to, first, manually open and literally read the data file, then then write code in your program to access certain keys to extract the data, and then run your program. YAML_Pipe let's you grab the data, and then pipe it as input to another CLI tool or write it to a new file. It does not modify the original file.

Features

gif demonstrating autocomplete

Usage:

$ yaml_pipe [-h/--help] [-q/--quiet]
<file> <enumerate, yaml, or json> <keys...>
[--search <key>] [--type <int, float, bool, bin, null, or timestamp>]

'yaml_pipe' takes three positional arguments, and four options. Provides autocomplete and abbreviation.

  • HELP: [-h/--help] Usual help option.
  • QUIET: [-q/--quiet] Option to turn off success messages printed to stderr.
  • FILE: [file] Must include path to data file to parse as YAML (JSON is a subset of YAML).
  • COMMAND: <enumerate, yaml, or json> Must select one of three commands:
    • ENUMERATE: Print the nodes at the current level. No nesting. Index sequences.
    • YAML: Output YAML data.
    • JSON: Output JSON string.
  • KEYS: <keys ...> Optionally provide keys and/or indices as extra args to access nested nodes. Tab for autocomplete to list keys and indices.
  • SEARCH: [--search <key>] Optionally search for a key. Must match exactly. Default data type is a string.
  • TYPE: [--type <data_type>] Optionally select the data type of search keys that are not strings. Each choice correlates with a YAML data tag. Is an option for the search option.

NOTE: To ensure autocomplete with argcomplete works as intended, follow the order of arguments found here: $ yaml_pipe -q file command keys... --search key --type data_type

Download/Install

From source:

  1. Clone the repo:
$ git clone https://github.com/skovranek/yaml_pipe
  1. Change directories to the new 'yaml_pipe directory/', then run:
$ python3 -m pip install -e .
$ eval "$(register-python-argcomplete3 yaml_pipe)"

From PyPI:

$ pip install pipeyaml

NOTE: YAML_Pipe is published on PyPI as 'pipeyaml', not 'yaml_pipe' or 'yamlpipe'.

Implement Library

There are a few different functions from this project you may want to import.

access_keys(node: Any, keys: List[str]) -> Any, bool:

Attempt to access value in a series of nested dicts and lists via list of keys and indices as strings. True/False for exists/not exists.

key_search(node: Any, key: str) -> Any, List[Any], bool:

Attempt to find dict key in series of nested dicts and lists. Returned list is path of keys or indices to access value. True/False for found/not found.

print_keys(node: Any):

Prints the first layer of nodes. Keys are listed. Sequences are indexed. Nested values are printed inline flow style.

View the main function of Yaml_Pip for an example of how these functions are used.

Dependencies

The main dependencies of YAML_Pipe are ruamel.yaml to parse YAML and JSON, argparse to parse CLI args, and argcomplete to autocomplete arguments and options.

View the requirements.txt file for the entire list of dependencies.

Testing

Manually tested with a zsh shell in the macOS terminal.

Contact

Questions, issues or suggestions: mattjskov at gmail.com

Contribute

Anyone is welcome to submit pull requests to the main branch.

Metadata

Release files for pipeyaml 0.1.1

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

Source distribution (sdist)

Source distribution for pipeyaml 0.1.1
File Size Uploaded Provenance Actions
pipeyaml-0.1.1.tar.gz 15.6 kB Without provenance Details for pipeyaml-0.1.1.tar.gz

Release files / pipeyaml-0.1.1.tar.gz

Download URL pipeyaml-0.1.1.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dd9b24ba6688e8341d018dd85f35ad9a63a239cc88c003d1aa955d55dc25acbd
BLAKE2b-256 checksum
How to use checksums
625519f7b590aeeb7bf7d2a3d68e2ae856f01f57e2a7cbe67181595eed8b8952
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Security for pipeyaml 0.1.1

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.1.1 This release

1 release file 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