Skip to main content

A general-purpose .paw templating engine (Jinja2 + Alpine + HTMX parity), pure Python, backend agnostic, Bao first.

Project description

Pating

A general-purpose .paw templating engine. Pure Python, no npm, no Node, no build pipeline. Backend agnostic and usable standalone; Bao first for model-aware components and realtime.

Pating targets parity with Jinja2 (templating), Alpine (client reactivity), and HTMX (server interaction), unified under one .paw syntax. Use it to render web pages, HTML fragments, emails, reports, config files, or plain text.

This is a private, work-in-progress repository. It has no remote.

Install

pip install -e ".[dev]"

Only dependency for the core is markupsafe. The client runtime is a single prebuilt JS file (no build step).

Quick start

from pating import render

html = render("<h1>{title|upper}</h1>", {"title": "hello"})
# '<h1>HELLO</h1>'  (autoescaped by default)

Loops, conditionals, filters, whitespace control:

render(
    "<ul><for u in users><li>{u.name}<if u.admin> (admin)</if></li></for></ul>",
    {"users": [{"name": "Al", "admin": True}, {"name": "Bo", "admin": False}]},
)

Files, includes, and layout inheritance use an Environment with a loader:

from pating import render_file
render_file("templates/page.paw", {"title": "Users", "users": [...]})

The .paw syntax at a glance

{# a comment, dropped from output #}
{expr}                              {# interpolation, HTML-escaped by default #}
{value | filter(arg)}               {# filters, chainable #}
{a if cond else b}                  {# ternary #}

<if cond> ... <elif other> ... <else> ... </if>
<for item in items> ... <else> ... </for>      {# loop helpers: loop.index, .first, .last, .length, .cycle(...) #}
<set name = expr/>

<include "partial.paw">             {# include with current context #}
<include "partial.paw" with={'k': v}>

<extends "layout.paw">              {# layout inheritance #}
<block content> ... {super} ... </block>

<macro card(title, body="")> ... </macro>   {# reusable components #}
<call card("Hi")/>

{x -}   {- y}                       {# whitespace control: trim after / before #}

Client and server directives are plain HTML attributes that the small client runtime interprets in the browser:

<div p-data="{ count: 0 }">
  <button @click="count++">+</button>
  <span p-text="count"></span>
</div>

<button p-get="/items" p-target="#list" p-swap="beforeend">Load more</button>
<div p-sse="/events" p-swap="innerHTML"></div>

Documentation

Status

  • Phase 1 (templating core): production-ready. Full Jinja2-class feature set with a comprehensive test suite.
  • Phase 2 (client reactivity) + Phase 3 (server interaction): the client runtime (src/pating/runtime/pating.js, ~17 KB unminified) and the Python directive builders are complete. The runtime has not yet been exercised by an automated browser test; the Python surface is tested.
  • Phase 4 (Bao-first): complete behind an adapter interface and tested with a fake adapter. Bao is imported lazily and is never required by the core.
  • Phase 5 (packaging/docs/examples): this README, docs/USAGE.md, and examples/.

See the report at the bottom of docs/USAGE.md for known gaps.

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

pating-0.1.0.tar.gz (59.3 kB view details)

Uploaded Source

Built Distribution

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

pating-0.1.0-py3-none-any.whl (46.1 kB view details)

Uploaded Python 3

File details

Details for the file pating-0.1.0.tar.gz.

File metadata

  • Download URL: pating-0.1.0.tar.gz
  • Upload date:
  • Size: 59.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pating-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3638eebba82043e39bdb92c6e5f04ba1bc3680d57780ede79e18a856fdc1cb72
MD5 0509ffb52db3b943d947f892173e17af
BLAKE2b-256 61483f995c35f4c70d285e2b9b7361aee087b07d941916eb07c86d23f0f9b24b

See more details on using hashes here.

File details

Details for the file pating-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pating-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 46.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pating-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bcbfae89b65abde44e048db4f1c296d3f67fe89911990190b6d40e6105a91198
MD5 0effa68f5079806027ea47bc2a7a24be
BLAKE2b-256 e0dc267cbc7121f2252744d4b8c474ae64ee5011dbe6b794458327f736d48531

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