Skip to main content

A package for enhancing YAML processing with various features.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yaml-transformer-0.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yaml_transformer-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file yaml-transformer-0.1.0.tar.gz.

File metadata

  • Download URL: yaml-transformer-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for yaml-transformer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9f6e8d98b1cd32c18240ff65f832cf380bf6934debd7f60a5b10e6005970f530
MD5 ed36fbe903a4c11880d932658fd7bf74
BLAKE2b-256 5bf860a4069a3d2d2b9ebea2da6721b2d186b2a3ae197c1bdd8aecb7d6797592

See more details on using hashes here.

File details

Details for the file yaml_transformer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for yaml_transformer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6fc111b266c424c53e92fd47b26e8c458ea30324f419f5e19b6e6cbf1e37b99
MD5 2a8363d476951dd1d66e8ba7b49dbc8d
BLAKE2b-256 a3505fda9a09713079ac2e8165952fcf8c5e0415090a65ace6136c0d1e047f13

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page