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-1.0.0.tar.gz
(4.4 kB
view hashes)
Built Distribution
Close
Hashes for yaml_patch-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48048aa75dbddbee8995848ed03e89f8ae746d545613687a34e9cc549a5520c8 |
|
MD5 | 71539bfdcb7051519217c36562e18134 |
|
BLAKE2b-256 | 6c7a577e96ff19ce7fd2c07ba223d41e96fcceb51917971eefeab1d8fa99f27f |