A library for building HTML documents with a simple and learnable syntax, inspired by (and similar to) Cenk Altı's PyHTML library, but with improved documentation and type safety.
Learn more by reading the documentation.
-
Inline documentation and type safety for all tags.
-
Editor support for many common tags (attribute suggestions).
-
A modern and readable codebase.
-
No dependencies.
-
100% test coverage.
>>> import pyhtml as p
>>> my_website = p.html(
... p.head(
... p.title("Hello, world!"),
... p.script(src="http://example.com/script.js"),
... ),
... p.body(
... p.h1("Hello, world!"),
... p.p("This is my amazing website!"),
... ),
... )
>>> print(str(my_website))
<!DOCTYPE html>
<html>
<head>
<title>
Hello, world!
</title>
<script type="text/javascript" src="http://example.com/script.js"></script>
</head>
<body>
<h1>
Hello, world!
</h1>
<p>
This is my amazing website!
</p>
</body>
</html>