Optionally installable features of IDOM.
To install a stable set of features for IDOM simply run.
pip install idom[stable]
To install all extra features run
pip install idom[all]
At the moment this is the only supported :ref:`Layout Server` available for IDOM:
pip install idom[sanic]
IDOM includes a transpiler for writing JSX-like syntax in a normal Python 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]
- Import
idom
in your application'sentrypoint.py
- Import
your_module.py
with a# dialect=html
header comment. - Inside
your_module.py
importhtml
fromidom
- 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!
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 :class:`~idom.dialect.HtmlDialectTranspiler` which implements
Pyalect's :class:`~pyalect.dialect.Transpiler` interface using some tooling from
htm.py.