htmlfactory 
A simple way to produce HTML with Python. Source code can be found on github.
pip install htmlfactory
htmlfactory simplifies the process of making HTML through Python.
Examples:
basic div example
TagFactory("div.my-class")
<div class='my-class'></div>
To add content between the divs, we can pass a string or TagFactory objects.
# pass a string
TagFactory("div.my-class", 'I am inside the div.')
<div class='my-class'>I am inside the div.</div>
# pass a TagFactory object
TagFactory("div.my-class", TagFactory("div", "child tag"))
<div class="my-class">
<div>
child tag
</div>
</div>
children div example
pass a list of TagFactory objects
TagFactory("div.parent-div", [
TagFactory("div.first-child-div", (
TagFactory("div.second-child-div", "It's party time.")))])
<div class='parent-div'>
<div class='first-child-div'>
<div class='second-child-div'>
It's party time.
</div>
</div>
</div>
Note: Children tags can be passed through a list, tuple, or singular TagFactory object.
printing TagFactory objects
To output a TagFactory object, use print.
print(TagFactory('div', TagFactory('form')))
<div><form></form></div>
Use the function pretty_str() for an indented output.
print(TagFactory('div', TagFactory('form')).pretty_str())
<div>
<form>
</form>
</div>
If you would like an HTML, body, and head tag to be included, pass add_html_tags=True.
print(TagFactory('div', TagFactory('form')).pretty_str(add_html_tags=True))
<html>
<head>
</head>
<body>
<div>
<form>
</form>
</div>
</body>
</html>
multiple classes example
You can add as many classes as you want to your tag object:
TagFactory("div.class1.class2.class3.class4.class5", 'I have a lot of classes.')
<div class='class1 class2 class3 class4 class5'>I have a lot of classes.</div>
adding attributes example
You can add attributes to your tab object by using keyword arguments:
TagFactory("form", 'I have an action & method attribute.', action="/action_page.php", method="get")
<form action='/action_page.php' method='get'>I have an action and method attribute.</form>
Note: 'for' is a keyword so it cannot be used as a keyword argument. Instead use 'four'. Example:
TagFactory("div.my-class", "inside the div", four="my-form")
Dashes (-) also cause a similar problem. For all html attributes that require a dash, omit the dash. The dash will be added upon creation of the object.
# with an omitted dash
TagFactory("div", role="application", ariadescribedby="info")
<div role='application' aria-describedby='info'></div>
adding tags without closing brackets example
You can create tags without closing brackets, which may be useful if wanting to add an img or link:
test_tag = SingletonTag("img", border="0", alt="TestTag",
src="logo_w3s.gif", width="100",
height="100")
<img border='0' alt='TestTag' src='logo_w3s.gif' width='100' height='100'>
The SingletonTag class is inherited to the TagFactory class, so SingletonTags can be treated like TagFactory objects and added as children html elements to other TagFactory objects.
a_tag = TagFactory("a", SingletonTag("img", src="logo_w3s.gif"),
href="www.google.com")
<a href='www.google.com'><img src='logo_w3s.gif'></a>
Metadata
Release files for htmlfactory 0.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 | |
|---|---|---|---|---|
| htmlfactory-0.0.1.tar.gz | 6.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| htmlfactory-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.2 kB
Release files / htmlfactory-0.0.1.tar.gz
| Download URL | htmlfactory-0.0.1.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b5e44bdd71b0b0a948cf2488984b534757ace337b9c6eee3a784cde5135d890
|
|
BLAKE2b-256 checksum How to use checksums |
bc25c6275f450f86a616b451a3acec59f33e296866b11158d648296a2d4d9b96
|
| 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/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1
|
Release files / htmlfactory-0.0.1-py3-none-any.whl
| Download URL | htmlfactory-0.0.1-py3-none-any.whl |
|---|---|
| Size | 7.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4dee2a7863f76e80357491a9a888d2edc4eefac588ff697fae2a751d23ee5065
|
|
BLAKE2b-256 checksum How to use checksums |
a8d26abdade907f01082ebeca5935ff8134275dddc9280fbfe24154e4fc5c2ae
|
| 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/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.1
|
Security for htmlfactory 0.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.