A lightweight Python templating engine for CHTML files with includes and variable substitution support.
Project description
Cleature
A lightweight, fast templating engine for .chtml files, with variable injection, file includes, and a clean CLI. Designed for making static site generation easy with partitions and variables.
Table of Contents
- What is Cleature?
- Installation
- CLI Usage
- Module Usage
- Notes
- Configuration File
- Cleature Syntax
- Option Key Mapping
- About Cleature
- About the Author
What is Cleature?
Cleature is a static templating engine for .chtml files that supports:
- Variable substitution, with different scopes –
{{ variable }} - Constants block that override global variables –
<constants(...) /> - File includes to include
.chtmland.htmlfiles –<include("partials/footer.chtml") /> - Clean CLI with custom configurations –
cleature render srcdir distdir [options] - Set custom configurations with
cleature.config.jsonfile. - Usable as a CLI tool, or directly in Python code for versatility.
Use Cleature to build modular, maintainable, and portable static HTML projects with zero runtime dependencies.
Installation
You can install Cleature just by running this command:
pip install cleature
You can check the version by running:
cleature --version
CLI Usage
Cleature provides a clean CLI powered by Python's argparse:
cleature render <srcdir> <distdir> [options]
Here,
<srcdir>should be the source directory in which there are.chtmlfiles.<distdir>should be the output directory, where the parsed files and folders will be kept.
<srcdir> and <distdir> can be anywhere on the disk and don't need to be near each other.
Options
-
--refresh: Clear the output (distdir) before rendering. -
--exclude <dir1> <dir2> ...: Skip one or more directories inside srcdir. -
--debug: Enable debug logs. -
--variables a=x b=y ...: Modify or add variables inkey=valuepairs that will be substituted.
Example
Here is a simple example of using Cleature:
cleature render ./src ./out --refresh --exclude temp drafts --debug --variables sitename=Foo author=Bar
This will:
- Render all
.chtmlfiles from./src - Save output HTML to
./out - Skip
tempanddraftsdirectories and the files inside it. - Clean the output folder first.
- Enable debug logging.
Module Usage
Cleature can also be used as a regular Python module:
from cleature.core import render
from pathlib import Path
render(
src_directory=Path("src"),
dist_directory=Path("dist"),
provided_options={
"refresh_dist": True,
"excluded_dirs": ["drafts", "temp"],
"debug": True,
"variables": {
"title": "Hello from Python!"
}
}
)
Perfect for use in:
- Web backends
- Build pipelines
- CI/CD workflows
- Custom automation scripts
Notes
- Only
<srcdir>and<distdir>are required, and the options are optional. - The recommended way to provide the options is via the
cleature.config.jsonfile. - The options provided via the
cleature.config.jsonfile, have less priority than the options provided via the CLI or Python module. - The options key (or names) are different and simple in case of CLI, but same for the
cleature.config.jsonfile and module options. - All the paths (except the
<distdir>that is, the output directory) is always relative to the<srcdir>that is, the source directory.
Configuration File
The recommended way to provide the options is through the cleature.config.json file. It should be kept at the root of the SRC directory, so that it can be detected.
{
"variables": {
"title": "Website Title",
"author": "John Doe",
"year": "2025"
},
"excluded_dirs": ["components/"]
}
The options are the same, as when programmatically using the module. Cleature will automatically detect and merge this config.
Cleature Syntax
The .chtml files should follow this syntax, to be properly processed. The syntax is fully common HTML, as long as not any specific Cleature feature is needed.
But, for variables substitution, and includes, this is how the syntax looks:
File Inclusion
To include a file, this line should be placed, where another file needs to be included. <include(path/to/file.chtml)/>
Variable Substitution
We can set variables, using the options in CLI, module or cleature.config.json.
Use variables by placing them wherever needed, and they’ll be automatically substituted:
{{ variable_name }}
Constants
You can also set file-level variables using the <constants(...) /> block.
These are shared by the file in which they are defined, and any files included by that file.
Place them at the top of the file like this:
<constants(
"page_title":"Home",
"name": "Homepage"
)/>
This block also overrides the variables set by the options, but only for the file in which it is defined.
Syntax Example
If this is the content of index.chtml:
<constants(
"user": "John Doe"
)/>
<include(greet.chtml)/>
<p>You are welcome to {{ site_name }}.</p>
And this is the content of greet.chtml:
<h1>Hello, {{ user }}!</h1>
And if site_name variable is set as MySite in the options, then the output index.html would be like this:
<h1>Hello, John Doe!</h1>
<p>You are welcome to MySite.</p>
Here, in the example above,
In index.chtml:
<constants(...) />is used to define file level variables.<include(greet.chtml)/>is used to include thegreet.chtmlfile, and evaluate it.{{ site_name }}will be evaluated to the variable namedsite_namefrom the variable list. (Here, we have assumed we providedsite_namein options during rendering. Also, we could have usedcleature.config.json)
In greet.chtml:
{{ user }}will be evaluated to the value ofuserset in theindex.chtml(i.e., the file in which this was included. This happens because file-level variables are shared by the includes.)
Option Key Mapping
The keys of some options are different in CLI from its config/module key, for simplicity purposes. Both serve the same purpose. Both version of keys are shown below:
| CLI Option | Config/Module Key |
|---|---|
| --refresh | refresh_dist |
| --exclude | excluded_dirs |
| --variables | variables |
| --debug | debug |
About Cleature
Cleature requires Python 3.7 and above. It doesn't need any external dependencies, or packages.
Cleature comes under MIT License — Use freely, modify, and distribute with credit.
About the Author
Hey, I'm CodemasterUnited, the author of this library. I got the idea of making Cleature when I was writing the docs for ArtenoMark, which is my image watermarking API. I was struggling with the changes I had to make to all the files, just for a little theme-level change, which was very inefficient. Also, I didn't find any other simple and lightweight library that could help me in generating simple static sites. Either they were too advanced, or I didn't like their syntax.
So, I decided to make my own simple templating engine — Cleature. Cleature may not be too advanced yet, but it fulfills the task I made it for. If there is someone like me, who also had to struggle with not finding a simple templating engine, they should check out Cleature.
If anyone is interested in contributing to Cleature, they are most welcome. But still, I won't force anyone to use Cleature, or contribute to it. If you need it, use it. If you don't, then don't. 😁
Finally, happy coding! 🎉
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 cleature-0.1.0.tar.gz.
File metadata
- Download URL: cleature-0.1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba07ab115d76d16c507de3b6953e19e2610fef6c6b47931a3ce2ded9ef2052f6
|
|
| MD5 |
a4c8f7c9f78bbebebe025af5533a54ae
|
|
| BLAKE2b-256 |
942eb5db604c35a30b6fe819e1154d2a709241a4d6e0a16edd786465a69269a4
|
File details
Details for the file cleature-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cleature-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd8470994dc7700b70efc6cab7b3ae80f7f5b6ff9a7ee1e2375f7c18011b8b33
|
|
| MD5 |
95a8f3bbb32b7fb78aebe07a34f90bee
|
|
| BLAKE2b-256 |
829c3d342b1bb08abe3b4fd105e864b5e1a8aaf066ec5689e10f70c78eafee56
|