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.

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>
    </>

IDE Support

Type checking, completions, hover docs, go-to-definition, rename, and semantic highlighting — all working inside fragment syntax.

VS Code completions demo

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.

Feedback and feature requests

Bug reports and feature requests are welcome via GitHub Issues. The project is not currently accepting code contributions.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_fragments-0.32.tar.gz
  • Upload date:
  • Size: 24.5 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.32.tar.gz
Algorithm Hash digest
SHA256 9a5929858c5765944067a1287ce8b906ab79ac84af033cf36391d15a1bd4522d
MD5 d0103e36c30dfca70df0c78588da9bcc
BLAKE2b-256 d1055e85688b68ca435299d5fcbfaca4d65233f999852282f3cf4fb647dfd284

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: python_fragments-0.32-py3-none-any.whl
  • Upload date:
  • Size: 30.7 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.32-py3-none-any.whl
Algorithm Hash digest
SHA256 3ccdcd5c17189f59ba101a0692f4e031f8da2ca4f3d9532e3bfe7a82a0c8f5a7
MD5 0898aa0ce1803e0ed12d3ad68320a4f9
BLAKE2b-256 30ad8f6d44b3e04437eec74a8215b1d1b42a857987e238062a97d65cf65be457

See more details on using hashes here.

Provenance

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