Parse yaml files with variables.
Project description
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.
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
Built Distribution
Hashes for yaml_replace-1.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c5823208ccf1611ad91fedee81cc247b25f6e4082b3950611d7583908d00b37 |
|
MD5 | 2655824d90cbadecc05dadb5e3089d2c |
|
BLAKE2b-256 | e8a80516f02d06d0e1efde7294199f7a89079629935339dba1991c72a06ce4a5 |