mohtml
This project is all about a DSL to write HTML in Python.
This work is heavily inspired by FastHTML.
I mainly made this to see if I could reimplement it easily and if I might be able to hack together a lightweight variant of the idea for Marimo. If you feel like giving folks credit, feel free to join the FastHTML Discord and give them a high-five first.
Installation
You can install this project via uv/pip:
uv pip install mohtml
Quick demo
With that out of the way, let's have a quick look what what the DSL is like.
# You can import any HTML element this way
from mohtml import a, p, div, script, h1
div(
script(src="https://cdn.tailwindcss.com"),
h1("welcome to my blog", klass="font-bold text-xl"),
p("my name is vincent", klass="text-gray-500 text-sm"),
a("please check my site", href="https://calmcode.io", klass="underline")
)
This code will generate the following HTML:
<div>
<script src="https://cdn.tailwindcss.com">
</script>
<h1 class="font-bold text-xl">
welcome to my blog
</h1>
<p class="text-gray-500 text-sm">
my name is vincent
</p>
<a class="underline" href="https://calmcode.io">
please check my site
</a>
</div>
You can also render this HTML nicely from Marimo via:
myhtml = div(...)
mo.Html(f"{myhtml}")
From here?
This is already pretty cool on it's own, but there are a few directions here.
- Maybe we can use this tool to make representations of objects nicer in Marimo.
- Maybe we can come up with a nice way to turn these HTML objects into something reactive.
- Maybe we can use this as an alternative for Jinja templates in some cases. Could be nice to make some simple dashboard-y UI components here.
Metadata
Release files for mohtml 0.1.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mohtml-0.1.11.tar.gz | 11.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mohtml-0.1.11-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.5 kB
Release files / mohtml-0.1.11.tar.gz
| Download URL | mohtml-0.1.11.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d64024cce66c4b7b553867dd8d9b4d76c0201c0a2291b79b8af2ef28818403b8
|
|
BLAKE2b-256 checksum How to use checksums |
e623a284ff5cae21d147f493a5b9a888a8cd4fb0434f0dfe81b7d414b07356d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Release files / mohtml-0.1.11-py3-none-any.whl
| Download URL | mohtml-0.1.11-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
edfc94650c7803a445e80d548d109d9be5b394ea94c74ec7e8947721d83712a0
|
|
BLAKE2b-256 checksum How to use checksums |
758968d89c91cd00f1b1ee42f29ddfb1742c3232662da1ee3558284194bed6b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|