yaml-replace
Parse yaml files with variables. You can substitute variables in yaml files with values you want to inject.
Installation
pip install yaml-replace
Usage & Examples
You can specify a variable in yaml file with ${{ variable_name }} and then replace it with a value you want to inject.
For example, let's say you have a yaml file some-yaml-file.yaml with the following content:
# some-yaml-file.yaml
name: GitHub Copilot
description: AI Programming Assistant
version: ${{ version }}
features:
- name: code generation
languages_supported: ${{ languages }}
In your python code, you can use yaml-replace to replace the variables in the yaml file with the values you want to inject:
from yaml_replace import YAMLTemplate
YAMLTemplate.from_file('some-yaml-file.yaml').render(
{
'version': '1.0.0',
'languages': ["Python", "JavaScript", "Java", "C++", "C#"],
}
)
The code above will output:
{
'name': 'GitHub Copilot',
'description': 'AI Programming Assistant',
'version': '1.0.0',
'features': [
{
'name': 'code generation',
'languages_supported': ['Python', 'JavaScript', 'Java', 'C++', 'C#']
}
]
}
You can also use YAMLTemplate to load the yaml content from a string:
yaml_content = """
name: GitHub Copilot
description: AI Programming Assistant
version: ${{ version }}
features:
- name: code generation
languages_supported: ${{ languages }}
"""
YAMLTemplate(yaml_content).render(
{
'version': '1.0.0',
'languages': ["Python", "JavaScript", "Java", "C++", "C#"],
}
) # Output is the same as the previous example
Contributing
Any contribution is welcome! Check out CONTRIBUTING.md and CODE_OF_CONDUCT.md for more information on how to get started.
License
yaml-replace is licensed under a MIT License.
Metadata
Release files for yaml-replace 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| yaml_replace-1.1.2.tar.gz | 3.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| yaml_replace-1.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.2 kB
Release files / yaml_replace-1.1.2.tar.gz
| Download URL | yaml_replace-1.1.2.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67ef8b03dcd56bb0eac0d11852ca580d6facf12f012cb62b1b9d5f2c0c5c27eb
|
|
BLAKE2b-256 checksum How to use checksums |
62bde217b794596df93577812f5bff0db297c228d281741c2549a5df6f05c4cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1015-azure
|
Release files / yaml_replace-1.1.2-py3-none-any.whl
| Download URL | yaml_replace-1.1.2-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c5823208ccf1611ad91fedee81cc247b25f6e4082b3950611d7583908d00b37
|
|
BLAKE2b-256 checksum How to use checksums |
e8a80516f02d06d0e1efde7294199f7a89079629935339dba1991c72a06ce4a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1015-azure
|