A lightweight Python template engine
Project description
Blockie Python template engine
Blockie is an extremely lightweight and simple universal Python-based template engine. It can generate various types of text-based content, e.g., standard text, source code, data files or markup language content like HTML, XML or markdown.
Blockie is aimed to be used in template-based projects that do not need templates containing complex custom commands or programming language parsers. Instead, Blockie uses only a few simple but extremely multipurpose principles and clean, logicless templates. If a more advanced template-filling logic is needed, then it is expected to be defined directly within the user-defined Python script, which avoids the need for a custom template language.
The block diagram below illustrates the fairly standard process of generating the content from a template using values defined in the input data:
+----------+ +------------+
| template | | input data |
+----------+ +------------+
| |
V V
+-----------------------+
| Python filling script |
| using blockie |
+-----------------------+
|
V
+-------------------+
| generated content |
+-------------------+
Please read the full documentation here.
Installation
The Blockie package can be installed from the Python Package Index using the following pip console command:
pip install blockie
Alternatively, it is also possible to install the Blockie package from a *.tar.gz source distribution that can be downloaded from the dist directory:
pip install blockie-<version>.tar.gz
Quick start
The following Python script serves as a simple illustration of all basic principles. The template
is loaded from the template string and filled using the data dictionary with the FLAG
variable in the template defined by the script since the Blockie templates are logicless. At the
end the generated content is printed out.
import blockie
template = """
SHOPPING LIST
Items Quantity
------------------------------------------------------------------------
<ITEMS>
* <FLAG>IMPORTANT! <^FLAG>MAYBE? </FLAG><ITEM><+> <QTY><UNIT> kg<^UNIT> l</UNIT>
</ITEMS>
Short list: <ITEMS><ITEM><.>, <^.></.></ITEMS>
"""
important_items = ("potatoes", "rice")
maybe_items = ("cooking magazine",)
data = {
"items": [
{"item": "apples", "qty": "1", "unit": 0},
{"item": "potatoes", "qty": "2", "unit": 0},
{"item": "rice", "qty": "1", "unit": 0},
{"item": "orange juice", "qty": "1", "unit": 1},
{"item": "cooking magazine", "qty": None, "unit": None}
]
}
for item in data["items"]:
item["flag"] = 0 if item["item"] in important_items else 1 if item["item"] in maybe_items else None
blk = blockie.Block(template)
blk.fill(data)
print(blk.content)
Prints the following generated content:
SHOPPING LIST
Items Quantity
------------------------------------------------------------------------
* apples 1 kg
* IMPORTANT! potatoes 2 kg
* IMPORTANT! rice 1 kg
* orange juice 1 l
* MAYBE? cooking magazine
Short list: apples, potatoes, rice, orange juice, cooking magazine
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 blockie-1.1.0.tar.gz.
File metadata
- Download URL: blockie-1.1.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
914ae4d358416fbf194d28874865f40a391129eb2abf652689c97c9b0b3efe3a
|
|
| MD5 |
808dce42b07a62b64100689017aa8aa9
|
|
| BLAKE2b-256 |
365ca98a6794cfa7f1b198968346f4329014d187830316009068c12febc18e5e
|
File details
Details for the file blockie-1.1.0-py3-none-any.whl.
File metadata
- Download URL: blockie-1.1.0-py3-none-any.whl
- Upload date:
- Size: 23.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d30b60198b4dfd03e570290c7c4445f5105780d825a56f03b47de4d828a8f1f
|
|
| MD5 |
4086df06ee66582825de908d3d3f4c81
|
|
| BLAKE2b-256 |
bc90eff62ef8d953c5af51d632fe4ebceacdcdfe8487e8d9892e0251bfdbab0c
|