Skip to main content

Yet Another Expansion Syntax (pronounced ‘Yasssss Kweeeeen’) for expanding complex data (YAML / JSON) with Jinja2 templating

If a block has no control keywords, everything is emitted as is:

import yaes

block = {
    "ya": "{{ a }}"
}

values = {
    "a": "sure"
}

list(yaes.each(block, values))
# [
#     ({"ya": "{{ a }}"}, {"a": "sure"})
# ]

The behavior is the same if you send a list of blocks:

list(yaes.each([block], values))
# [
#     ({"ya": "{{ a }}"}, {"a": "sure"})
# ]

requires

If a requires keyword is present, all the keys listed must be in values for the block to emitted:

blocks = [
    {
        "name": "one",
        "requires": "a"
    },
    {
        "name": "twp",
        "requires": ["a", "b"]
    }
]

values = {
    "a": "sure"
}

list(yaes.each(blocks, values))
# [
#     ({"name": "one"}, {"a": "sure"})
# ]

This is useful for modules like opengui, where we don’t want to evaluate the conditions on some fields unless other fields in those conditions actually have values.

transpose

If a transpose keyword is present, it’ll use the key pairs to transpose the values:

blocks = [
    {
        "name": "one",
        "transpose": {
            "b": "a"
        }
    }
]

values = {
    "a": "sure"
}

list(yaes.each(blocks, values))
# [
#     ({"name": "one"}, {"a": "sure", "b": "sure"})
# ]

This is useful if you’re re-using a template that uses veriables and you want to replace them with your usage’s specific variables.

iterate

If a iterate keyword is present, it’ll use the key pairs to iterate new values:

blocks = [
    {
        "name": "{{ fruit }}",
        "iterate": {
            "fruit": "fruits"
        }
    }
]

values = {
    "fruits": [
        "apple",
        "pear",
        "orange"
    ]
}

list(yaes.each(blocks, values))
# [
#     (
#         {
#             "name": "{{ fruit }}"
#         },
#         {
#             "fruit": "apple",
#             "fruits": [
#                 "apple",
#                 "pear",
#                 "orange"
#             ]
#         }
#     ),
#     (
#         {
#             "name": "{{ fruit }}"
#         },
#         {
#             "fruit": "pear",
#             "fruits": [
#                 "apple",
#                 "pear",
#                 "orange"
#             ]
#         }
#     ),
#     (
#         {
#             "name": "{{ fruit }}"
#         },
#         {
#             "fruit": "orange",
#             "fruits": [
#                 "apple",
#                 "pear",
#                 "orange"
#             ]
#         }
#     )
# ]

This is useful with opengui as you can take the values of a multi option field and use those values to create a new field for each option selected.

condition

If a condition keyword is present, it’ll only emit the block if the condition evaluates True:

blocks = [
    {
        "name": "one",
        "condition": "{? a == 1 ?}"
    },
    {
        "name": "two",
        "condition": "{? a == 2 ?}"
    }
]

values = {
    "a": 1
}

list(yaes.each(blocks, values))
# [
#     ({"name": "one"}, {"a": 1})
# ]

This is useful if you only want to use a block under certain conditions.

blocks

If a blocks keyword is present, it’ll expand those blocks, using the parent block as a base:

blocks = [
    {
        "base": "value",
        "blocks": [
            {
                "name": "one"
            },
            {
                "name": "two",
                "base": "override"
            }
        ]
    }
]

values = {
    "a": 1
}

list(yaes.each(blocks, values))
# [
#     (
#         {
#             "base": "value",
#             "name": "one"
#         },
#         {
#             "a": 1
#         }
#     ),
#     (
#         {
#             "base": "override",
#             "name": "two"
#         },
#         {
#             "a": 1
#         }
#     )
# ]

This is useful if you have a condition or iterate that you want to apply to multiple block without having to use those keywords on each block.

values

If a values keyword is present, it’ll merge those values into teh values emitted:

blocks = [
    {
        "name": "one"
    },
    {
        "name": "two",
        "values": {
            "a": 2,
            "c": "{{ b }}sah"
        }
    }
]

values = {
    "a": 1,
    "b": "yes"
}

list(yaes.each(blocks, values))
# [
#     (
#         {
#             "name": "one"
#         },
#         {
#             "a": 1,
#             "b": "yes"
#         }
#     ),
#     (
#         {
#             "name": "two"
#         },
#         {
#             "a": 2,
#             "b": "yes",
#             "c": "yessah"
#         }
#     )
# ]

This is useful if you want to override the existing values but at this point I don’t think even I’ve ever used it.

Release files for yaes 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yaes 0.2.6
File Size Uploaded
yaes-0.2.6.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yaes 0.2.6
File Interpreter ABI Platform
yaes-0.2.6-py3-none-any.whl Python 3 none any Details

Total release size: 15.6 kB

Release files / yaes-0.2.6.tar.gz

Download URL yaes-0.2.6.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fc0055fdde960da6bf6f2f59d67b542dacf60b11a4d7dc0c059c394885fc46fb
BLAKE2b-256 checksum
How to use checksums
ee50af80d657ef2c1b4ab2bb8442874e82f14f16756efc00deb85bbf09c18fb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.5

Release files / yaes-0.2.6-py3-none-any.whl

Download URL yaes-0.2.6-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1885eb5f47c148c0a7c636de99a9b93425b860551e5710323e4518be167f295e
BLAKE2b-256 checksum
How to use checksums
7ab54a9d0884aed093af180a526ba4a068604bfd829a7cc7ad046bc24b4e7887
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.2.6 This release

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page