Skip to main content

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.

Download files

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

Source Distribution

yaml_replace-1.1.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

yaml_replace-1.1.2-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file yaml_replace-1.1.2.tar.gz.

File metadata

  • Download URL: yaml_replace-1.1.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1015-azure

File hashes

Hashes for yaml_replace-1.1.2.tar.gz
Algorithm Hash digest
SHA256 67ef8b03dcd56bb0eac0d11852ca580d6facf12f012cb62b1b9d5f2c0c5c27eb
MD5 1064d6403fc5813f194650ce8af2c5f2
BLAKE2b-256 62bde217b794596df93577812f5bff0db297c228d281741c2549a5df6f05c4cb

See more details on using hashes here.

File details

Details for the file yaml_replace-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: yaml_replace-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1015-azure

File hashes

Hashes for yaml_replace-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8c5823208ccf1611ad91fedee81cc247b25f6e4082b3950611d7583908d00b37
MD5 2655824d90cbadecc05dadb5e3089d2c
BLAKE2b-256 e8a80516f02d06d0e1efde7294199f7a89079629935339dba1991c72a06ce4a5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.1.0

2 files

Supported by

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