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.15.tar.gz (20.2 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.15-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_fragments-0.15.tar.gz
  • Upload date:
  • Size: 20.2 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.15.tar.gz
Algorithm Hash digest
SHA256 e96882af181eba80e39e728197d5458a6a938278b48d3d1b8c73fe6762e506e1
MD5 31cf9ad5b7b4d84e814149bfcaffb069
BLAKE2b-256 eabf7be9ee5defd9901e354f2643daa3534e1ea32d53b741bb13bc84a7ccf477

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_fragments-0.15.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.15-py3-none-any.whl.

File metadata

  • Download URL: python_fragments-0.15-py3-none-any.whl
  • Upload date:
  • Size: 28.5 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.15-py3-none-any.whl
Algorithm Hash digest
SHA256 b93bbf97ada38580c8105a9784f229ea4d59cb13160900aecad1871380c6fdca
MD5 52d281123f2af956e28fe8f04526df5f
BLAKE2b-256 1fe15ee2f140447d52f4378461362a580478060340fb77e821cf8d9bba3a7b04

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_fragments-0.15-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