resvg-py

0.3.1 · active · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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)}")

view raw JSON →