Skip to main content

Modern HTML template rendering in Python

Project description

Python Fragments

This package is in early development and not yet stable. The API may change without notice between releases.

Production-ready, modern HTML template rendering in Python — no build step, no template files, and native HTML awareness out of the box.

from fragments import loader  # isort: skip

from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from components import Layout, PostCard

app = FastAPI()

POSTS = [...]

@app.get("/", response_class=HTMLResponse)
async def index() -> str:
    published = [p for p in POSTS if p.published]
    return <>
        <Layout title="My Blog">
            <h1>Latest Posts</h1>
            <PostCard for={{ post in published }} post={{ post }} />
        </Layout>
    </>

Installation

pip install python-fragments

Register the loader at your application's entry point, before importing any modules that contain fragments:

from fragments import loader  # isort: skip

Any .py file containing <> is transpiled automatically. Nothing else to configure.

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

python_fragments-0.3.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

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

python_fragments-0.3-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file python_fragments-0.3.tar.gz.

File metadata

  • Download URL: python_fragments-0.3.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_fragments-0.3.tar.gz
Algorithm Hash digest
SHA256 03c5266fa4b9c175534368e490e28292bee96b739c83aca085708675b0f90df2
MD5 32208e45d8a861350ada7603fa76f0e5
BLAKE2b-256 35e8e9a464972675055619bf3ee7b68e7fae23d0f93f73ec902cb81ae5cae204

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_fragments-0.3.tar.gz:

Publisher: release.yml on TheRunningAlgorithm2/python-fragments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_fragments-0.3-py3-none-any.whl.

File metadata

  • Download URL: python_fragments-0.3-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_fragments-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9a2071543b8825c2597a9c1606c26a9a62f5397282c0cd3bc94884bf3ba934f1
MD5 9b75518649309de23ec559918db8330a
BLAKE2b-256 f3fd7f646c335abead6cb27456a9b9e8275a1b606bb5281015bb3146737f5d63

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_fragments-0.3-py3-none-any.whl:

Publisher: release.yml on TheRunningAlgorithm2/python-fragments

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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