Skip to main content

Patch yaml strings

Project description

yaml-patch

Apply patches to a yaml string, keeping most of the formatting and comments.

Some formatting is not kept due to underlying yaml library limitations:

  • Indentation will be forced to two spaces
  • Spacing before sequence dashes will be forced to two spaces
  • Empty lines at the start of the string will be removed

As a command line tool

You can pass any number of patches to be applied, they use the following syntax options:

Patch a single value:

<field>.<subfield>=<value>

Example:

yaml-patch -f test.yml  'spec.replicas=2'

Patch a value inside a single list item:

<field>.[<position]>.<subfield>=<value>

Example:

yaml-patch -f test.yml  'spec.template.containers.[0].image="mycontainer:latest"'

Patch a value inside all list items:

<field>.[].<subfield>=<value>

Example:

yaml-patch -f test.yml 'spec.template.containers.[].image="mycontainer:latest"'

As a Python library

To use yaml-patch as a library just import the function and pass patches as dictionary entries.

Example:

from yaml_patch import patch
from textwrap import dedent

def override_list_all_values():
    source_yaml = dedent(
        """\
        some_list:
          - alice
          - bob
        """
    )
    patches = {"some_list.[]": "charlie"}
    expected_yaml = dedent(
        """\
        some_list:
          - charlie
          - charlie
        """
    )
    assert patch(source_yaml, patches) == expected_yaml

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-patch-0.1.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

yaml_patch-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file yaml-patch-0.1.1.tar.gz.

File metadata

  • Download URL: yaml-patch-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.9.6 Linux/5.11.0-27-generic

File hashes

Hashes for yaml-patch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0ea343dbf464555bed3a2363f35c180f276e8c419178ac0c5c3703b28873a921
MD5 2607948b715b5642cb35e3278fe0ccee
BLAKE2b-256 70bce1cd28907c4ae7caecc8bf9095c48d31e8bd0701b32a6a13f23b47d7283b

See more details on using hashes here.

File details

Details for the file yaml_patch-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: yaml_patch-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.9.6 Linux/5.11.0-27-generic

File hashes

Hashes for yaml_patch-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fd6cf5f893346424fc5ef3312e0b4bb8af785cc4b8a36660d795af84c983f2e8
MD5 7ec089fd34b08d4160996bb4fc2d84fe
BLAKE2b-256 a6d3c522ca58845b5c36b914fedb8fca1439eb65b79dfea322d96a841dcd9663

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