Skip to main content

YAML glue for structural templating and processing

Project description

Build Status PyPI version

Yglu ᕄ

Yglu is YAML enriched with an advanced expression language. Unlike usual text templating, Yglu relies on the YAML structure and leverages its typing features combined with the YAQL query language.

This association enables templating and functional processing a bit like if YAML nodes where spreadsheet cells.

Yglu input documents are pure YAML using tags for computed nodes.

input
a: 1
b: !? .a + 1  
output
a: 1
b: 2  
input
tags: !-
  - 'nginx:1.16'
  - 'node:13.6'
  - 'couchbase:9.3'
image: !()
  !? $.split(':')[0]: 
    version: !? $.split(':')[1]
images: !? 
  $_.tags
    .select(($_.image)($))
    .aggregate($1.mergeWith($2), {})
output
images:
  nginx: 
    version: '1.16'
  node: 
    version: '13.6'
  couchbase: 
    version: '9.3'
     
     
     
       

In the example above, the tags sequence is hidden, image is a function (like a template block) and images is an expression which iterates through all tags, apply the image function to them and aggregate the individual results by merging them together as a mapping.

See the test samples for more examples.

Install

pip install yglu

Run

Usage: yglu [options] [<filename>]

Options:
  -v - -version          Print version and exit.
  -h - -help             Print help and exit.

Tags

Tags specify an alteration of the document structure.

Tag    Description
!? Evaluate an expression. The result can be a scalar, mapping or sequence. Can also be used in mapping keys.
!- Hide the node in the output but keep it accessible from expressions. When used with a scalar, it evaluates it as an expression.
!() Make the node reusable in expressions as a function. It is also hidden.
!if Shortcut for conditional merge of mappings. See merge.yml.

Expressions

Expressions are written in YAQL.

They are evaluated in a context with the following predefined variables:

Variable Description
$_ Refers to the current document root. Can be omitted at the beginning of the expression if it starts with a dot.
$ Implicit argument of functions.
$env Gives access to environment variables. Disabled by default. Set the $YGLU_ENABLE_ENV environment variable to enable.

Built-in Functions

In addition to standard YAQL operators, Yglu defines the following functions:

Function Description
$import(filename) Imports another document in the current node.

Planned Features

  • Tag for merging mappings easily (e.g. conditionally)

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

yglu-0.10.0.tar.gz (6.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page