Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/nishad12323/py2html/llms.txt

Use this file to discover all available pages before exploring further.

py2html is a Python library that lets you build full HTML pages entirely in Python code. Instead of writing markup or template strings, you create a Parent object and call methods like Button(), Frame(), Heading(), and Link() to compose your document — then call getHTML() to render it.

Installation

Set up py2html in your project using the installer script.

Quickstart

Build your first HTML page in under five minutes.

Core Concepts

Understand how the Parent class and element model work.

API Reference

Full reference for every method on the Parent class.

Why py2html?

Writing HTML by hand means wrestling with closing tags, escaping user input, and keeping markup in sync with your Python logic. py2html keeps everything in one place — your Python file — so you can build pages with loops, conditionals, and variables just like any other Python code.

Widget-Style API

Call methods like Button(), Frame(), and Heading() — no template syntax to learn.

Inline Text Markup

Use shorthand like [* bold *], [_ italic _], and [xl large xl] inside text content.

Flexbox Layouts

The Frame() method maps directly to CSS flexbox and block layouts with full positioning support.

Auto-Escaping

All user-supplied text is HTML-escaped by default so you don’t accidentally inject markup.

How it works

1

Create a Parent

Instantiate py2html.Parent() to start a new document.
2

Add elements

Call methods like Heading(), Button(), and Frame() to add elements to your page.
3

Render HTML

Call getHTML() to get the rendered HTML string, or saveToFile() to write it directly to disk.
import py2html

page = py2html.Parent()
page.Heading(level=1, text="Hello, py2html!")
page.Button(text="Click me", fg="#fff", bg="#00a651")

print(page.getHTML(format=True))
py2html is not on PyPI. Use the installer script to set it up in your project.

Build docs developers (and LLMs) love