Skip to main content
balisage Logo

Use Python to build HTML.


GitHub Last Commit GitHub License PyPI Page PyPI Downloads GitHub Actions Workflow Status Codecov Test Coverage


balisage is a Python package that allows you to generate HTML using an intuitive and easy-to-use interface.

balisage Section Divider balisage Section Divider

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
balisage Section Divider

Authors

Release files for balisage 0.4.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for balisage 0.4.5
File Size Uploaded
balisage-0.4.5.tar.gz 17.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for balisage 0.4.5
File Interpreter ABI Platform
balisage-0.4.5-py3-none-any.whl Python 3 none any Details

Total release size: 37.2 kB

Release files / balisage-0.4.5.tar.gz

Download URL balisage-0.4.5.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d57355dc60cce991bba3dc6c7d179147d2dfd9c2f6b01a91e9a9eb33030ffa2a
BLAKE2b-256 checksum
How to use checksums
53f885f67bf1c840818f8f1a7c94971f060f15cbf03a45b4fd2e84dee9a2acb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Release files / balisage-0.4.5-py3-none-any.whl

Download URL balisage-0.4.5-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15a55a81c9c71a9e1385614b93b50ac8f79749edc63c4c304471e6e9b85c4e57
BLAKE2b-256 checksum
How to use checksums
fc81acbe4d9aabba7e7b421f8f1cc8931fa1832d88bc28441e978543290717ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Release history Release notifications | RSS feed

This release

0.4.5 This release

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.2.3

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page