Registry / data / resvg-py

resvg-py

JSON →
library0.5.0pypypi✓ verified 24d ago

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.

pip install resvg-py
INSTALL
IMPORT
SIG · RESVG-PY
R
resvg-py
datapythonv0.5.0
Install
1.7s avg
Import
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.0 · 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.000s · 21.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.000s · 21MB
19MB installed
● package 19MB
Code
Verified usage

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

svg_to_bytes
from resvg_py import svg_to_bytes
This is the primary function for simple SVG to PNG byte conversion in the current `resvg-py` API.

This quickstart demonstrates how to convert a simple SVG string into PNG image bytes using `resvg-py`'s `svg_to_bytes` function.

import resvg_py svg_string = """ <svg width="300" height="130" xmlns="http://www.w3.org/2000/svg"> <rect width="200" height="100" x="10" y="10" rx="20" ry="20" fill="blue" /> </svg> """ # Renders SVG to PNG bytes png_bytes = resvg_py.svg_to_bytes(svg_string=svg_string) # The 'png_bytes' variable now holds the binary data of the rendered PNG image. # You can save it to a file or process it further. print(f"Generated PNG bytes of length: {len(png_bytes)}")
Debug
Known issues
gotcharesvg-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.
fix
Ensure your SVGs adhere to a static subset of the specification. Avoid dynamic features or elements if rendering with `resvg-py`.
affects: All versions
gotchaThe 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.
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.
affects: All versions
gotchaSVG files that specify dimensions in `mm` (millimeters) units might fail to load with an 'SVG has an invalid size' error.
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.
affects: All versions
Errors
Common errors & fixes
error: command 'cargo' failed with exit code 1
The Rust toolchain (compiler and Cargo package manager) is not installed or not correctly configured in your system's PATH, preventing `resvg-py` from being built during installation.
fix
Install the Rust toolchain using rustup: `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` and ensure it's added to your system's PATH.
ValueError: Either `output_path` or `fmt` must be specified.
The `resvg` function was called without specifying either an `output_path` to save the rendered image to a file or a `fmt` (e.g., 'png', 'jpeg') to return the image data as bytes.
fix
Provide either the `output_path` argument to save to a file, or the `fmt` argument to return the image data as bytes, for example: `resvg(svg_data, output_path='output.png')` or `png_data = resvg(svg_data, fmt='png')`.
ModuleNotFoundError: No module named 'resvg_py'
The `resvg-py` package is not installed in the current Python environment, or the Python environment where it was installed is not currently active.
fix
Install the package using pip: `pip install resvg-py` or ensure you are working within the correct virtual environment where the package is installed.
AttributeError: module 'resvg_py' has no attribute 'render'
The user is attempting to call a function named `render` directly on the `resvg_py` module, but the primary rendering function in `resvg-py` is named `resvg`.
fix
Use the correct function name `resvg`: `from resvg_py import resvg; resvg(svg_data, output_path='output.png')` or `import resvg_py; resvg_py.resvg(svg_data, output_path='output.png')`.
ERROR: Could not find a version that satisfies the requirement resvg-py (from versions: none)
pip failed to find pre-built binary wheels for your specific system (OS, architecture, Python version), and the necessary Rust toolchain and C/C++ build tools are missing for source compilation.
fix
Install the Rust toolchain (`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`) and ensure your system has C/C++ build tools (e.g., `build-essential` on Linux, Xcode Command Line Tools on macOS), then retry `pip install resvg-py`.
Upgrade
Version history
0.5.0latest on PyPI · released Aug 24, 2026
Audit
Dependencies
affineoptionalUsed for convenient creation of affine transformation matrices in advanced rendering scenarios, eliminating the need to directly wrap `tiny_skia`'s Transformation class.
Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources