Pyodide HTML
HTML elements for pyodide, implemented as Python functions.
Quickstart
import micropip
micropip.install('pyodide-html')
import pyodide_html as html
ele = html.h1('Hello, world!')
js.document.body.appendChild(ele)
Motivation
In pyodide, you can create HTML elements using js.document, but it is extremely verbose. For example, a range input would look like:
import js
ele = js.document.createElement('input')
ele.type = 'range'
ele.min = 0
ele.max = 50
ele.value = 25
ele.step = 1
With pyodide_html, you can do all this with a single function call:
import pyodide_html as html
ele = html.input(type="range", min=0, max=50, value=25, step=1)
Usage
All the HTML tags are implemented as Python functions. For example, html.h1 creates a <h1> element, html.input creates an <input> element, and so on.
The signature of the function is:
html.element(*children, **props)
which is equivalent to calling <element **props>*children</element>.
Every element has an add method that lets you add new, or update existing children or props. It has the following signature:
html.element(*children, **props).add(*children, **props)
This is convenient if you want to initialize an element with certain props, then add/update the children or props later using add. For example:
import pyodide_html as html
# initialize your element
ele = html.div(className="container")
# Add children
ele.add(
html.h1("My header"),
html.p("Some paragraph here"),
# ...
)
# You can add new props:
ele.add(style="background-color: lightgray")
# You can also update existing props:
ele.add(style="background-color: lightblue")
You can also chain add calls:
ele.add(style="...").add(className="...").add(html.div("a child"))
Note that add modifies an element in-place.
Documentation
See REFERENCE.txt (GitHub Link) for the API reference.
Contributing/Development
After cloning this repo, start with:
pip install -r dev-requirements.txt
You can then make the desired changes
Metadata
Release files for pyodide-html 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyodide-html-0.1.0.tar.gz | 4.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyodide_html-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.7 kB
Release files / pyodide-html-0.1.0.tar.gz
| Download URL | pyodide-html-0.1.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
286acd1e36eea87672b6d93c0b9bc1272aa4d52b7ed2836dee987825d3edf6cd
|
|
BLAKE2b-256 checksum How to use checksums |
87875544d1662319afdb4753e2dcd650492b16f52b59bf773d61d1e9375af90c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.3
|
Release files / pyodide_html-0.1.0-py3-none-any.whl
| Download URL | pyodide_html-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c01d5e758a4c79e148754fdc5fcfc33198d86540ff0c179d668421b6fbf2e413
|
|
BLAKE2b-256 checksum How to use checksums |
d7522df703f0612096a56d7338a7b82f92cb7e7b18a936be47a397a6c1dacb95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.3
|
Security for pyodide-html 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.