Python port of the Web Definition Language (WDL) core component rendering engine.
ruledwdl is a pure Python implementation of the WDL component renderer (1:1 replica of @ruledwdl/csr / ruledwdl-php). It takes REGISTRY, COMPONENTS, and DATA JSON definitions and compiles them into clean HTML markup with zero runtime external dependencies.
- Zero External Dependencies: Pure Python 3.8+ implementation with 0 third-party packages required.
- WDL Layers Syntax v0.3.x: Emmet-like layer expressions (
tag.semantic_id,>,+,<,<*N,<@N,*repeat,*loopKey) backed byWDLDomTree. - Registry Schema V2.1 Support: Compiles Scoped CSS Rules (
@scope), inheritance (uses), theme variables, anddata-variantattributes. - Component Identifier Attributes: Automatically emits
wdl-comp="{semantic_id}"anddata-wdl-indexfor precise element targeting. - Pluggable Hooks: Supports custom
transformDataandtransformTexthooks for external text formatting or Markdown parsing.
pip install ruledwdlOr install locally:
pip install -e .from ruledwdl import render
registry = {
"$version": "2.1",
"card": {
"class": "p-6 bg-slate-800 border border-slate-700 rounded-xl"
}
}
components = [
{
"layers": "div.card > h2.title + p.desc",
"attr": {
".title": {"text": "${title}", "class": "text-xl font-bold text-white"},
".desc": {"text": "${desc}", "class": "text-slate-400"}
}
}
]
data = {
"title": "RuledWDL Python",
"desc": "Native server-side WDL layout rendering in Python."
}
html = render(registry, components, data)
print(html)from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from ruledwdl import render
app = FastAPI()
@app.get("/", response_class=HTMLResponse)
def home():
components = [
{
"layers": "main.container > h1.heading + p.body",
"attr": {
".heading": {"text": "FastAPI + RuledWDL", "class": "text-3xl font-extrabold"},
".body": {"text": "Rendered dynamically with Python."}
}
}
]
html = render({}, components, {})
return HTMLResponse(content=html)python3 -m unittest discover -s testspython3 examples/cli.pyuvicorn examples.fastapi_app:app --reloadLicensed under GNU Affero General Public License v3.0 (AGPL-3.0-or-later).