Installation

To install IDOM and a default implementation for all features:

pip install idom[stable]

For a minimal installation that lacks implementations for some features:

pip install idom

For more installation options see the Extra Features section.

Note

IDOM also supplies a Flake8 Plugin to help enforce the Rules of Hooks

Extra Features

Optionally installable features of IDOM. To include, them use the given “Name” from the table below:

pip install idom[NAME]

Name

Description

stable

Default implementations for all IDOM’s features

testing

Utilities for testing IDOM using Selenium

sanic

Sanic as a Layout Server

fastapi

FastAPI as a Layout Server

tornado

Tornado as a Layout Server

flask

Flask as a Layout Server

dialect

Python Language Extension for writing JSX-like syntax

all

All the features listed above (not usually needed)

Python Language Extension

IDOM includes an import-time transpiler for writing JSX-like syntax in a .py file!

# dialect=html
from idom import html

message = "hello world!"
attrs = {"height": "10px", "width": "10px"}
model = html(f"<div ...{attrs}><p>{message}</p></div>")

assert model == {
    "tagName": "div",
    "attributes": {"height": "10px", "width": "10px"},
    "children": [{"tagName": "p", "children": ["hello world!"]}],
}

With Jupyter and IPython support:

%%dialect html
from idom import html
assert html(f"<div/>") == {"tagName": "div"}

That you can install with pip:

pip install idom[dialect]

Usage

  1. Import idom in your application’s entrypoint.py

  2. Import your_module.py with a # dialect=html header comment.

  3. Inside your_module.py import html from idom

  4. Run python entrypoint.py from your console.

So here’s the files you should have set up:

project
|-  entrypoint.py
|-  your_module.py

The contents of entrypoint.py should contain:

import idom  # this needs to be first!
import your_module

While your_module.py should contain the following:

# dialect=html
from idom import html
assert html(f"<div/>") == {"tagName": "div"}

And that’s it!

How It Works

Once idom has been imported at your application’s entrypoint, any following modules imported with a # dialect=html header comment get transpiled just before they’re executed. This is accomplished by using Pyalect to hook a transpiler into Pythons import system. The HtmlDialectTranspiler implements Pyalect’s Transpiler interface using some tooling from htm.py.