{"id":5714,"library":"resvg-py","title":"resvg-py","description":"Resvg-py is a Python package that provides high-performance SVG rendering by wrapping the `resvg` Rust library using PyO3. This package allows Python applications to easily render SVG files to various image formats such as PNG, PDF, and SVGZ, with high fidelity and performance. It aims to offer safe and high-level bindings to the underlying `resvg` project. The library maintains a frequent release cadence, with updates often occurring monthly or bi-monthly.","status":"active","version":"0.3.1","language":"en","source_language":"en","source_url":"https://github.com/baseplate-admin/resvg-py","tags":["SVG","rendering","image conversion","Rust","PyO3","PNG","PDF"],"install":[{"cmd":"pip install resvg-py","lang":"bash","label":"Install `resvg-py`"}],"dependencies":[{"reason":"Used for convenient creation of affine transformation matrices in advanced rendering scenarios, eliminating the need to directly wrap `tiny_skia`'s Transformation class.","package":"affine","optional":true}],"imports":[{"note":"This is the primary function for simple SVG to PNG byte conversion in the current `resvg-py` API.","symbol":"svg_to_bytes","correct":"from resvg_py import svg_to_bytes"}],"quickstart":{"code":"import resvg_py\n\nsvg_string = \"\"\"\n<svg width=\"300\" height=\"130\" xmlns=\"http://www.w3.org/2000/svg\">\n  <rect width=\"200\" height=\"100\" x=\"10\" y=\"10\" rx=\"20\" ry=\"20\" fill=\"blue\" />\n</svg>\n\"\"\"\n\n# Renders SVG to PNG bytes\npng_bytes = resvg_py.svg_to_bytes(svg_string=svg_string)\n\n# The 'png_bytes' variable now holds the binary data of the rendered PNG image.\n# You can save it to a file or process it further.\nprint(f\"Generated PNG bytes of length: {len(png_bytes)}\")","lang":"python","description":"This quickstart demonstrates how to convert a simple SVG string into PNG image bytes using `resvg-py`'s `svg_to_bytes` function."},"warnings":[{"fix":"Ensure your SVGs adhere to a static subset of the specification. Avoid dynamic features or elements if rendering with `resvg-py`.","message":"resvg-py inherits limitations from the underlying `resvg` Rust library regarding SVG feature support. It primarily supports a static subset of SVG 1.1/2, explicitly excluding dynamic features such as animations, scripting, or elements like `<a>`, `script`, `view`, or `cursor`. Users expecting full browser-like SVG rendering capabilities will find these features unsupported.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For custom fonts, use the appropriate API (e.g., `usvg.FontDatabase.default().load_system_fonts()` or similar methods if exposed by `resvg_py`) to load them for consistent rendering. Refer to the documentation for advanced font handling.","message":"The library does not use native system text rendering. It relies on its own internal font handling mechanisms, which might lead to inconsistencies if specific system fonts or exact rendering matches are expected. Users need to ensure necessary fonts are explicitly loaded if custom fonts are used in their SVGs.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To resolve this, modify the SVG file to use pixel (`px`) units for dimensions, or simply remove the 'mm' suffix from the `width` and `height` attributes, allowing `resvg-py` to parse them correctly.","message":"SVG files that specify dimensions in `mm` (millimeters) units might fail to load with an 'SVG has an invalid size' error.","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"}