JSON/YAML homoiconic templating language
Project description
JSON/YAML homoiconic templating language
python3 -m pip install jinsi
Usage via CLI
python3 -m jinsi - # read from stdin
python3 -m jinsi -j - # read from stdin, render as json
python3 -m jinsi file1.yaml file2.yaml
Examples
Cloudformation Template
YAML input:
::let:
user:
::object:
- ::titlecase:
::get: $user.username
- Type: AWS::IAM::User
Properties:
UserName:
::get: $user.username
Groups:
- Administrators
LoginProfile:
Password:
::get: $user.password
::else: default
PasswordResetRequired: Yes
users:
::merge:
::each $ as $user:
::call user:
Resources:
::call users:
- username: jim
password: one
- username: jack
password: two
- username: johnny
Rendered output:
Resources:
Jack:
Properties:
Groups:
- Administrators
LoginProfile:
Password: two
PasswordResetRequired: true
UserName: jack
Type: AWS::IAM::User
Jim:
Properties:
Groups:
- Administrators
LoginProfile:
Password: one
PasswordResetRequired: true
UserName: jim
Type: AWS::IAM::User
Johnny:
Properties:
Groups:
- Administrators
LoginProfile:
Password: default
PasswordResetRequired: true
UserName: johnny
Type: AWS::IAM::User
Fibonacci
This is just an example to show how complex a template can be. Also note: The fibonacci function is defined recursively. This would blow up and values upto 50 could not be computed. Since Jinsi is purely functional, functions are mappings and can be cached. This is why the computation returns quickly (at all).
python3 -m jinsi max=50 -
YAML input:
::let:
fib:
::when:
::get: $n == 0 or $n == 1
::then:
::get: $n
::else:
::add:
- ::call fib:
$n:
::get: $n - 1
- ::call fib:
$n:
::get: $n - 2
fibs:
::range_exclusive:
- 0
- ::get: $max
::else: 10
result:
::each fibs as $n:
::call: fib
Rendered output:
result:
- 0
- 1
- 1
- 2
- 3
- 5
- 8
- 13
- 21
- 34
- 55
- 89
- 144
- 233
- 377
- 610
- 987
- 1597
- 2584
- 4181
- 6765
- 10946
- 17711
- 28657
- 46368
- 75025
- 121393
- 196418
- 317811
- 514229
- 832040
- 1346269
- 2178309
- 3524578
- 5702887
- 9227465
- 14930352
- 24157817
- 39088169
- 63245986
- 102334155
- 165580141
- 267914296
- 433494437
- 701408733
- 1134903170
- 1836311903
- 2971215073
- 4807526976
- 7778742049
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
jinsi-0.12.0.tar.gz
(21.5 kB
view details)
Built Distribution
jinsi-0.12.0-py3-none-any.whl
(25.9 kB
view details)
File details
Details for the file jinsi-0.12.0.tar.gz
.
File metadata
- Download URL: jinsi-0.12.0.tar.gz
- Upload date:
- Size: 21.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 632065afb68de32a703314c9421fd4ef4094f34368662b138ce634bb06f015a1 |
|
MD5 | f4b994378e17ec19bc22c323e76ef17b |
|
BLAKE2b-256 | 4dc7213a582af005b7defb56d6268fe1bdfb69573eae6029d0b2334c1c19de67 |
File details
Details for the file jinsi-0.12.0-py3-none-any.whl
.
File metadata
- Download URL: jinsi-0.12.0-py3-none-any.whl
- Upload date:
- Size: 25.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6753a38a8dd237f972c2755fbbcedd8d60ae1a1349eae187f36296313099d8e5 |
|
MD5 | 94dfcd663a67b9e77b33c9c424a42d07 |
|
BLAKE2b-256 | c32b96ef7f8557fda9cc8ad52f37fb95aa496704fd721bfe85d6fd54a0908a33 |