htmlclasses
Python in, HTML out.
There are templating engines making it possible to write code in HTML template files. However, I would very much prefer to be able to write Python that gets converted to HTML rather than write Python-like mini language engulfed in HTML.
Version
0.3.2
Goals
Generating valid HTML from pure Python code.
Non-goals
Features geared toward JavaScript.
- I find using 2 intertwined languages too cumbersome.
- JavaScript is heavily overused and misused. I don't want to add to the problem.
Installation
pip install htmlclasses
Developing
This project is managed with poetry: https://github.com/python-poetry/poetry
git clone git@github.com:uigctaw/htmlclasses.gitpoetry install
Running tests
./check_all.sh
Examples
To convert Python to HTML run:
from htmlclasses import to_string
to_string(html, indent=' ')
Hello World
from htmlclasses import E
class html(E):
class head:
pass
class body:
class p:
TEXT = 'Hello, world!'
<!DOCTYPE html>
<html>
<head/>
<body>
<p>
Hello, world!
</p>
</body>
</html>
Repeated Elements
from htmlclasses import E
class html(E):
class head(E): # Must sublcass if repeating tags
class meta:
name = 'description'
content = 'Framework usage examples'
class meta: # type: ignore[no-redef] # noqa: F811
name = 'keywords'
content = 'Python, HTML'
class body:
class p:
TEXT = 'Hello, world!'
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Framework usage examples"/>
<meta name="keywords" content="Python, HTML"/>
</head>
<body>
<p>
Hello, world!
</p>
</body>
</html>
Work in progress
SVG utilities for creating plots.
Alternatives
Release files for htmlclasses 0.3.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 | |
|---|---|---|---|
| htmlclasses-0.3.2.tar.gz | 10.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| htmlclasses-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.1 kB
Release files / htmlclasses-0.3.2.tar.gz
| Download URL | htmlclasses-0.3.2.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3bd08f4ba4dcf6260c6d47eab38e1188937ece0ec4dab1e990155c0c209ccea4
|
|
BLAKE2b-256 checksum How to use checksums |
d04a9b7e007f32b23dd4cbfeaa71c95fe20144e52aaec8665384bfeac5c957fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.6 CPython/3.8.10 Linux/5.11.0-34-generic
|
Release files / htmlclasses-0.3.2-py3-none-any.whl
| Download URL | htmlclasses-0.3.2-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df0b95a5fa038a1ee49b7a8259b62c1c78ea689b7a15fba58f4534631c0cf197
|
|
BLAKE2b-256 checksum How to use checksums |
ed504325f1638e1c4fa88200f36a89415bb4c5e9a1e274416df465fff7d2df5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.6 CPython/3.8.10 Linux/5.11.0-34-generic
|