Skip to main content

DSL for Python to HTML aimed at Marimo

Project description

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.

  1. Maybe we can use this tool to make representations of objects nicer in Marimo.
  2. Maybe we can come up with a nice way to turn these HTML objects into something reactive.
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mohtml-0.1.4.tar.gz (6.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mohtml-0.1.4-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file mohtml-0.1.4.tar.gz.

File metadata

  • Download URL: mohtml-0.1.4.tar.gz
  • Upload date:
  • Size: 6.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.5

File hashes

Hashes for mohtml-0.1.4.tar.gz
Algorithm Hash digest
SHA256 9d8754e643cdab9c7e1ee4783e9dc71593df8788a844e91ad5587ca085b5d029
MD5 e4e683ca457190868cb8a696d608a11b
BLAKE2b-256 077c572584c5a52cbb780a42c1fd7d5926bc31736354a96e035212c7a7fb3bd7

See more details on using hashes here.

File details

Details for the file mohtml-0.1.4-py2.py3-none-any.whl.

File metadata

  • Download URL: mohtml-0.1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.5

File hashes

Hashes for mohtml-0.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ab1ef8a11bd4c936dcd6a01706236fc170c2959e9eaa3e284e53221b4a5c71e5
MD5 c167487bfd03f07b86b1e3c403b65e1f
BLAKE2b-256 3fb8d7328b518314b0e0e9c397c17aa5312804c5cf8751f94bbe1b76f1c08d2c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page