Lua-powered templating engine with 100% Jinja2 compatibility
Project description
Luma Python Bindings
Python bindings for Luma templating engine, providing a drop-in replacement for Jinja2.
Installation
pip install luma-py
Quick Start
from luma import Template
# Simple rendering
template = Template("Hello, {{ name }}!")
output = template.render(name="World")
print(output) # Hello, World!
# From file
template = Template.from_file("template.luma")
output = template.render(context={"user": "Alice"})
Jinja2 Compatibility
Luma is 100% compatible with Jinja2 templates:
# Works with Jinja2 syntax
template = Template("""
{% for item in items %}
- {{ item | upper }}
{% endfor %}
""")
# Also works with Luma native syntax
template = Template("""
@for item in items
- $item | upper
@end
""")
Features
- ✅ 100% Jinja2 feature parity
- ✅ Drop-in Jinja2 replacement
- ✅ Faster compilation (Lua-powered)
- ✅ Better whitespace handling
- ✅ Template inheritance
- ✅ Macros and filters
- ✅ Autoescape for security
- ✅ Custom filters and tests
API
Template Class
class Template:
def __init__(self, source: str, syntax: str = "auto")
def render(self, **context) -> str
def render_dict(self, context: dict) -> str
@classmethod
def from_file(cls, path: str, syntax: str = "auto") -> Template
Environment Class
class Environment:
def __init__(self, loader=None, **options)
def get_template(self, name: str) -> Template
def from_string(self, source: str) -> Template
def add_filter(self, name: str, func: callable)
def add_test(self, name: str, func: callable)
Examples
Flask Integration
from flask import Flask, render_template_string
from luma import Environment, FileSystemLoader
app = Flask(__name__)
# Use Luma as template engine
luma_env = Environment(loader=FileSystemLoader("templates"))
@app.route("/")
def index():
template = luma_env.get_template("index.html")
return template.render(title="My App")
Django Integration
# settings.py
TEMPLATES = [{
'BACKEND': 'luma.django.LumaTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [...],
},
}]
Migration from Jinja2
Replace imports:
# Before (Jinja2)
from jinja2 import Template, Environment
# After (Luma)
from luma import Template, Environment
That's it! Your Jinja2 templates work unchanged.
Performance
Luma offers better performance than Jinja2 for most workloads:
Benchmark: 10,000 renders
Jinja2: 1.245s
Luma: 0.892s (1.4x faster)
Testing
Run the test suite:
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=luma --cov-report=html
# Run specific test file
pytest tests/test_template.py -v
Running Examples
See the examples/ directory for complete examples:
- basic.py - Simple template rendering examples
- flask_app.py - Flask web application integration
- kubernetes.py - Kubernetes manifest generation
Run examples:
# Basic examples
python examples/basic.py
# Flask app (requires: pip install flask)
python examples/flask_app.py
# Kubernetes manifests
python examples/kubernetes.py
Development
# Clone repository
git clone https://github.com/santosr2/luma.git
cd luma/bindings/python
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black luma tests
# Type check
mypy luma
# Lint
flake8 luma
Publishing to PyPI
See PYPI.md for publishing instructions.
Version
Current version: 0.1.0
License
MIT License - See LICENSE file for details.
Links
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
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 luma_py-0.1.0rc4.tar.gz.
File metadata
- Download URL: luma_py-0.1.0rc4.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bf0d1bafd0bae057353468392a4741b9dd9ec3c12eb15f5093ccaa49f5d4c96
|
|
| MD5 |
404e7beee83ea1dcae5ba0cbe223b23b
|
|
| BLAKE2b-256 |
7753ba2276e46dd8604607401f578749373f4ddd81963c4d5cad5e0320861045
|
Provenance
The following attestation bundles were made for luma_py-0.1.0rc4.tar.gz:
Publisher:
release.yml on santosr2/luma
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
luma_py-0.1.0rc4.tar.gz -
Subject digest:
7bf0d1bafd0bae057353468392a4741b9dd9ec3c12eb15f5093ccaa49f5d4c96 - Sigstore transparency entry: 788154910
- Sigstore integration time:
-
Permalink:
santosr2/luma@a4ae4f953d3110409e7beae345e8915ccc9c922f -
Branch / Tag:
refs/tags/v0.1.0-rc.4 - Owner: https://github.com/santosr2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a4ae4f953d3110409e7beae345e8915ccc9c922f -
Trigger Event:
push
-
Statement type:
File details
Details for the file luma_py-0.1.0rc4-py3-none-any.whl.
File metadata
- Download URL: luma_py-0.1.0rc4-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a9d17ce6d45fbf1dd7659d62b9870e26303a228fc57386b6eefa698ee0396be
|
|
| MD5 |
af8374f8e9e395b0c6731c096de9a1b7
|
|
| BLAKE2b-256 |
9d6717a75445aa2a5b779bdbe9320530b4d601256ce6fc0e6019ddc8d3468d1c
|
Provenance
The following attestation bundles were made for luma_py-0.1.0rc4-py3-none-any.whl:
Publisher:
release.yml on santosr2/luma
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
luma_py-0.1.0rc4-py3-none-any.whl -
Subject digest:
0a9d17ce6d45fbf1dd7659d62b9870e26303a228fc57386b6eefa698ee0396be - Sigstore transparency entry: 788154920
- Sigstore integration time:
-
Permalink:
santosr2/luma@a4ae4f953d3110409e7beae345e8915ccc9c922f -
Branch / Tag:
refs/tags/v0.1.0-rc.4 - Owner: https://github.com/santosr2
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a4ae4f953d3110409e7beae345e8915ccc9c922f -
Trigger Event:
push
-
Statement type: