{"id":1954,"library":"branca","title":"Branca: HTML+JS Generation","description":"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.","status":"active","version":"0.8.2","language":"python","source_language":"en","source_url":"https://github.com/python-visualization/branca","tags":["html generation","visualization","jupyter","maps","templating"],"install":[{"cmd":"pip install branca","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for templating HTML and JavaScript content.","package":"Jinja2","optional":false}],"imports":[{"symbol":"Figure","correct":"from branca.element import Figure"},{"symbol":"Element","correct":"from branca.element import Element"},{"symbol":"JavascriptLink","correct":"from branca.element import JavascriptLink"},{"symbol":"LinearColormap","correct":"from branca.colormap import LinearColormap"},{"symbol":"StepColormap","correct":"from branca.colormap import StepColormap"}],"quickstart":{"code":"from branca.element import Figure, Element, JavascriptLink\n\n# Create a new Figure object to hold elements\nf = Figure(width=\"100%\", height=\"400px\")\n\n# Add a JavaScript library link (e.g., jQuery) to the figure's head\nf.add_child(JavascriptLink(\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js\"))\n\n# Add a simple HTML element to the figure's body\nf.add_child(Element(\"<h1>Hello from Branca!</h1><p>This is a basic HTML element generated by Python.</p>\"))\n\n# Render the figure to an HTML string\nhtml_output = f.render()\nprint(html_output[:500]) # Print the first 500 characters of the generated HTML\n\n# To save to a file (uncomment to run):\n# f.save(\"branca_example.html\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python interpreter to 3.8 or newer.","message":"Python 3.7 support was dropped in Branca v0.7.2. Users on Python 3.7 or older must upgrade their Python environment or stick to Branca <0.7.2.","severity":"breaking","affected_versions":">=0.7.2"},{"fix":"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.","message":"The internal `_env` instance attribute was removed from the `Element` class in v0.7.1. Direct access or manipulation of this attribute will cause `AttributeError`.","severity":"breaking","affected_versions":">=0.7.1"},{"fix":"Update any custom code that extracts HTML content from Branca elements to look for the `srcdoc` attribute instead of `data-html`.","message":"In v0.5.0, `Element` changed how it stores HTML content, moving from `data-html` to `srcdoc`. If you have custom parsers or scripts that relied on the `data-html` attribute to extract content, they will break.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Review your codebase for any direct calls to `branca.utilities.split_six` and remove or replace them with equivalent standard Python functionality.","message":"The `split_six` utility function was removed in v0.7.2. While primarily an internal utility, if any custom code used it, it will no longer be available.","severity":"deprecated","affected_versions":">=0.7.2"},{"fix":"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.","message":"Starting with v0.8.2, `Element` ID generation became customizable. While this offers flexibility, if you relied on the exact default ID generation pattern for JavaScript interactions in previous versions, you might encounter subtle changes or unexpected behavior if IDs change slightly.","severity":"gotcha","affected_versions":">=0.8.2"}],"env_vars":null,"search_vec":"'0.8.2':48 'activ':53 'base':28 'branca':1,5 'colormap':43 'complex':13 'compon':38 'core':37 'current':45 'cycl':55 'design':10 'develop':54 'element':41 'figur':40 'folium':35 'generat':4,12,63 'html':2,14,62 'javascript':16 'js':3 'jupyt':65 'level':27 'librari':9,32 'like':39 'low':26 'low-level':25 'maintain':51 'map':66 'minor':60 'notabl':34 'object':20 'page':17 'patch':58 'provid':36 'python':8,19 'regular':57 'releas':61 'serv':22 'templat':67 'version':46 'visual':31,64","created_at":"2026-04-09T18:37:16.307995+00:00","updated_at":"2026-04-16T00:54:05.714059+00:00","problems":[{"fix":"Install the branca package using pip: `pip install branca`","cause":"The 'branca' package is not installed in the Python environment where the code is being executed, or the environment is not correctly configured.","error":"ModuleNotFoundError: No module named 'branca'"},{"fix":"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.","cause":"This error often occurs when bundling Python applications with tools like Nuitka or PyInstaller, as `jinja2.PackageLoader` (used by branca) may fail to locate templates within the generated executable.","error":"ValueError: The 'branca' package was not installed in a way that PackageLoader understands."},{"fix":"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)`.","cause":"This error typically occurs when trying to access a predefined colormap palette by an incorrect attribute name or when using an older, deprecated method for generating colormaps.","error":"AttributeError: '_LinearColormaps' object has no attribute 'gnuplot'"},{"fix":"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.","cause":"When using `branca.element.IFrame` within visualization libraries like Folium, percentage-based width values might not be correctly interpreted by the rendering environment or browser, leading to incorrect sizing.","error":"Branca HTML iFrame width in percentage not working"},{"fix":"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.","cause":"Older versions of Folium or Branca might have compatibility issues where `folium.raster_layers.ImageOverlay` does not correctly process or display `branca.colormap.LinearColormap` objects.","error":"Issue using branca colormap with folium.raster_layers.ImageOverlay"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.8.2","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/python-visualization/branca","docs":null,"changelog":null,"pypi":"https://pypi.org/project/branca/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","data","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}