Build Status Coverage

Simple python templates

  - key : %os.environ.get(USER)
  - roaming : %if(sys.platform=='win32',1,0)
  - other : %eval(1 + 1)
import mod
f = open('')

Allows simple macros to be expanded inline. You can from smx import Smx to evaluate, or evaluate from the command line. Options to import all env vars, or modules from the command line are available. Macros can be nested... so %expand(%include(...)) is a valid syntax.

Used for yml templates, config files, kubernates deployments, simple HTML pages, etc.


pip install smx


   > smx > file.out
   > smx --help

Or from python:

   from smx import Smx
   ctx = Smx()
   ctx.expand_io(fin, fout)
   ctx.expand_file(filename, in_place=True)

Including code and files

Macro Description
indent(str) each line of the indented string is indented at the level where the indent function was called.
include(str) include the specified file
strip(str) strip a string
expand(str) string is expanded using smx syntax
python(str) string is expanded using python syntax
module(str) string is interpreted as a module and imported


Macro Description
os.... os functions are included by default, for example %os.path.basename(...)
sys.... sys functions are included by default EG: %sys.platform% can be used


Macro Description
for(name, range, loop) loop code is expanded for each value in the range
if(val, true-val, false-val) if val is expanded to non-empty, true-val is executed
add(a, b) numbers are added
sub(a, b) numbers are subtracted


Smx includes an wsgi module. The goal is to be able to easily serve template driven pages using smx syntax.