A beautiful html builder library.
Likely abandoned. No release or commit for years (last release over 5 years ago).
$
pip install htmlbuilderREADME as published on PyPI with version 1.0.0.
HtmlBuilder
HtmlBuilder is a python library that allows you to render HTML files by writing python code. And to make use of python features, clean syntax, and object-oriented design to their full potential.
Why should you care about this library?
When rendering HTML programmatically, there are other options available (template engines and other rendering libraries). Still, these are often limited in what they can do, or it's necessary to learn a new level of abstraction before being productive. HtmlBuilder tries to improve on this by following the next few ideas:
- Minimal learning curve: Users should need no more than Python and HTML knowledge to be productive using this tool.
- Real python code: The final code looks and behaves as you would expect from other python code.
- Easily testable: Users can introspect and unit test the HTML object structure before rendering the HTML string.
Installation
run pip install htmlbuilder
Use examples:
A simple example
# import necessary tags and attributes
from htmlBuilder.tags import *
from htmlBuilder.attributes import Class, Style as InlineStyle
# html tags are represented by classes
html = Html([],
# any tag can receive another tag as constructor parameter
Head([],
Title([], "A beautiful site")
),
Body([Class('btn btn-success'), InlineStyle(background_color='red', bottom='35px')],
Hr(),
Div([],
Div()
)
)
)
# no closing tags are required
# call the render() method to return tag instances as html text
print(html.render(pretty=True))
Output
<html>
<head>
<title>
A beautiful site
</title>
</head>
<body class='btn btn-success' style='background-color: red; bottom: 35px'>
<hr/>
<div>
<div></div>
</div>
</body>
</html>