Skip to main content

yaml-transformer

Introduction

yaml-transformer is a powerful Python package designed to enhance YAML processing capabilities. It introduces advanced features like including other YAML files, executing JSONPath queries, applying JQ queries, and flattening lists within YAML files.

Installation

To install yaml-transformer, run the following command:

pip install yaml-transformer

Features

  • !include: Include and merge other YAML files.
  • !jsonpath: Perform JSONPath queries on YAML nodes.
  • !jq: Apply JQ queries and modifications to YAML nodes.
  • !flatten: Flatten nested lists into a single list.

Usage

The yaml-transformer package enhances YAML processing with advanced features. Below are examples demonstrating its capabilities using a Transformers theme. These examples show how to include external YAML files, apply JSONPath queries, use JQ queries, and flatten lists, all within a YAML context.

Including External YAML Files

Autobots YAML (autobots.yaml):

- name: Optimus Prime
  role: Leader
- name: Bumblebee
  role: Scout

Decepticons YAML (decepticons.yaml):

- name: Megatron
  role: Leader
- name: Starscream
  role: Fighter

Leaders YAML (leaders.yaml):

autobots:
  - name: Optimus Prime
    role: Leader

Main YAML:

autobots: &autobots !include autobots.yaml
decepticons: &decepticons !include decepticons.yaml

In this setup, autobots.yaml and decepticons.yaml are included and referenced in the main YAML file using YAML anchors (&autobots and &decepticons).

Applying JQ Query

To find a specific Transformer leader (e.g., Optimus Prime) using JQ:

leaders: &leaders !include leaders.yaml
leader: !jq { object: *leaders, filter: '[.autobots[] | select(.name == "Optimus Prime")]' }

This JQ query selects "Optimus Prime" from the included leaders.yaml.

Combining JSONPath Queries with Flatten

Combining the names of all Transformers (both Autobots and Decepticons) into a single list:

all_names: !flatten
  - !jsonpath { object: *autobots, path: '$[*].name', all: true }
  - !jsonpath { object: *decepticons, path: '$[*].name', all: true }

Here, !jsonpath queries are used to extract the names of all Autobots and Decepticons, and !flatten combines these names into a single list.

Running Tests

To run tests, install the package with development dependencies:

pip install yaml-transformer[dev]

Then, execute the test suite using pytest:

pytest

Contributing

Contributions to yaml-transformer are welcome!

License

yaml-transformer is released under the MIT License.

Metadata

Release files for yaml-transformer 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 yaml-transformer 0.1.1
File Size Uploaded Provenance Actions
yaml-transformer-0.1.1.tar.gz 4.0 kB Without provenance Details for yaml-transformer-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for yaml-transformer 0.1.1
File Interpreter ABI Platform Actions
yaml_transformer-0.1.1-py3-none-any.whl Python 3 none any Details for yaml_transformer-0.1.1-py3-none-any.whl

Total release size: 8.6 kB

Release files / yaml-transformer-0.1.1.tar.gz

Download URL yaml-transformer-0.1.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1b474f0a85073c1636bd20abd3c2110c93b44eab9f4b1bf0c073a06034233327
BLAKE2b-256 checksum
How to use checksums
16ea5ebbff8ecb5136b3ca3a51493cfa2ffe056dcf57d3fbb0f6afdbe6996381
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / yaml_transformer-0.1.1-py3-none-any.whl

Download URL yaml_transformer-0.1.1-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c8579ef083257e0900353ea8362489ad89a5b8517614ee5a139bd7ff5593030
BLAKE2b-256 checksum
How to use checksums
2b29dd23fcfd6911dccb2b8fd15029e7e45c3887c4345e664b9a4645befbc5b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Security for yaml-transformer 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

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