DSL for Python to HTML aimed at Marimo
Project description
Enter 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 dases. Could be nice to make some simple dashboard-y UI components here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mohtml-0.1.2.tar.gz
.
File metadata
- Download URL: mohtml-0.1.2.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c2f9eea72023bc3cbcee8ae2ebca94cfe4707ea49a386c67aac5a53f33b3d50 |
|
MD5 | ce7d3d05db0277ba762b07d93ad57144 |
|
BLAKE2b-256 | 924e9f642b71c3897012e53709431e42b46fd0b5b29ab7b34cc72a24b94bebbe |
File details
Details for the file mohtml-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: mohtml-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb3a5e1edf4d6ca6339673e31ba52c51caaca929ce377c4a6eb6b1773db5c378 |
|
MD5 | f1a78d05d532beb4341c7abe49eee7ee |
|
BLAKE2b-256 | 20034d6820534e0990a64eb7e0e454e399bbd4c76fbb4af7ab2d6fc7dbf82fbe |