{"id":3822,"library":"svg-path","title":"SVG Path Objects and Parser","description":"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.","status":"active","version":"7.0","language":"en","source_language":"en","source_url":"https://github.com/regebro/svg.path","tags":["SVG","graphics","path","parser","geometry","vector"],"install":[{"cmd":"pip install svg.path","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"Path","correct":"from svg.path import Path"},{"symbol":"Line","correct":"from svg.path import Line"},{"symbol":"Arc","correct":"from svg.path import Arc"},{"symbol":"CubicBezier","correct":"from svg.path import CubicBezier"},{"symbol":"QuadraticBezier","correct":"from svg.path import QuadraticBezier"},{"symbol":"Close","correct":"from svg.path import Close"},{"symbol":"parse_path","correct":"from svg.path import parse_path"}],"quickstart":{"code":"from svg.path import parse_path, Path, Line, Arc\nimport cmath # For complex numbers used by svg.path\n\n# Parse an SVG path string\npath_data = \"M 10 10 L 100 10 L 50 50 Z\"\npath = parse_path(path_data)\n\nprint(f\"Path has {len(path)} segments.\")\nfor i, segment in enumerate(path):\n    print(f\"Segment {i}: {type(segment).__name__} from {segment.start} to {segment.end}\")\n    # Example: Get a point along the segment\n    if hasattr(segment, 'point'):\n        mid_point = segment.point(0.5)\n        print(f\"  Midpoint: ({mid_point.real:.2f}, {mid_point.imag:.2f})\")\n\n# Construct a path programmatically\np = Path([\n    Line(start=cmath.rect(1, cmath.pi/2), end=cmath.rect(10, cmath.pi/2)), # Example using complex numbers\n    Line(start=(10+0j), end=(10+50j)),\n    Arc(start=(10+50j), radius=(20,20), rotation=0, large_arc=True, sweep=True, end=(30+70j))\n])\nprint(f\"\\nProgrammatic path has {len(p)} segments.\")\n","lang":"python","description":"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."},"warnings":[{"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)`).","message":"In 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.","severity":"breaking","affected_versions":">=7.0"},{"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.","message":"In version 4.0, the `Path` object no longer has a `closed` attribute.","severity":"breaking","affected_versions":">=4.0"},{"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.","message":"For `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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"SVG 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}