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

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_fragments-0.7.tar.gz
  • Upload date:
  • Size: 18.0 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.7.tar.gz
Algorithm Hash digest
SHA256 cc0d7478c23875d251a4f19d26387428c400fb7d83cffbb8baf993a9deb76b18
MD5 8d15a35b9ae0503c0e2006e537c122cd
BLAKE2b-256 de095f0b992d2470caec3b7d4f0c7e6b41d20a7cc76c9f045ed9c2766dddb1f3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: python_fragments-0.7-py3-none-any.whl
  • Upload date:
  • Size: 27.4 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 13993be1c15190064b0dd97b0ca1f431e1cddcd0d80f49e7edd0b77e36b76a28
MD5 32cd81c507a2827d0449e800f85f5a5e
BLAKE2b-256 ff4eb81bc4d76282dcde73b2ebd7fa9d5bcbba2f7a5757eeeb0fcfbec1a2c23c

See more details on using hashes here.

Provenance

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