A powerful template engine with Python expression evaluation
Project description
Xylo
A powerful template engine with Python expression evaluation.
Installation
pip install xylo.py
Usage
from xylo import xylo
# Basic expressions
xylo("text $(1 + 5)") # "text 6"
# Variables via context
xylo("Hello $(name)!", {"name": "World"}) # "Hello World!"
# Conditionals
xylo("$if(x > 5) Big $else Small $end", {"x": 10}) # " Big "
# Loops
xylo("$for(i in range(3)) $(i) $end") # " 0 1 2 "
# Functions
xylo('$function(greet, name) Hello, $(name)! $end $call(greet, "World")') # " Hello, World! "
Features
- Expressions:
$(expression)- Evaluate and insert Python expressions - Exec:
$exec(code)- Execute Python code without output - Conditionals:
$if(cond) ... $elif(cond) ... $else ... $end - Loops:
$for(var in iterable) ... $end,$while(cond) ... $end - Functions:
$function(name, args) ... $endand$call(name, args) - Include:
$include("file.sdf", key=value, ...)- Include and render another template - Import:
$import("file.sdf", key=value, ...)- Import and render another template without the current context - Switch:
$switch(expr) $case(val) ... $default ... $end - Error handling:
$try ... $catch(e) ... $end,$raise(msg),$assert(cond) - Context managers:
$with(expr as var) ... $end - Control flow:
$break,$continue,$return
License
MIT
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
xylo_py-0.1.9.tar.gz
(13.3 kB
view details)
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 xylo_py-0.1.9.tar.gz.
File metadata
- Download URL: xylo_py-0.1.9.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
457c74116c1c8b5a34b71947a3bbc3c02b0cc6f1e6d23f766a338923d88855e9
|
|
| MD5 |
4b8a4a295530d064545069e213f41451
|
|
| BLAKE2b-256 |
e4e875bb89513ac7416bcc7eae4aa9561e85e8c56399bd277d851d5f1501c4c5
|
File details
Details for the file xylo_py-0.1.9-py3-none-any.whl.
File metadata
- Download URL: xylo_py-0.1.9-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c3c1c9ba37d7f05977c47f9a782d799b42697206dec1cd4b14696eaacda5ee5
|
|
| MD5 |
d091460ddbc0cfb220a2c429cc4e3f8c
|
|
| BLAKE2b-256 |
90be77b5cc445ce2e9d86a529d19a20c068219e3a19ac4ebe0f44f50eb23a77c
|