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.
pip install brancaVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade your Python interpreter to 3.8 or newer.
Avoid direct access to `Element._env`. Use public methods or properties for element manipulation. If highly custom Jinja2 templating is needed, it might require a different approach or contributing to Branca's public API.
Update any custom code that extracts HTML content from Branca elements to look for the `srcdoc` attribute instead of `data-html`.
Review your codebase for any direct calls to `branca.utilities.split_six` and remove or replace them with equivalent standard Python functionality.
If your application relies on predicting element IDs for JavaScript, consider using the new customization options to explicitly define IDs or ensure your JS is resilient to varying ID formats.
Install the branca package using pip: `pip install branca`
For PyInstaller, ensure the `branca` package's templates and JSON files are explicitly included in the spec file using `datas`: `datas=[('.\venv\Lib\site-packages\branca\*.json','branca'), ('.\venv\Lib\site-packages\branca\templates','templates')]` (adjust path as needed). Alternatively, some users modify `branca/element.py` to use `jinja2.FileSystemLoader` with a dynamic path.Instead of accessing predefined palettes as attributes, import `LinearColormap` or `StepColormap` directly and construct the colormap with a list of colors. For example: `from branca.colormap import LinearColormap; colormap = LinearColormap(colors=['red', 'green', 'blue'], vmin=0, vmax=1)`.
Specify the `width` parameter of `branca.element.IFrame` using pixel values (e.g., `width=500`) instead of percentages (e.g., `width='100%'`) to ensure consistent rendering. You may also need to adjust the `height` and `ratio` parameters accordingly.
Upgrade both `folium` and `branca` to their latest versions, as this specific issue has been addressed in newer releases. If the problem persists, ensure the `branca.colormap` is correctly configured with `vmin` and `vmax` that align with your image data.