svgwrite

SVG vector graphics library for Python — creates SVG files programmatically without a display. svgwrite features: Drawing container for SVG document, shapes (Rect, Circle, Ellipse, Line, Polyline, Polygon, Path), Text and TSpan for text elements, Image for embedded images, Group for element grouping, Use for element reuse/symbols, Gradient (linear/radial) and Pattern fills, ClipPath, Marker for line-end arrows, Filter effects, CSS class/style attributes, SVG animation, debug validation mode, and saveas() for file output. Pure Python with no binary dependencies.

Evaluated Mar 06, 2026 (0d ago) v1.4.x
Homepage ↗ Repo ↗ Developer Tools python svgwrite svg vector-graphics drawing chart diagram
⚙ Agent Friendliness
65
/ 100
Can an agent use this?
🔒 Security
91
/ 100
Is it safe for agents?
⚡ Reliability
80
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
80
Error Messages
75
Auth Simplicity
99
Rate Limits
99

🔒 Security

TLS Enforcement
92
Auth Strength
92
Scope Granularity
90
Dep. Hygiene
90
Secret Handling
92

SVG generation library with no network calls. User-controlled SVG text content: SVG can embed JavaScript via <script> tags and event handlers; when serving agent-generated SVG to browsers, sanitize any user-controlled text inserted into SVG; use HTML encoding for text content. SVG is XML — validate against XML injection if building SVG from user data.

⚡ Reliability

Uptime/SLA
78
Version Stability
80
Breaking Changes
82
Error Recovery
80
AF Security Reliability

Best When

Programmatic SVG generation for diagrams, icons, and simple vector graphics — svgwrite provides the most straightforward Python API for creating SVG files without a GUI.

Avoid When

Raster images (use Pillow), complex charts (use matplotlib/plotly), PDF output (use reportlab), or when cairosvg conversion to other formats is needed.

Use Cases

  • Agent diagram generation — import svgwrite; dwg = svgwrite.Drawing('diagram.svg', size=('800px', '600px')); dwg.add(dwg.rect((10, 10), (200, 100), fill='blue')); dwg.add(dwg.text('Label', insert=(110, 60), fill='white', text_anchor='middle')); dwg.save() — SVG diagram; agent generates architectural diagrams or data visualizations as vector SVG
  • Agent chart creation — dwg = svgwrite.Drawing('chart.svg'); for i, value in enumerate(data): height = value * scale; dwg.add(dwg.rect((i*50, 200-height), (40, height), fill=colors[i])) — bar chart; agent creates data charts as SVG for web embedding; SVG scales without pixelation
  • Agent flow diagram — dwg = svgwrite.Drawing(); dwg.add(dwg.line((100, 50), (100, 150), stroke='black')); arrow = dwg.marker(insert=(0,3), size=(6,6), orient='auto'); arrow.add(dwg.path('M0,0 L0,6 L6,3 z', fill='black')); dwg.defs.add(arrow) — flow diagram; agent generates workflow diagrams with arrows and shapes
  • Agent gradient background — g = dwg.linearGradient(('0%', '0%'), ('100%', '0%')); g.add_stop_color(0, 'blue'); g.add_stop_color(1, 'green'); dwg.defs.add(g); dwg.add(dwg.rect((0,0), (800,600), fill=g.get_paint_server())) — gradients; agent creates styled SVG with gradient fills
  • Agent SVG string output — dwg = svgwrite.Drawing(); dwg.add(dwg.circle((100, 100), 50, fill='red')); svg_string = dwg.tostring() — in-memory; agent generates SVG as string for HTTP response without file I/O; tostring() returns SVG markup

Not For

  • Raster image generation — svgwrite is vector SVG only; for PNG/JPEG use Pillow
  • Complex data visualization — for charts/plots use matplotlib, plotly, or altair
  • PDF generation — svgwrite makes SVG not PDF; for PDF use reportlab or weasyprint

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

No auth — local SVG generation library.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

svgwrite is MIT licensed. Free for all use.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • Coordinates are (x, y) tuples not keyword args — dwg.rect((x, y), (width, height)); NOT dwg.rect(x=x, y=y, width=w, height=h); agent code: first arg is position tuple, second is size tuple; Line: dwg.line((x1,y1), (x2,y2)); Circle: dwg.circle((cx,cy), r); consistent tuple-based positional API
  • SVG coordinate system: y increases downward — SVG origin is top-left; y=0 is top; larger y is lower on screen; agent code drawing charts: invert y axis for intuitive charts: svg_y = height - data_y; or use transform='scale(1,-1)' with translate to flip
  • debug=True mode disables some performance — svgwrite.Drawing(debug=True) validates attribute types at element creation; useful for development; agent production code: svgwrite.Drawing(debug=False) for speed; debug mode catches invalid hex colors, unit strings, etc.
  • Text baseline is bottom not top — dwg.text('Hello', insert=(x, y)) places text with baseline at y; text appears ABOVE the y coordinate; agent code wanting text anchored at top: add font-size offset: y + font_size; or use dominant-baseline='hanging' attribute
  • defs must be added before use — SVG defs (gradients, markers, symbols) must be added via dwg.defs.add() before referencing in elements; agent code: add gradient to defs first, then reference in rect fill; order matters in SVG: defs section precedes use
  • tostring() returns bytes not str in some configs — svgwrite tostring() behavior varies; for HTTP response: use dwg.tostring().decode('utf-8') to ensure string; or use dwg.get_xml() for ElementTree object; agent code serving SVG via web framework: test encoding of tostring() output

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for svgwrite.

$99

Scores are editorial opinions as of 2026-03-06.

5208
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered