Python command-line tool to generates text files based on Jinja2 template and YAML data file.
Project description
JINJACRAFT
JinjaCraft is a simple Python command-line tool which can generate text file based on a Jinja2 template and a YAML data file and event generate a base data file in Yaml format from a Jinja2 template.
Requirements
Python 3.9 or higher
Installation
Using pip:
pip install jinjacraft
Using pipx (recommended for CLI tools):
pipx install jinjacraft
Usage
usage: jinjacraft [-h] [-g TEMPLATE] [-f] [-o OUTPUT_FILE] [data_file] [template_file]
Generate text files from Jinja2 templates and YAML data
positional arguments:
data_file YAML data file path
template_file Jinja2 template file path
options:
-h, --help show this help message and exit
-g TEMPLATE, --generate-model TEMPLATE
Generate a model YAML file from a Jinja2 template
-f, --force Overwrite existing output file
-o OUTPUT_FILE, --output_file OUTPUT_FILE
Output file path
Features
Data Validation
JinjaCraft validates your YAML data against the template before rendering:
- Missing variables: If a variable is used in the template but not defined in the YAML file, an error is returned and rendering is aborted.
- Unused variables: If a variable is defined in the YAML file but not used in the template, a warning is displayed but rendering continues.
Model Generation
Generate a model YAML file from a Jinja2 template to see which variables are expected:
jinjacraft -g template.jinja2
This creates template.yaml with placeholders and type comments:
title: "<title>" # string
tasks: # list
- name: "<name>" # string
completed: "<completed>" # truthy value (boolean, string, number)
Use -o to specify a custom output file, and -f to overwrite an existing file:
jinjacraft -g template.jinja2 -o model.yaml -f
Example
YAML file
title: Hello World
tasks:
- name: First task
completed: True
- name: Second task
completed: False
Template file
Document: {{ title }}
Tasks:
{% for task in tasks %}- {{ task.name }} ({% if task.completed %}completed{% else %}not completed{% endif %})
{% endfor %}
Command line
jinjacraft data.yaml template.jinja2 -o outputfile.txt
Output file content
Document: Hello World
Tasks:
- First task (completed)
- Second task (not completed)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jinjacraft-1.5.0.tar.gz.
File metadata
- Download URL: jinjacraft-1.5.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
195051e6e9cdc326e24c165e13b7f0a1bb05e2cdf43a202c1cb160e6c28b8e9e
|
|
| MD5 |
e3ad969a0d11b74f0b285d9cbaae1892
|
|
| BLAKE2b-256 |
82f9475366b41ac4d6635c303362f1f19f6ca8c4a19604eb9bbf3153fc3071c6
|
Provenance
The following attestation bundles were made for jinjacraft-1.5.0.tar.gz:
Publisher:
release.yml on sdejongh/jinjacraft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jinjacraft-1.5.0.tar.gz -
Subject digest:
195051e6e9cdc326e24c165e13b7f0a1bb05e2cdf43a202c1cb160e6c28b8e9e - Sigstore transparency entry: 813663230
- Sigstore integration time:
-
Permalink:
sdejongh/jinjacraft@4f3a57d1953a11d1d6f2bc92ab24693cf8656960 -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/sdejongh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4f3a57d1953a11d1d6f2bc92ab24693cf8656960 -
Trigger Event:
push
-
Statement type:
File details
Details for the file jinjacraft-1.5.0-py3-none-any.whl.
File metadata
- Download URL: jinjacraft-1.5.0-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de500e0906e95a4d4ae7dd2f11d185c53f8169401e8450aa61d377eaff710af9
|
|
| MD5 |
59b77cac4a23a019f72b648b2103f7b2
|
|
| BLAKE2b-256 |
8b5a56e1d5b5090b58fa70fbd45eb074872749655ee791af017095a81cda722d
|
Provenance
The following attestation bundles were made for jinjacraft-1.5.0-py3-none-any.whl:
Publisher:
release.yml on sdejongh/jinjacraft
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jinjacraft-1.5.0-py3-none-any.whl -
Subject digest:
de500e0906e95a4d4ae7dd2f11d185c53f8169401e8450aa61d377eaff710af9 - Sigstore transparency entry: 813663232
- Sigstore integration time:
-
Permalink:
sdejongh/jinjacraft@4f3a57d1953a11d1d6f2bc92ab24693cf8656960 -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/sdejongh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4f3a57d1953a11d1d6f2bc92ab24693cf8656960 -
Trigger Event:
push
-
Statement type: