Install & Compatibility
Where this runs
tested against v0.3.4 · 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 0.056s · 29.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 2.2s · import 0.054s · 30MB
28MB installed
● package 28MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
svgutils
✓ import svgutils
✗ import svglib
svglib is a different library for reading SVG files.
SVGFigure
✓ from svgutils.compose import SVGFigure
✗ from svgutils import SVGFigure
SVGFigure is in the compose module.
Create a simple SVG with text and a line.
from svgutils.compose import SVGFigure, Element, Text, Line
# Create a new SVG figure
fig = SVGFigure(width=200, height=200)
# Add a text element
txt = Text('Hello, svgutils!', x=10, y=50, size=16, color='black')
# Add a line
line = Line(x1=10, y1=10, x2=100, y2=100, stroke='red')
# Attach elements to figure
fig.append(txt)
fig.append(line)
# Save to file
fig.save('output.svg')
Errors
Common errors & fixes
ImportError: cannot import name 'SVGFigure' from 'svgutils'
Incorrect import path. SVGFigure is in svgutils.compose.
fixUse from svgutils.compose import SVGFigure
AttributeError: 'NoneType' object has no attribute 'write'
Attempting to save a figure with no attached elements or invalid path.
fixEnsure the figure has at least one element appended and the output path is writable.
lxml.etree.XMLSyntaxError: Start tag expected, ...
Opening a non-XML file or malformed SVG.
fixVerify the input SVG file is well-formed XML. Use fromstring() with proper encoding.
Upgrade
Version history
0.3.4latest on PyPI · released Feb 10, 2021
Audit
Dependencies
lxmlrequiredXML parsing and manipulation