Registry / serialization / svgpathtools

svgpathtools

JSON →
library1.7.2pypypi✓ verified 85d ago

svgpathtools is a Python library (version 1.7.2) for manipulating and analyzing SVG Path objects and Bézier curves. It offers functions to read, write, and display SVG files, convert Bézier segments to polynomials, compute tangents, curvature, intersections, and perform various geometric transformations. It is actively maintained with releases as needed.

pip install svgpathtools
INSTALL
IMPORT
SIG · SVGPATHTOOLS
S
svgpathtools
serializationpythonv1.7.2
Install
7.4s avg
Import
1828ms
Disk
231MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.7.2 · 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.920 runs
installs and imports cleanly · install 0.0s · import 1.877s · 231.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 7.4s · import 1.778s · 223MB
231MB installed
● package 231MB
Code
Verified usage

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

Path
from svgpathtools import Path
Main class for composite paths.
Line, QuadraticBezier, CubicBezier, Arc
from svgpathtools import Line, QuadraticBezier, CubicBezier, Arc
Classes for individual path segments.
svg2paths
from svgpathtools import svg2paths
Function to read paths from an SVG file.
wsvg
from svgpathtools import wsvg
Function to write paths to an SVG file.
Path
from svgpathtools import Path
from svg.path import Path
While `svgpathtools` was inspired by `svg.path`, its classes and functions are part of the `svgpathtools` namespace. Direct imports from `svg.path` will result in different objects and methods.

This quickstart demonstrates how to read paths from an SVG file, modify an existing path (e.g., scaling it), create a new path using segment classes (Line, CubicBezier), and then write all paths to a new SVG file. Coordinates are handled as complex numbers (x + yj).

from svgpathtools import svg2paths, wsvg, Path, Line, CubicBezier import os # Create a dummy SVG file for demonstration with open('example.svg', 'w') as f: f.write('<svg width="200" height="200">') f.write('<path d="M10 10 L100 10 L100 100 L10 100 Z" fill="blue"/>') f.write('</svg>') # 1. Read paths from an existing SVG file paths, attributes = svg2paths('example.svg') print(f"Read {len(paths)} path(s) from example.svg") # 2. Manipulate a path (e.g., scale the first path) if paths: original_path = paths[0] # Scale the path by 0.5 scaled_path = original_path.scaled(0.5) paths[0] = scaled_path print(f"Scaled the first path. New length: {scaled_path.length():.2f}") # 3. Create a new path programmatically new_segment1 = Line(start=10+10j, end=50+100j) new_segment2 = CubicBezier(start=50+100j, control1=150+50j, control2=50+150j, end=150+100j) new_path = Path(new_segment1, new_segment2) # Add the new path to the list and assign attributes paths.append(new_path) attributes.append({'fill': 'red', 'stroke': 'black', 'stroke-width': '2'}) # 4. Write the modified and new paths to a new SVG file wsvg(paths, attributes=attributes, filename='output.svg', openinbrowser=False) print("Modified paths written to output.svg") # Clean up dummy file (optional) os.remove('example.svg') # os.remove('output.svg') # Uncomment to remove output file after inspection
Debug
Known issues
gotchaThe `svg2paths()` function currently ignores SVG group (<g>) transformations when parsing files. Paths inside groups will be read without the parent group's transformations applied.
fix
Manually apply transformations to paths after reading, or use the experimental `Document` class for improved I/O which might handle transformations better (check its documentation). See GitHub issue #16 for discussion and manual transformation examples.
affects: All versions up to 1.7.2
gotchaSome functionality within `svgpathtools`, particularly concerning discontinuous `Path` objects, has not been fully tested and might lead to unexpected behavior.
fix
For potentially discontinuous paths, consider using the `Path.continuous_subpaths()` method to break them into continuous components as a workaround.
affects: All versions up to 1.7.2
gotchaThe `Path.scaled()` method might produce visual artifacts or unexpected 'cavities' in paths when using very small scaling factors (e.g., below ~0.45). This could be due to internal segmentation or precision issues.
fix
If encountering issues with small scaling factors, consider applying scaling to individual path segment parameters or control points manually, or scaling the SVG in a graphics editor before processing.
affects: All versions up to 1.7.2
deprecatedThe `svg2paths` function's argument signature in older installed versions (e.g., via `pip3`) might not perfectly match the latest documentation or GitHub source, particularly regarding `convert_circles_to_paths` and `convert_ellipses_to_paths` arguments.
fix
Ensure you are using the latest version of `svgpathtools`. If discrepancies persist, consider installing directly from the GitHub source if comfortable, or check the `svg_to_paths.py` source file for the exact function signature on your installed version.
affects: Older pip installations prior to 1.6.0, specific to how `setup.py` was handled.
Errors
Common errors & fixes
could not convert string to float: 's'
This error, or similar ones like 'list index out of range', often occurs when `svgpathtools.parse_path()` attempts to parse an SVG path `d` attribute string that is malformed or contains unexpected characters/commands. This can happen with complex SVG exports from graphic design software (e.g., Inkscape) that might use non-standard or subtly incorrect syntax for path commands.
fix
Validate the SVG `d` string against the official SVG Path Data specification. Simplify the path in the originating software, or manually inspect and correct the `d` attribute string. Ensure all path commands (M, L, C, A, Z, etc.) are correctly capitalized (for absolute coordinates) or lowercase (for relative coordinates) and have the correct number of parameters.
SVG groups are ignored. Especially transformations acting on the paths inside the group.
The `svg2paths()` function processes path elements directly and does not automatically apply transformations defined on parent `<g>` (group) elements in the SVG document structure.
fix
After reading the paths using `svg2paths()`, you need to manually traverse the SVG's DOM (e.g., using `xml.etree.ElementTree`) to identify parent group transformations and apply them to the respective child paths. The `Document` class (experimental) aims to provide a higher-level API that might simplify this in the future.
Upgrade
Version history
1.7.2latest on PyPI · released Nov 30, 2025
Audit
Dependencies
numpyrequiredRequired for numerical operations, especially vector inputs and geometric calculations.
svgwriterequiredRequired for writing SVG files using `wsvg()` and for rendering path data.
scipyoptionalOptional, but recommended for performance, particularly for integration-related tasks.
Agent activity
53 hits · last 30 days
node
46
OpenAI (training)
1
Resources