htexpr: Templating for Dash
htexpr compiles an html-like template syntax into Python
expressions, allowing embedded Python expressions in attributes and
content. It is inspired by JSX and intended to complement the
excellent Dash package, which allows you to write single-page
React apps in Python. For motivation and further instructions, see the
documentation.
Example
A Unicode table:
import dash
from dash import dcc, html, Input, Output, State
from htexpr import compile
import unicodedata
app = dash.Dash()
app.layout = compile("""
<div>
<table style={"margin": "0 auto"}>
<tr><th>char</th><th>name</th><th>category</th></tr>
[
(<tr style={'background-color': '#eee' if line % 2 else '#ccc'}>
<td>{ char }</td>
<td>{ unicodedata.name(char, '???') }</td>
<td>{ unicodedata.category(char) }</td>
</tr>)
for line, char in enumerate(chr(i) for i in range(32, 128))
]
</table>
</div>
""").run()
app.run_server(debug=True)
Further demonstrations:
- a larger Unicode table
- a Bootstrap example
Development status
I wrote this to help me with a particular project where I kept making bracketing mistakes. The code works for that project, but there are likely to be corner cases I haven't considered.
The Python grammar used here is quite simplistic: it recognizes strings and variously parenthesized expressions. By understanding more Python it would probably be possible to disambiguate between comparison operators and tags, and thus drop the requirement to enclose nested expressions in parentheses.
The error messages are not always helpful, and in particular the code objects don't yet have reliable line-number data.
Metadata
Release files for htexpr 0.1.2
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 | Actions |
|---|---|---|---|---|
| htexpr-0.1.2.tar.gz | 11.5 kB | Without provenance | Details for htexpr-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| htexpr-0.1.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for htexpr-0.1.2-py2.py3-none-any.whl |
Total release size: 21.9 kB
Release files / htexpr-0.1.2.tar.gz
| Download URL | htexpr-0.1.2.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5b0d9423ca30984639442c31fae14c699d13d7ee242cc79f82b0b02ea2d36b5
|
|
BLAKE2b-256 checksum How to use checksums |
7fb043ef436d234696b1f33f0c1d15826310535198e45e18b89577046f5c696d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.0
|
Release files / htexpr-0.1.2-py2.py3-none-any.whl
| Download URL | htexpr-0.1.2-py2.py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
988c8fb5188cbcac47d1f5541786b31ec9252fdaae34bf6527162507cbc2cd59
|
|
BLAKE2b-256 checksum How to use checksums |
fc7422bfea0265d038053d5cc7929dacd772cb3c363c5f7a3e0d702304a7405b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.0
|
Security for htexpr 0.1.2
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.