Registry / data / pygal
library3.1.3pypypi✓ verified 24d ago

Pygal is an open-source Python library for creating dynamic and interactive SVG (Scalar Vector Graphics) charts. It is known for its ease of use, allowing developers to generate high-quality, scalable visualizations with minimal code. Pygal is currently at version 3.1.0 and maintains an active development and release cadence, with recent updates focusing on fixes and minor enhancements.

pip install pygal
INSTALL
IMPORT
SIG · PYGAL
P
pygal
datapythonv3.1.3
Install
1.8s avg
Import
170ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.1.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.180s · 19.1MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.8s · import 0.159s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Bar
import pygal chart = pygal.Bar()
from pygal import Bar
While 'from pygal import Bar' works, the official documentation and common examples prefer importing 'pygal' and accessing chart types as attributes (e.g., pygal.Bar()). This aligns with the library's design for easily creating different chart types.
Style
from pygal.style import Style

This quickstart demonstrates how to create a simple bar chart with two data series and render it to an SVG file. It also shows the (commented out) option to render directly in a web browser, which requires the `lxml` optional dependency.

import pygal # Create a Bar chart object bar_chart = pygal.Bar() # Add data series bar_chart.add('Fibonacci', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]) bar_chart.add('Prime', [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]) # Render the chart to an SVG file bar_chart.render_to_file('bar_chart.svg') # To display in a browser (requires lxml installed) # bar_chart.render_in_browser() print("Chart rendered to bar_chart.svg")
pygal --version
Debug
Known issues
gotchaWhen embedding Pygal SVGs directly into HTML, custom fonts defined in styles might not apply correctly. The browser might not fetch external stylesheets linked within the SVG if it's not embedded via an `<embed>` or `<iframe>` tag.
fix
Embed the SVG using `<embed type="image/svg+xml" src="your_chart.svg">` or render the chart directly into a Flask/Django response, which typically handles embedding correctly. Alternatively, manually add the font stylesheet to your main HTML file.
affects: All versions
gotchaCharts rendered in environments like Jupyter Notebooks might display raw SVG/XML metadata instead of the visual chart. This is because the notebook environment might not automatically interpret raw SVG strings as renderable content.
fix
Use `chart.render_data_uri()` to get a base64 encoded URI, which can then be displayed in Jupyter using `IPython.display.HTML`. For file output, use `render_to_file()` and open the `.svg` file in a web browser. For interactive display, `render_in_browser()` (requires `lxml`) can be used, but this will open a new browser tab.
affects: All versions
breakingPygal 3.0.0 removed the `Iterable` import from `collections` (which was deprecated in Python 3.8 and removed in Python 3.10) and changed internal dependencies like `pytest` attributes and `pkg_resources` usage. Code relying on older Python versions (pre-3.8) or specific `pytest` internals might encounter issues.
fix
Ensure you are using Python 3.8 or newer. Update your development environment to use recent versions of `pytest` if you are running tests against Pygal's internals. Migrate any custom code that might have indirectly relied on these deprecated Python features or library internals.
affects: >=3.0.0
gotchaRendering PNG output requires the `cairosvg` library. If `cairosvg` is not installed, calls to `render_to_png()` will raise an error.
fix
Install `cairosvg` separately (`pip install cairosvg`) or install Pygal with the `[all]` extra: `pip install "pygal[all]"`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pygal'
The pygal library is not installed in the Python environment being used, or the Python interpreter configured in your IDE (like VS Code or PyCharm) is not the one where pygal was installed.
fix
Ensure pygal is installed for the correct Python environment using `pip install pygal`. If using an IDE, verify that the project interpreter is set to the environment where pygal is installed.
AttributeError: 'module' object has no attribute 'Bar'
This error often occurs when your Python script file is named `pygal.py`. When you `import pygal`, Python imports your script instead of the installed pygal library, and your script does not have a 'Bar' attribute.
fix
Rename your Python script file to something other than `pygal.py` (e.g., `my_chart.py`) to avoid shadowing the pygal library.
AttributeError: 'NoneType' object has no attribute 'decode'
This error typically arises when data points or labels passed to a pygal chart (especially in lists or dictionaries) contain `None` values, but pygal expects string or numeric types to render them. The `decode` method is attempted on a `None` object, which doesn't possess it.
fix
Filter out or replace `None` values in your data with appropriate empty strings or default numeric values before passing them to pygal chart methods like `add()` or when setting labels.
Upgrade
Version history
3.1.3latest on PyPI · released Jun 18, 2026
Audit
Dependencies
python-importlib-metadatarequiredCore dependency for metadata handling.
python-setuptoolsrequiredCore dependency for package distribution and setup.
cairosvgoptionalOptional, required for PNG output. If not installed, PNG rendering will fail.
lxmloptionalOptional, provides faster XML parsing and enables `render_in_browser()` functionality and XML output through lxml instead of xml.etree. If not installed, some rendering options may be unavailable or slower.
Agent activity
15 hits · last 30 days
node
10
Resources
pygal — pip install pygal · libregistry