Skip to main content

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) ... $end and $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


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.5.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xylo_py-0.1.5-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file xylo_py-0.1.5.tar.gz.

File metadata

  • Download URL: xylo_py-0.1.5.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for xylo_py-0.1.5.tar.gz
Algorithm Hash digest
SHA256 468ba79bf37675d7dfce20a6d4b3ab79110c2bac0269f3fb582ef63daeb1f0e3
MD5 ab349b8657e40bf1a7cacfe19d717f2f
BLAKE2b-256 e15fec1fb8739a0f9c41c51670d040fd093ac0118d1f612d2ccfdd6a3eb492e6

See more details on using hashes here.

File details

Details for the file xylo_py-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: xylo_py-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for xylo_py-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3e8688782ddaf9ac3d098d9a0feb3c3bac26a3afb80b0e3b5346ca9897470b98
MD5 0b6cd85e7b2bbe9403b369a0e417ba6c
BLAKE2b-256 4cb9fa03d2dfe5a98fa02b3f81d3f002a3fc7b23c752db8fb7d0adad2e712630

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page