low-level python hacker and author of RPyC,Construct and Plumbum. writes
about python, algorithms,
software architecture and whatever else comes to mind.
Templite is a fast, light-weight, general purpose, and fully featured templating engine in ~40
lines of code. Unlike many templating engines, this one is not specific to any format (HTML, XML,
etc.). Instead, all the text surrounded by ${ and }$ is evaluated as python code.
Any python code can be used (import modules, define functions, etc.). In order to emit the rendered
text into the template, use the emit or emitf functions.
Security note: templating is mainly used in webservers. Having the template stored on the server
is fine, but since the template can contain arbitrary python code (like os.system("rm -rf /")),
never accept templites from the client side.
Also note that Templite had given birth to Templite+,
which is more sophisticated, and you’ll probably want to use the latter.
Features:
All the parsing and compiling is performed at preprocessing, so rendering the text is fast
You can escape the ${ delimiter by $\{, and the }$ delimiter by }\$
Use inline, as t = Templite("the template") or load from a file, as
t = Templite.from_file("c:\\thefile.txt") or t = Templite.from_file(open("c:\\thefile.txt"))