How to Install and Get Started with Pygal
Updated
Pygal is a Python charting library that produces SVG charts, and the documented way to get running is short: install the package, create a chart object, pass in your data, and call render(). The official documentation (pygal 3.0.5) shows the whole pattern in one line — pygal.Bar()(1, 3, 3, 7)(1, 6, 6, 4).render() — which tells you the library is designed so that a usable chart needs no configuration beyond your data.
Installing Pygal
The documentation lists Installing as a top-level section alongside Documentation, Contributing, Changelog, and API. The standard Python package workflow applies:
pip install pygal
If you work in an isolated environment, install it inside a virtual environment so the dependency stays scoped to that project. The docs also maintain a Contributing page, which is where you'd look if you want to install from source rather than from a package index.
Your First Chart
The documented example is the clearest starting point:
import pygal
pygal.Bar()(1, 3, 3, 7)(1, 6, 6, 4).render()
Reading it left to right:
pygal.Bar()creates an empty bar chart object.- The first call,
(1, 3, 3, 7), adds one data series. - The second call,
(1, 6, 6, 4), adds a second series. .render()returns the chart as an SVG string.
Two things are worth noting about this API. First, calling the chart object is how you add data — there is no separate add() step in the documented example. Second, render() returns a string, so you decide what to do with it: write it to a .svg file, embed it in an HTML page, or return it from a web view.
Choosing a Chart Type
Pygal exposes chart types as classes. The documentation's own example uses Bar, and the API Index and Module Index list the rest. The pattern is identical across types — swap the class name and keep the same call-and-render flow:
import pygal
chart = pygal.Line()
chart.add('Series A', [1, 3, 3, 7])
chart.add('Series B', [1, 6, 6, 4])
chart.render()
Both the chained form and the explicit add() form work; use whichever reads more clearly in your code.
Where to Go Next
The documentation is organized into these sections:
| Section | What it covers |
|---|---|
| Documentation | Overview and usage guidance |
| Installing | Getting the package onto your system |
| Contributing | Working on Pygal itself |
| Changelog | Version history |
| API Index / Module Index | Reference for classes and methods |
Start with Documentation for usage patterns, and keep API Index open when you need the exact signature of a chart type or option. Pygal is a Kozea project, and the docs are built with Sphinx.
Common Sticking Points
- Nothing renders to a file automatically.
render()gives you a string; saving or serving it is your job. - Data goes in as sequences. The documented example passes plain tuples, so lists and other sequences follow the same path.
- Check your chart type exists. If a class name isn't in the API Index, it isn't part of the documented surface.
- Version matters. The documentation covers pygal 3.0.5; behavior described there may differ from older releases, so confirm your installed version if something doesn't match.