SVG libraries for Python
The common choices in Python:
- CairoSVG converts SVG to PNG, PDF and PostScript using the Cairo graphics library. One function call per conversion, good SVG 1.1 coverage, and safe defaults for untrusted files. LGPL-3.0; needs the Cairo C library installed.
- svglib converts SVG into a ReportLab drawing, which you can save as PDF or place inside a PDF document built with ReportLab. Needs no system libraries for PDF output. LGPL-3.0.
- drawsvg generates SVG from Python: shapes, paths, text, gradients, groups and native SVG animation, with display in Jupyter. MIT.
Pick CairoSVG to rasterize, svglib when you build PDFs with ReportLab or can’t install Cairo, and drawsvg to create SVG. Pillow doesn’t read SVG; pyvips (libvips + librsvg) and Wand (ImageMagick) also rasterize SVG.
- CairoSVG CairoSVG converts SVG to PNG, PDF and PostScript in Python using Cairo. How to install it, convert files, set the output size or DPI, convert from strings.
- drawsvg drawsvg generates SVG images and animations from Python. How to install it, draw shapes, paths and text, use gradients and groups, save SVG and PNG files.
- svglib svglib converts SVG to ReportLab drawings without Cairo, to make PDF files or embed SVG in ReportLab documents. How to install it, convert SVG to PDF.