Registry / serialization / svgutils

svgutils

JSON →
library0.3.4pypypi✓ verified 85d ago

svgutils is a Python library for editing and manipulating SVG files. It allows you to create, transform, and combine SVG elements programmatically. Current version is 0.3.4. The library is in maintenance mode with infrequent releases.

pip install svgutils
INSTALL
IMPORT
SIG · SVGUTILS
S
svgutils
serializationpythonv0.3.4
Install
2.2s avg
Import
55ms
Disk
28MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.056s · 29.8MB
glibc
py 3.103.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')
Debug
Known issues
deprecatedsvgutils.compose module is considered stable but older transform methods may be deprecated. Check for deprecation warnings.
fix
Use the compose API where possible; refer to examples on GitHub.
affects: <=0.3.4
gotchaElement positions (x, y) are in SVG user units, not pixels. Scaling depends on viewBox.
fix
Set viewBox explicitly via SVGFigure attributes to control coordinate space.
affects: all
gotchaAll elements must be appended to a figure before saving. Attaching elements after save does not update file.
fix
Call fig.append() before fig.save().
affects: all
breakingPython 2 support was dropped in version 0.3.0. Python 3.6+ required.
fix
Upgrade to Python 3.6 or later.
affects: >=0.3.0
Errors
Common errors & fixes
ImportError: cannot import name 'SVGFigure' from 'svgutils'
Incorrect import path. SVGFigure is in svgutils.compose.
fix
Use from svgutils.compose import SVGFigure
AttributeError: 'NoneType' object has no attribute 'write'
Attempting to save a figure with no attached elements or invalid path.
fix
Ensure 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.
fix
Verify 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
Agent activity
20 hits · last 30 days
node
16
Amazon
1
Resources
svgutils — pip install svgutils · libregistry