Branca: HTML+JS Generation

0.8.2 · active · verified Thu Apr 09

Branca is a Python library designed to generate complex HTML and JavaScript pages from Python objects. It serves as a low-level base for other visualization libraries, most notably Folium, providing core components like `Figure`, `Element`, and `Colormap`. The current version is 0.8.2, and it maintains an active development cycle with regular patch and minor releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a `Figure` object, add external JavaScript links and custom HTML `Element`s to it, and then render the entire structure to an HTML string or save it to a file. It showcases Branca's role as a low-level HTML/JS generation utility.

from branca.element import Figure, Element, JavascriptLink

# Create a new Figure object to hold elements
f = Figure(width="100%", height="400px")

# Add a JavaScript library link (e.g., jQuery) to the figure's head
f.add_child(JavascriptLink("https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"))

# Add a simple HTML element to the figure's body
f.add_child(Element("<h1>Hello from Branca!</h1><p>This is a basic HTML element generated by Python.</p>"))

# Render the figure to an HTML string
html_output = f.render()
print(html_output[:500]) # Print the first 500 characters of the generated HTML

# To save to a file (uncomment to run):
# f.save("branca_example.html")

view raw JSON →