Skip to main content

A lightweight Python template engine

Project description

Blockie - Lightweight Python template engine

Introduction

Blockie is a lightweight, fast, universal and easy to use low-level Python-based template engine. It was developed as an expandable solution with uncluttered templates for the generation of any type of text-based content, including a standard text, markup language, source code, and various data files.

Blockie uses simple logicless templates consisting of two types of elements: variables and blocks. In most cases, the logic of filling the template can be driven by the input data structure and values. No custom script-like statements are needed. However, an additional logic can be implemented directly in the Python script running the template filling process.

Please read the full documentation here.

Installation

The Blockie package can be installed from the Python Package Index using the pip console command:

> pip install blockie

Quick start

The content generation follows the sequence below:

template + input data -> Python filling script -> generated content

In the simplest form, the user-defined Python filling script can be a set of just three commands illustrated in the example below that shows the most important principles of the data-driven template filling used by Blockie for the input data provided in form of an appropriately structured Python dictionary or a struct-like object.

import blockie

template = """
                SHOPPING LIST
  Items                             Quantity
--------------------------------------------
<ITEMS>
* <ITEM><+>                         <QTY><UNIT> kg<^UNIT> l</UNIT>
</ITEMS>

Short list: <ITEMS><ITEM><.>, <^.></.></ITEMS>
"""

data = {
    "items": [
        {"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},
    ]
}

# User-defined template filling script:
blk = blockie.Block(template)   # 1. Create the primary block and load its template.
blk.fill(data)                  # 2. Fill the template blocks and variables with data values.
print(blk.content)              # 3. Get the generated content from the primary block.

Output:

                SHOPPING LIST
  Items                             Quantity
--------------------------------------------
* potatoes                          2 kg
* rice                              1 kg
* orange juice                      1 l
* cooking magazine

Short list: potatoes, rice, orange juice, cooking magazine

Any required additional template filling logic can be implemented within the Python script either by restructuring the original input data and/or using the low-level manual filling functions provided by the Blockie module to precisely control the content generation. The script can also configure a different format of template tags.

License

Blockie - Lightweight Python template engine.

Copyright (C) 2025 Lubomir Milko This file is part of blockie https://github.com/lubomilko/blockie.

No generative artificial intelligence (AI) was used in the development process.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

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

blockie-2.0.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

blockie-2.0.0-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file blockie-2.0.0.tar.gz.

File metadata

  • Download URL: blockie-2.0.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for blockie-2.0.0.tar.gz
Algorithm Hash digest
SHA256 404745a5f08896f2054aa6e9bae21b76beac6440046cf8f8dee05e0fe0c3e9b3
MD5 1596f413bcb87368680b87d3f3844090
BLAKE2b-256 36661820c9710d2935a62965d3b6be4fb4b2cf69452046f838bca7499da35ce5

See more details on using hashes here.

File details

Details for the file blockie-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: blockie-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for blockie-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc3e6711138b2e38ec6e49e9e04eb5e0389609bf2cfc60dae838fe457c5427f7
MD5 1a05131b3c33502e3bcbd6eb50e31fc0
BLAKE2b-256 672f915968e911516bb2cf9e02fe0f4dfeba585f5e491003c266553edaf443be

See more details on using hashes here.

Supported by

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