{"id":5395,"library":"pygal","title":"Pygal","description":"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.","status":"active","version":"3.1.0","language":"en","source_language":"en","source_url":"https://github.com/Kozea/pygal","tags":["charting","svg","data visualization","interactive graphs"],"install":[{"cmd":"pip install pygal","lang":"bash","label":"Install stable version"},{"cmd":"pip install \"pygal[all]\"","lang":"bash","label":"Install with all optional dependencies"}],"dependencies":[{"reason":"Core dependency for metadata handling.","package":"python-importlib-metadata","optional":false},{"reason":"Core dependency for package distribution and setup.","package":"python-setuptools","optional":false},{"reason":"Optional, required for PNG output. If not installed, PNG rendering will fail.","package":"cairosvg","optional":true},{"reason":"Optional, 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.","package":"lxml","optional":true}],"imports":[{"note":"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.","wrong":"from pygal import Bar","symbol":"Bar","correct":"import pygal\nchart = pygal.Bar()"},{"symbol":"Style","correct":"from pygal.style import Style"}],"quickstart":{"code":"import pygal\n\n# Create a Bar chart object\nbar_chart = pygal.Bar()\n\n# Add data series\nbar_chart.add('Fibonacci', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34])\nbar_chart.add('Prime', [2, 3, 5, 7, 11, 13, 17, 19, 23, 29])\n\n# Render the chart to an SVG file\nbar_chart.render_to_file('bar_chart.svg')\n\n# To display in a browser (requires lxml installed)\n# bar_chart.render_in_browser()\n\nprint(\"Chart rendered to bar_chart.svg\")","lang":"python","description":"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."},"warnings":[{"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.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Charts 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Pygal 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.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Install `cairosvg` separately (`pip install cairosvg`) or install Pygal with the `[all]` extra: `pip install \"pygal[all]\"`.","message":"Rendering PNG output requires the `cairosvg` library. If `cairosvg` is not installed, calls to `render_to_png()` will raise an error.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}