Skip to main content

Add your description here

Project description

Maler

A Python templating library for rendering dynamic HTML and MJML content in a type-safe way.

Why Maler?

"Maler" is Norwegian for both "painters" and "templates" — fitting for a library that helps you paint your pages with reusable templates.

Installation

uv add maler

Or with pip:

pip install maler

Quick Start

Create your first template:

from maler import div, span

my_page = div(
    "Hello ", span("World", class_="font-bold")
).render()

Dynamic Content

Use the @template decorator for safe-dynamic content. This will escape unsafe HTML content:

from maler import div, span, template

@template
def hello_world(name: str | None = None):
    return div(
        "Hello ", span(name or "World", class_="font-bold")
    )

html = hello_world(name="<script>a_bad_script=...</script>")

Leading to the following:

<div>Hello <span class="font-bold">&lt;script&gt;a_bad_script...</span></div>

FastAPI Integration

Maler integrates seamlessly with FastAPI using the render_template decorator:

from fastapi import FastAPI
from maler import div, h1
from maler.fastapi import render_template

app = FastAPI()

def page_template(user: User):
    return div(
        h1("Welcome, ", user.name)
    )

def error_template(error: Exception):
    return div("Something went wrong!")

@app.get("/user/{user_id}")
@render_template(page_template, error_template)
async def get_user(user_id: int):
    return await fetch_user(user_id)

The decorator automatically returns an HTMLResponse. If the client sends Accept-Encoding: application/json will it return JSON instead.

MJML Support

Create responsive emails using MJML syntax with the @mjml_template decorator:

from maler.mjml import mjml_template
from maler.mjml_tags import mjml, mj_body, mj_section, mj_column, mj_text
from maler import Tag

@mjml_template
def welcome_email(name: str):
    return mjml(
        mj_body(
            mj_section(
                mj_column(
                    mj_text(f"Welcome, {name}!")
                )
            )
        )
    )

html = welcome_email("Alice")

This requires the mrml package for MJML-to-HTML conversion.

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

maler-0.1.1.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

maler-0.1.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file maler-0.1.1.tar.gz.

File metadata

  • Download URL: maler-0.1.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for maler-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b53ae5806f950242490c9aa7d0cf6fc3d94a42b5f68bb48e659db13e7881c4d7
MD5 1ddf927a4a50a3db5cff08d1da8d2c7e
BLAKE2b-256 8bc42c792d69484b8eb685b310a2fd069872ca95ac27016334d5390576e10bc8

See more details on using hashes here.

File details

Details for the file maler-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: maler-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for maler-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dedd9e0e2bcdebdeb4837cd41e0cad4de930ce6de5608b9812eb27ce46cb1c6f
MD5 138b28d624ef44c0cc81fb88d3a72cd3
BLAKE2b-256 c49fb6919c05a61f093af3141b708d3fd641d001162c189b4350ddc57543b3d0

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