any2htpy
any2htpy is a principled converter for HTML/SVG and MathML to htpy inspired by html2htpy, the built-in tool for htpy.
Unlike html2htpy any2htpy uses a feature-complete HTML parser called justhtml.
Features
- adheres to SVG and MathML
- preserves case-sensitive attributes such as SVG
viewBox - preserves SVG path commands and other non-class attribute values with spaces
- tries best-effort DOM for malformed HTML
- properly preserves whitespace for respective tags
- only supports
class_syntax to allow stable parsing by TailwindCSS
A few things any2htpy needs to fix to be better suited for :
- auto-detect if code is just a fragment or a whole document
- boolean attributes are not yet detected (use
dictsyntax) - special attribute detection for AlpineJS or HTMX
- specifically passing HTMX events
:or AlpineJS@
- specifically passing HTMX events
Things that any2htpy will not do:
- add the
import htpycode - add the shorthand syntax of
htpy
Usage
usage: any2htpy [-h] [--input INPUT] [--stdin] [--debug] [--prefix PREFIX] [--fragment]
options:
-h, --help show this help message and exit
--input INPUT input as string or file
--stdin use stdin as input
--debug generate debug output
--prefix PREFIX use a prefix for the tags
--fragment use htpy fragment
input through stdin
[me@machine ] echo "<p>Hello World</p>" | any2htpy --stdin --prefix htpy
htpy.p["Hello World"]
fetching an icon from Bootstrap library:
[me@machine ] curl -s https://icons.getbootstrap.com/assets/icons/0-circle.svg | any2htpy --fragment --stdin
svg(xmlns="http://www.w3.org/2000/svg",width="16",height="16",fill="currentColor",class_=["bi","bi-0-circle"],viewBox="0 0 16 16")[path(d="M7.988 12.158c-1.851 0-2.941-1.57-2.941-3.99V7.84c0-2.408 1.101-3.996 2.965-3.996 1.857 0 2.935 1.57 2.935 3.996v.328c0 2.408-1.101 3.99-2.959 3.99M8 4.951c-1.008 0-1.629 1.09-1.629 2.895v.31c0 1.81.627 2.895 1.629 2.895s1.623-1.09 1.623-2.895v-.31c0-1.8-.621-2.895-1.623-2.895"),path(d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0M1 8a7 7 0 1 0 14 0A7 7 0 0 0 1 8")]
convert a local file
[me@machine ] any2htpy --input icon.svg
Disclaimer
As an AI-skeptic, specifically regarding code and software in general, justhtml is not exactly the obvious choice or more precisely the exact opposite one. However, the heavy test-rig with thousands of tests and the use as a parser without introducing it as a dependency in the resulting code make it a better choice than any other native Python parser library.
License
Licensed under the terms of the MIT License
Copyright
Copyright (c) 2026 Hartmut Seichter
Metadata
Release files for any2htpy 0.2.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 |
|---|---|---|---|---|
| any2htpy-0.2.2.tar.gz | 8.2 kB | Without provenance | Details for any2htpy-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| any2htpy-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for any2htpy-0.2.2-py3-none-any.whl |
Total release size: 14.1 kB
Release files / any2htpy-0.2.2.tar.gz
| Download URL | any2htpy-0.2.2.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ddbebab14195349c7f6b81a4a4025d5a45397f4a05899eb393c136511113a3b3
|
|
BLAKE2b-256 checksum How to use checksums |
1204e9b163a654194c97d427ea4914cbc21dd3afe42544e234fb9a6e72e22b2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / any2htpy-0.2.2-py3-none-any.whl
| Download URL | any2htpy-0.2.2-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b4cd22f9fb6ffa00bf1b2d55f6c50d1966c281d69a8dcd2c857212d14881029
|
|
BLAKE2b-256 checksum How to use checksums |
08d9d7772485963ea44fcd65677ede0a115caba0ae042a3ae1cfc287f97dcb5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for any2htpy 0.2.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.