Install & Compatibility
Where this runs
tested against v2.2.0 · 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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 1.068s · 58.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.8s · import 1.010s · 60MB
58MB installed
● package 58MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
svg2rlg
✓ from svglib.svglib import svg2rlg
Primary function to convert an SVG file into a ReportLab Drawing object.
renderPDF
✓ from reportlab.graphics import renderPDF
Used for rendering ReportLab Drawing objects to PDF. Part of the 'reportlab' dependency.
renderPM
✓ from reportlab.graphics import renderPM
Used for rendering ReportLab Drawing objects to pixelmap (e.g., PNG). Part of the 'reportlab' dependency.
This quickstart demonstrates how to convert an SVG file to a ReportLab Drawing object, and then render it to both PDF and PNG formats. It requires a local 'example.svg' file to run, which is created dynamically in the code.
import os
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPDF, renderPM
# Create a dummy SVG file for demonstration
dummy_svg_content = '''
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
<rect x="10" y="10" width="180" height="180" fill="blue" stroke="black" stroke-width="3" />
<text x="50" y="100" font-family="sans-serif" font-size="20" fill="white">Hello svglib!</text>
</svg>
'''
with open("example.svg", "w") as f:
f.write(dummy_svg_content)
# Convert SVG to ReportLab Drawing object
drawing = svg2rlg("example.svg")
# Render to PDF
renderPDF.drawToFile(drawing, "example.pdf")
print("Generated example.pdf")
# Render to PNG
renderPM.drawToFile(drawing, "example.png")
print("Generated example.png")
# Clean up dummy file (optional)
os.remove("example.svg")
svg2pdf --version
Debug
Known issues
breakingOlder versions (prior to 0.9.4) were vulnerable to XML External Entity (XXE) Injection. Ensure you are using a patched version (0.9.4 or higher) to avoid security risks.fixUpgrade `svglib` to version `0.9.4` or newer: `pip install --upgrade svglib`.
affects: <0.9.4
gotchaSvglib does not support all SVG features due to limitations in the underlying ReportLab library. Specifically, color gradients, patterns, markers, clipping paths (beyond single paths), `textPath`, and `ForeignObject` elements are not supported. This can lead to unexpected rendering or missing elements in the output.fixSimplify your SVG files to avoid unsupported features or use alternative conversion libraries if full SVG fidelity is required for these specific elements.
affects: All versions
gotchaCSS `@import` rules within SVG stylesheets are ignored by `svglib`. While versions 1.5.0+ avoid crashing, the imported styles will simply not be applied.fixEmbed CSS directly within the SVG file using `<style>` tags or inline styles instead of using `@import` rules.
affects: All versions
breakingUpgrading `svglib` from very old versions (e.g., 0.8.1 to 0.9.2) could lead to SVG images being rendered in black and white or encountering font errors in the output PDF.fixTest rendering thoroughly after upgrading. If issues occur, consult the `svglib` GitHub issues or consider adjusting `reportlab` versions. The current stable `1.x` versions have improved compatibility.
affects: e.g., 0.9.0 - 0.9.3 when upgrading from <0.9.0
deprecatedSupport for Python 3.8 was dropped in `svglib` 1.6.0. Users on older Python environments will need to use an earlier `svglib` version.fixUpgrade to Python 3.9+ or pin `svglib` to `<1.6.0` if Python 3.8 support is required (e.g., `pip install 'svglib<1.6.0'`).
affects: 1.6.0 and later
Errors
Common errors & fixes
command not found: svg2pdf
The `svg2pdf` command-line script is not in your system's PATH, often because a virtual environment is not activated or the script's installation location is not recognized.
fixActivate your virtual environment (if used) or run the script using `python -m svglib.svg2pdf input.svg output.pdf`.
ImportError: cannot import name 'svg2rlg' from 'svglib'
The `svg2rlg` function is located within the `svglib.svglib` submodule, not directly under the top-level `svglib` package.
fixThe correct import statement is `from svglib.svglib import svg2rlg`.
AttributeError: 'Drawing' object has no attribute 'save'
The `Drawing` object returned by `svg2rlg` is a ReportLab graphic representation; it does not have a direct `save` method for file output.
fixUse a ReportLab renderer like `reportlab.graphics.renderPDF.drawToFile` or a `reportlab.pdfgen.canvas.Canvas` to write the drawing to a file.
```python
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPDF
drawing = svg2rlg('input.svg')
renderPDF.drawToFile(drawing, 'output.pdf')
``` error: command 'gcc' failed with exit status 1
This error occurs during `pip install svglib` because `svglib` depends on `lxml`, which is a C extension and requires a C compiler (like `gcc`) to be available on your system.
fixInstall the necessary build tools and C compiler for your operating system (e.g., `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS, or Visual C++ Build Tools on Windows) before installing `svglib`.
Upgrade
Version history
2.2.0latest on PyPI · released Aug 14, 2026
Audit
Dependencies
reportlabrequiredCore dependency for converting SVG to ReportLab Drawing objects and rendering to various formats.
lxmlrequiredUsed for parsing and handling SVG CSS stylesheets.
cssselect2requiredUsed for a wider range of CSS selectors.
tinycss2requiredUsed for parsing CSS.