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.3.tar.gz
(11.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.3.tar.gz.
File metadata
- Download URL: xylo_py-0.1.3.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce176f6afef7f0da1b87811fa5e4eb4b18c7d5d583deafc56c826d267c470cfe
|
|
| MD5 |
bc5f4f6de714236e6afdf6b905e9b7b4
|
|
| BLAKE2b-256 |
1507b457998dccd4c1c39c840e3480962dc99a90fed5908a67e888da21c5fe55
|
File details
Details for the file xylo_py-0.1.3-py3-none-any.whl.
File metadata
- Download URL: xylo_py-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b02d4fd740b7858f1e1e8df2cb5ad7b8f8bd6c5cef866d2b64bbb751a314dd87
|
|
| MD5 |
9fae1211dacc53175681731bad451816
|
|
| BLAKE2b-256 |
5c399891aea721ba3d4f37280bb80b438c6d30a2b62bf8279fd47dfc9214f421
|