Project with extended YAML functionality.
Project description
Yaml Tag Extensions
Quick Guide
pip install YamlTagExtensions
Tags supported
!VARIABLE
# variables.yaml
country: Atlantis
name: Jane Doe
# deployment.yaml
conn_string: my_amazing_conn_string_xxxxxxxxxxxxxx
Use the tag to initialize settings / variables that needs to be accessed in the yaml.
The !variable / !VARIABLE / !Variable can be invoked as follows.
This approach requires to end the document using ---
Use yaml.load_all feature if this approach is chosen.
!VARIABLES
- '../test/resources/variable_loader/deployment.yaml'
- '../test/resources/variable_loader/variables.yaml'
---
person:
name: Jane Doe
country: !$ '.variables.country'
Assign a key before defining the !Variables.
Ending the document is not necessary, and yaml.load can be used.
setup: !VARIABLES
- '../test/resources/variable_loader/deployment.yaml'
- '../test/resources/variable_loader/variables.yaml'
!$
Use this tag to access the !Variables set into the loader context.
To access country
value from variables.yaml
person:
name: Jane Doe
country: !$ '.variables.country' # .<file_name>.<attribute>
Also allows fetching of nested values / attributes.
Env variables can also be accessed using !$
detected by the presence of .env
prefix in the fetch string.
database: !$ '.env.DATABASE_NAME' # .env.<attribute>
!FILE
Read a file and attach it as verbatim to a desired YAML location.
The read uses smart-open pkg for type resolution.
my_file_contents: !FILE
path: resources/file_loader/sample_file.txt
!TEMPLATE
Leverage the power of templating with Jinja2 + YAML.
Create a Jinja2 template / Yaml with Jinja2 syntax's, to create reusable configurations that render a YAML dynamically.
simple_job:
database_name: DB
table_name: person
sql:
- !TEMPLATE
path: "resources/j2_loader/insert_into_template.j2"
params:
name: John Doe
age: 30
country: Wakanda
- !Template
path: "resources/j2_loader/insert_into_template.j2"
params:
name: !$ '.variables.name'
age: 28
country: !$ '.variables.country'
# insert_into_template.j2
insert_into:
name: {{ name | upper }}
age: {{ age }}
country: {{ country }}
Rendered YAML
simple_job:
database_name: DB
table_name: person
sql:
- insert_into:
age: 30
country: Wakanda
name: JOHN DOE
- insert_into:
age: 28
country: Atlantis
name: JANE DOE
Initialize and load yaml using YTE
import yaml
from YamlTagExtensions.core import yte_loader
yaml.load_all(
open('<PATH TO THE YAML FILE>'),
Loader=yte_loader
)
import yaml
from YamlTagExtensions.core import yte_loader
yaml.load(
open('<PATH TO THE YAML FILE>'),
Loader=yte_loader
)
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file yaml-tag-extension-0.0.3.tar.gz
.
File metadata
- Download URL: yaml-tag-extension-0.0.3.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95dfc75e6bc7f2c314a2ad62ab9ec29be90c6213b8d7f0454b424520827f3a1c |
|
MD5 | 07d0bd7cff1a02db3e03a0b3b2d22410 |
|
BLAKE2b-256 | 4dbcf2c5d62ce0fdcff941cabe870c5ac8eb1819bfadaba1f2cdc17245c35381 |
File details
Details for the file yaml_tag_extension-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: yaml_tag_extension-0.0.3-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6e39ea514e6d465e9d6685924eb90e0165ab572e4ca155ef84978430f3f722e |
|
MD5 | 737cae89de4d2b84ffd10ea69f775e4b |
|
BLAKE2b-256 | 1c0fc3453b2bb56c4ef2ffe06bbc618b0c65af62424d9599e7e711aa76b80d1d |