Generate HTML using an intuitive Python interface.
Project description
Use Python to build HTML.
balisage is a Python package that allows you to generate HTML using an intuitive and easy-to-use interface.
Installation
balisage
is available on PyPI and can be installed using pip
:
pip install balisage
The source code can be viewed on GitHub.
Dependencies
Currently, the minimum required Python version is 3.11.
balisage
only uses the Python standard library, which means you don't need to install any additional dependencies to use it.
However, for some more advanced features, you may need to install extra optional dependencies:
Extra | Description | Dependencies |
---|---|---|
data |
Work with dataframes | pandas |
formatting |
Format HTML nicely | beautifulsoup4 |
You can install these dependencies using the command
pip install balisage[<extra>]
where <extra>
is the name of the extra dependency group.
To install multiple extra dependencies at once, you can use
pip install balisage[<extra>,<extra>,...]
Licensing
This project is licensed under the MIT License.
Example usage
The samples
directory has more examples, which include source code and output, but see below for a quick example of how to use the package.
Creating a basic page
To create a basic page, you can use the Page
object and its add
method. You can also specify stylesheets to link using the stylesheets
argument.
from balisage import (
Attributes, Classes, Heading1, Page, Paragraph
)
# Create a page
page = Page(
title="Sample Page",
stylesheets=["./style.css"],
)
# Add some elements
page.add(
Heading1(
"Heading",
classes=Classes("title", "large"),
attributes=Attributes({"id": "title"}),
),
Paragraph(
"Some text",
attributes=Attributes({"style": "color: red;"}),
),
)
# Save the page
page.save("sample_page.html")
Background
The balisage
package was originally created to generate hyper-customizable HTML tables from pandas
dataframes, since DataFrame.to_html()
has very limited styling options. That said, it has since been expanded to include a wider range of HTML elements with support for more advanced features such as Pythonic ways to add classes and attributes.
Admittedly, other tools like balisage
exist, and many are more mature. However, its creation provided an interesting opportunity to practice Python packaging and unit testing, as well as the ability to learn modern tools, including uv
, ruff
, and pytest
. Additionally, it was the perfect way to implement CI pipelining using GitHub Actions.
Lastly, the package's name balisage is the French word for markup (as in markup languages); the word's true context may have been lost in translation, but it sounds fun, unique, and leaves room to expand to other markup languages in the future.
Future improvements
Some ideas for future improvements, from highest priority to lowest priority:
- Add the rest of the HTML elements
- Version 1.0 will include the most common elements
- Refactor unit tests to use a class-based approach
- Primarily for readability and structure
- Improve documentation (docstrings, web docs, etc.)
- Validate that user-specified attributes are valid HTML attributes
- The current philosophy is that it is the user's responsibility to validate their attributes
- However, attribute validation may be desirable, especially since classes are already validated
- Expand to other markup languages, such as Markdown
Authors
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file balisage-0.4.5.tar.gz
.
File metadata
- Download URL: balisage-0.4.5.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d57355dc60cce991bba3dc6c7d179147d2dfd9c2f6b01a91e9a9eb33030ffa2a
|
|
MD5 |
fae35e7ba0b8c46cb0c12a363cdbf469
|
|
BLAKE2b-256 |
53f885f67bf1c840818f8f1a7c94971f060f15cbf03a45b4fd2e84dee9a2acb4
|
File details
Details for the file balisage-0.4.5-py3-none-any.whl
.
File metadata
- Download URL: balisage-0.4.5-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
15a55a81c9c71a9e1385614b93b50ac8f79749edc63c4c304471e6e9b85c4e57
|
|
MD5 |
efe7bf3c0921769b70fd032f5dfd127a
|
|
BLAKE2b-256 |
fc81acbe4d9aabba7e7b421f8f1cc8931fa1832d88bc28441e978543290717ed
|