Ketza - HTML defined in python
Contents
Rationale
This project provides a framework for defining reusable units of HTML in python code, as opposed to being a runtime or a templating engine.
My intention is to provide a powerful but simple interface, allowing for extensibility and interplay with other technologies without headaches.
Basics
At the core of Ketza is the tag function, which allows you to build a
html element in a series of function calls as follows:
from ketza import tag
main = tag("main") # Apply element name
app = main({"id": "app"}) # Apply attributes as key-value pairs
hello_world = app("Hello World!") # Apply inner string content
# hello_world is now equal to `<main id="app">Hello World!</main>`
However, Ketza also provides pre-defined named tags for recognised HTML elements based on the WHATWG living standard. A further example is presented below, making use of predefined tags.
Example with an unordered list
Let's say, for argument's sake, I would like to define a list like this:
<ul id="list-of-three">
<li class="list-triplet">
Foo
</li>
<li class="list-triplet">
Bar
</li>
<li class="list-triplet">
Baz
</li>
</ul>
This can be done as follows:
from ketza import ul, li
list_of_three = ul({"id": "list-of-three"})(
li({"class": "list-triplet"})(
"Foo"
),
li({"class": "list-triplet"})(
"Bar"
),
li({"class": "list-triplet"})(
"Baz"
),
)
However, we can simplify this even further:
from ketza import ul, li
triplet = li({"class": "list-triplet"})
list_of_three = ul({"id": "list-of-three"})(
triplet("Foo"),
triplet("Bar"),
triplet("Baz")
)
For our purposes, this yields html which is functionally equivalent to our
intended list-of-three. Even so, the raw html will look more like this:
<ul id="list-of-three"><li class="list-triplet">Foo</li><li class=....
While this does essentially result in pre-minified HTML output, there are situations which call for human-readable raw HTML. As such, the following section shall briefly touch on formatting.
Formatting
Ketza provides a utility function for indenting minified html:
from ketza.formatters import indent
list_of_three = indent(list_of_three)
The indent function turns this:
<ul id="list-of-three"><li class="list-triplet">Foo</li><li class=....
Into this!
<ul id="list-of-three">
<li class="list-triplet">
Foo
</li>
<li class="list-triplet">
Bar
</li>
<li class="list-triplet">
Baz
</li>
</ul>
Future Intentions
Though I am confident that Ketza provides the means to define components representing common HTML boilerplate, I am also considering defining utilities to further streamline HTML boilerplate creation.
I am also open to feedback for how I can improve and extend Ketza, as well as its interoperability with other web technologies.
Metadata
Release files for ketza 2.0.1
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 | |
|---|---|---|---|---|
| ketza-2.0.1.tar.gz | 5.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ketza-2.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.9 kB
Release files / ketza-2.0.1.tar.gz
| Download URL | ketza-2.0.1.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1478b79b62e68e68e2faeb6a1e7b642901e447a141882b354ba139cc2b06006
|
|
BLAKE2b-256 checksum How to use checksums |
3aceadb1a05d13c94ce71751b8a523467910bb93739b37c28ab900750af4831b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Release files / ketza-2.0.1-py3-none-any.whl
| Download URL | ketza-2.0.1-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ad627d353c07a07d9d4805c9cd682b3b3775d9d1e653aae2d5b24065b1e4290
|
|
BLAKE2b-256 checksum How to use checksums |
eea4999ad0b815828547cc946efe2d733c93fd8da3f40b0f9bb05c452d7ea864
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Security for ketza 2.0.1
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.