Registry / serialization / svg-path

svg-path

JSON →
library7.1pypypi✓ verified 23d ago

svg.path is a collection of objects that implement the different path commands in SVG, and a parser for SVG path definitions. It provides classes for various path segments (Line, Arc, CubicBezier, QuadraticBezier) and a `Path` object to collect them. As of version 7.0, it's actively maintained and frequently updated to reflect improvements and address edge cases in SVG path parsing.

pip install svg.path
INSTALL
IMPORT
SIG · SVG-PATH
S
svg-path
serializationpythonv7.1
Install
1.6s avg
Import
21ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.1 · 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.022s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.020s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

Path
from svg.path import Path
Line
from svg.path import Line
Arc
from svg.path import Arc
CubicBezier
from svg.path import CubicBezier
QuadraticBezier
from svg.path import QuadraticBezier
Close
from svg.path import Close
parse_path
from svg.path import parse_path

This quickstart demonstrates how to parse an SVG path string into a Path object and iterate through its segments. It also shows how to construct a path programmatically using segment objects like Line and Arc. Note that `svg.path` uses complex numbers for coordinates.

from svg.path import parse_path, Path, Line, Arc import cmath # For complex numbers used by svg.path # Parse an SVG path string path_data = "M 10 10 L 100 10 L 50 50 Z" path = parse_path(path_data) print(f"Path has {len(path)} segments.") for i, segment in enumerate(path): print(f"Segment {i}: {type(segment).__name__} from {segment.start} to {segment.end}") # Example: Get a point along the segment if hasattr(segment, 'point'): mid_point = segment.point(0.5) print(f" Midpoint: ({mid_point.real:.2f}, {mid_point.imag:.2f})") # Construct a path programmatically p = Path([ Line(start=cmath.rect(1, cmath.pi/2), end=cmath.rect(10, cmath.pi/2)), # Example using complex numbers Line(start=(10+0j), end=(10+50j)), Arc(start=(10+50j), radius=(20,20), rotation=0, large_arc=True, sweep=True, end=(30+70j)) ]) print(f"\nProgrammatic path has {len(p)} segments.")
Debug
Known issues
breakingIn version 7.0, the `Move` class was reclassified as a `PathSegment` for type annotation consistency. If you were using `isinstance()` to check for drawing commands (i.e., expecting `Move` *not* to be a `PathSegment`), your code will break.
fix
Adjust `isinstance()` checks to explicitly exclude `Move` segments if only drawing commands are desired (e.g., `isinstance(segment, PathSegment) and not isinstance(segment, Move)`).
affects: >=7.0
breakingIn version 4.0, the `Path` object no longer has a `closed` attribute.
fix
Review code that accessed `path.closed`. If the intention was to check for a `Close` command at the end of a subpath, you might need to iterate through segments or reconsider the logic based on the SVG specification.
affects: >=4.0
gotchaFor `CubicBezier` and `Arc` segments, setting `min_depth` to 0 (the recursion depth for approximation) can lead to inaccurate representations, especially for `CubicBezier` where it might approximate to a straight line. The default value is 5.
fix
Avoid setting `min_depth=0` for `CubicBezier` and `Arc` unless a simplified, possibly linear, approximation is explicitly desired. Use the default or a higher value for accuracy.
affects: All versions
gotchaSVG path data can use implicit commands (e.g., `M 10 20 30 40` implies `M 10 20 L 30 40`). The parser handles this correctly, but developers should be aware of this SVG specification detail when constructing or debugging path strings manually.
fix
Be mindful of SVG path syntax rules, especially for sequential commands where the command letter might be omitted. The `parse_path` function correctly interprets these implicit commands.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'svg.path'
The 'svg-path' library is not installed in your current Python environment.
fix
pip install svg.path
AttributeError: module 'svg.path' has no attribute 'parse_path'
The user tried to access `parse_path` as an attribute of the `svg.path` module after a direct `import svg.path`, but `parse_path` must be explicitly imported or accessed from the main module level.
fix
from svg.path import parse_path

# Then use it like:
path = parse_path("M 10 10 L 20 20")
TypeError: 'str' object is not callable
The user attempted to call the `svg.path` module itself as a function (e.g., `svg.path("M...")`) instead of using the `parse_path` function to parse SVG path data.
fix
from svg.path import parse_path

# Then use it like:
path = parse_path("M 10 10 L 20 20")
ValueError: Invalid path data: expected a number at position ...
The SVG path data string provided to `parse_path` is malformed, containing non-numeric characters where numbers are expected or violating SVG path syntax rules.
fix
Inspect and correct the SVG path data string to ensure it strictly adheres to the SVG path specification (e.g., ensure all coordinates are valid numbers and commands are correctly formatted).
Upgrade
Version history
7.1latest on PyPI · released Jul 7, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
svg-path — pip install svg-path · libregistry