Registry / devops / svg-py

svg-py

JSON →
library1.10.0pypypi✓ verified 84d ago

svg-py is a Python library for creating and manipulating SVG documents. It provides a fluent API to build SVG elements, supports attributes, styling, and inline CSS. Compatible with Python 3.7+, current version 1.10.0, released on a rolling cadence.

pip install svg-py
INSTALL
IMPORT
SIG · SVG-PY
S
svg-py
devopspythonv1.10.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SVG
from svg import SVG
Correct import for the main SVG container element.
Rectangle
from svg import Rectangle
Import for rectangle elements.
Element
from svg import Element
Base class for all SVG elements.

Create a simple SVG with a rectangle and a circle, then save to file.

from svg import SVG, Rectangle, Circle, Line svg = SVG(width=200, height=200, viewBox='0 0 200 200') svg.add_element( Rectangle(x=10, y=10, width=100, height=100, fill='blue', stroke='black') ) svg.add_element( Circle(cx=50, cy=50, r=40, fill='red') ) svg.save('output.svg')
Debug
Known issues
breakingIn version 1.0.0, the entire API was rewritten. The old module structure (e.g., `from svg import SVG` instead of `from svg import SVG` — actually same, but internal classes changed). Ensure you are using the new Element-based API.
fix
Migrate to the new Element API: use `from svg import SVG, Element, Rectangle, etc.` and the builder pattern.
affects: <1.0.0
gotchaThe `SVG` object does not automatically set default attributes like `xmlns`. You must explicitly set `xmlns='http://www.w3.org/2000/svg'` if needed for standalone SVG files.
fix
Add `xmlns='http://www.w3.org/2000/svg'` when creating the SVG element or as attribute.
affects: all
deprecatedThe method `add` for adding child elements is deprecated in favor of `add_element`.
fix
Use `svg.add_element(child)` instead of `svg.add(child)`.
affects: >=1.5.0
gotchaElement attributes are case-sensitive (e.g., `viewBox` vs `viewbox`). Using incorrect casing may cause the SVG to not render properly.
fix
Always use exact attribute names as per SVG spec (e.g., `viewBox`, `clipPath`).
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'svg'
The library is not installed or installed incorrectly.
fix
Run `pip install svg-py` to install.
AttributeError: module 'svg' has no attribute 'SVG'
Using an older version (<1.0.0) where the API was different, or importing from the wrong module.
fix
Upgrade to latest version: `pip install --upgrade svg-py`. Then use `from svg import SVG`.
TypeError: 'NoneType' object is not callable
Calling a method on an accidentally overwritten variable, e.g., using `svg = svg.add_element(...)` instead of `svg.add_element(...)`.
fix
Do not reassign the svg variable. Just call `svg.add_element(...)`.
Upgrade
Version history
1.10.0latest on PyPI · released Dec 28, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
13
Resources
svg-py — pip install svg-py · libregistry