Skip to main content

PyHTML Enhanced

A library for building HTML documents with a simple and learnable syntax, inspired by, and similar to the original PyHTML library, but with improved documentation and type safety.

Benefits over PyHTML

  • Inline documentation and type safety for all tags. Documentation for tags is pulled from MDN Web Docs.

  • A modern and readable codebase.

  • No dependencies.

Usage

import pyhtml as h

my_website = h.html(
    h.head(
        h.title("Hello, world!"),
        h.script(src="http://example.com/script.js"),
    ),
    h.body(
        h.h1("Hello, world!"),
        h.p("This is my amazing website rendered with PyHTML Enhanced!"),
    ),
)

# Converting it to a string is all you need to do to render it!
print(str(my_website))

This will produce the following HTML code:

<html>
  <head>
    <script src="http://example.com/script.js"></script>
    <title>
      Hello, world!
    </title>
  </head>
  <body>
    <h1>
      Hello, world!
    </h1>
    <p>
      This is my amazing website rendered with PyHTML Enhanced!
    </p>
  </body>
</html>

TODOs

There are a couple of things I haven't done yet

  • Make tags by themselves render, so str(br) renders to <br/>
  • Add default properties to tags
  • Make inline documentation include documentation of suggested properties
  • Update links within documentation to make them point to the right locations.
  • Some tags (eg <pre>) currently aren't properly implemented

How it works

Since there are so many HTML tags, it would be extremely tedious to document them all manually. In the meta directory, you will find code that solves this problem with the following steps:

  1. Download the Markdown source for MDN's documentation of all HTML elements.

  2. Parse the markdown to gather all tag names and descriptions, discarding garbage data and obsolete tags.

  3. Use data from a YAML configuration file (meta/tags.yml) to gather information on suggested properties and base classes to use for each tag.

  4. Generate Python code to represent all of these tags.

Credits

Cenkalti/PyHTML

Cenk Altı's work was used as a source of inspiration and reference. Although all the code in pyhtml-enhanced was written by me, I want to thank them for the significant help their hard work provided while creating this project.

MDN Web Docs

Almost all of the documentation was gathered from the MDN Web Docs. It's super neat that all their documentation is open (licensed as CC-BY-SA-2.5 if you're interested).

License

All code in this project is licensed under the MIT License.

However, the documentation found in pyhtml/__tags/generated.py was copied from MDN Web Docs, and is licensed under CC-BY-SA-2.5. See LICENSE_DOCS.md for a copy of the license.

Release files for pyhtml-enhanced 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyhtml-enhanced 0.2.0
File Size Uploaded
pyhtml_enhanced-0.2.0.tar.gz 25.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyhtml-enhanced 0.2.0
File Interpreter ABI Platform
pyhtml_enhanced-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.8 kB

Release files / pyhtml_enhanced-0.2.0.tar.gz

Download URL pyhtml_enhanced-0.2.0.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6d2db9fe8e62c88b5913f51eb2a85bbcff8a960926ecc8760607470210416ef2
BLAKE2b-256 checksum
How to use checksums
b1ad7c3003305191b3adb6c0d541fcc4115f60c5d840adf110b9c05a913c5fdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.5 Linux/5.15.0-1041-azure

Release files / pyhtml_enhanced-0.2.0-py3-none-any.whl

Download URL pyhtml_enhanced-0.2.0-py3-none-any.whl
Size 23.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01118eb72b3ea2ed80343f2f89669a9ed72146a497c36bef2b2a2a91e14c249c
BLAKE2b-256 checksum
How to use checksums
acd9894d4652554dbb3880bc06c5b3f3231a8e5124887f3a5e2d1d6741af4de3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.5 Linux/5.15.0-1041-azure

Release history Release notifications | RSS feed

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.4

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.1

2 release files

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page