Skip to main content

Generate HTML using an intuitive Python interface.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

balisage-0.4.5.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

balisage-0.4.5-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

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

Hashes for balisage-0.4.5.tar.gz
Algorithm Hash digest
SHA256 d57355dc60cce991bba3dc6c7d179147d2dfd9c2f6b01a91e9a9eb33030ffa2a
MD5 fae35e7ba0b8c46cb0c12a363cdbf469
BLAKE2b-256 53f885f67bf1c840818f8f1a7c94971f060f15cbf03a45b4fd2e84dee9a2acb4

See more details on using hashes here.

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

Hashes for balisage-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 15a55a81c9c71a9e1385614b93b50ac8f79749edc63c4c304471e6e9b85c4e57
MD5 efe7bf3c0921769b70fd032f5dfd127a
BLAKE2b-256 fc81acbe4d9aabba7e7b421f8f1cc8931fa1832d88bc28441e978543290717ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page