svg2png-py
Fast, accurate SVG → PNG rendering for Python, powered by the
resvg Rust library.
Built with PyO3 and
Maturin.
Unlike the original resvg-py, this binding is fully thread-safe: a
FontDatabase instance can be shared across threads and called concurrently
from a ThreadPoolExecutor without any locking on the Python side.
Features
- Full-fidelity SVG → PNG rasterization via
resvg/tiny-skia - Thread-safe
FontDatabase— share one instance across a thread pool - Affine-free transforms — pass a plain 6-tuple, no extra dependencies
- Batch rendering via
render_many - Background canvas: solid colour, existing PNG file, or raw PNG bytes
- Pre-built wheels for Windows, Linux, and macOS (Python ≥ 3.9)
Installation
pip install svg2png-py
Quick start
import svg2png_py
# Load fonts (system fonts + a custom one)
db = svg2png_py.FontDatabase.system()
db.load_font_file("/path/to/MyFont.ttf")
svg = open("diagram.svg", encoding="utf-8").read()
# Render with the SVG's intrinsic size
png_bytes = svg2png_py.svg_to_png(svg, db)
open("diagram.png", "wb").write(png_bytes)
API
FontDatabase
db = svg2png_py.FontDatabase() # empty
db = svg2png_py.FontDatabase.system() # pre-loaded with system fonts
db.load_system_fonts() # add system fonts to an existing db
db.load_font_file("/path/to/font.ttf") # load a single file
db.load_fonts_dir("/path/to/fonts/") # load all fonts in a directory
len(db) # number of loaded font faces
RenderOptions
opts = svg2png_py.RenderOptions(
dpi=96.0, # default: 96.0
font_family="Helvetica", # default: "Times New Roman"
font_size=12.0, # default: 12.0
resources_dir="/path/to/svgs/", # default: None (cwd)
)
svg_to_png
png: bytes = svg2png_py.svg_to_png(
svg_str, # str — SVG content
font_db, # FontDatabase
transform=None, # 6-tuple (a,b,c,d,e,f) or None for identity
bg_file=None, # str — path to a PNG background
bg_data=None, # bytes — raw PNG background
bg_size=None, # (w, h) — canvas size (default: SVG intrinsic)
bg_color=None, # (r, g, b, a) — fill colour 0-255
options=None, # RenderOptions
)
render_many
pages: list[bytes] = svg2png_py.render_many(
svg_strings, # list[str]
font_db, # FontDatabase
transform=None, # shared transform for all pages
bg_color=None, # shared fill colour for all pages
options=None, # shared RenderOptions
)
Transforms
The transform parameter accepts a 6-tuple (a, b, c, d, e, f) in
row-major order. This is the same layout as affine.Affine(...)[0:6], so
code that previously depended on the affine package can simply pass the
slice directly — no library change needed:
# Before (affine required):
# from affine import Affine
# tr = Affine.scale(2)
# data = old_render(tree, tr[0:6])
# After (no extra dependency):
a, b, c, d, e, f = 2, 0, 0, 0, 2, 0 # scale ×2
png = svg2png_py.svg_to_png(svg, db, transform=(a, b, c, d, e, f))
Pass None (the default) for the identity transform.
Thread-pool example
import svg2png_py
from concurrent.futures import ThreadPoolExecutor
db = svg2png_py.FontDatabase.system()
svgs = [open(f"page{i}.svg").read() for i in range(20)]
def render_one(svg):
return svg2png_py.svg_to_png(svg, db) # db shared across threads ✓
with ThreadPoolExecutor() as pool:
pngs = list(pool.map(render_one, svgs))
Credits
This package is a rewrite of resvg-py by Brice Yan, used under the MIT licence.
It wraps the resvg crate (formerly
by RazrFalcon, now maintained by the Linebender project), which uses
tiny-skia for rasterization and
fontdb for font resolution.
License
MIT
Metadata
Release files for svg2png-py 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| svg2png_py-1.1.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for svg2png_py-1.1.0-cp311-abi3-win_amd64.whl |
| svg2png_py-1.1.0-cp311-abi3-manylinux_2_34_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.34+ x86-64 | Details for svg2png_py-1.1.0-cp311-abi3-manylinux_2_34_x86_64.whl |
| svg2png_py-1.1.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details for svg2png_py-1.1.0-cp311-abi3-macosx_11_0_arm64.whl |
Total release size: 4.5 MB
Release files / svg2png_py-1.1.0-cp311-abi3-win_amd64.whl
| Download URL | svg2png_py-1.1.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
6bef5607bbc64003b350c8e0f7a6a20725d5226009f1666ddd4e2a1106cb0f54
|
|
BLAKE2b-256 checksum How to use checksums |
d22038dfaaef3aa1515970931d423965afe50bc6bc8671e9bf292825070ac52b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.
Transparency logRelease files / svg2png_py-1.1.0-cp311-abi3-manylinux_2_34_x86_64.whl
| Download URL | svg2png_py-1.1.0-cp311-abi3-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.11 Linux glibc 2.34+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
7a7af6e83d09f7eaeae2b1ee541e6d7e5271fe4028a1008e37fd8985da9001a0
|
|
BLAKE2b-256 checksum How to use checksums |
6d4e87db36ccf8f4015295c694ce9fc6adcd43754d515a0ba3fd54e2b3107af8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.
Transparency logRelease files / svg2png_py-1.1.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | svg2png_py-1.1.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
fa748d733e20954d18b0b6b8000900a5a9858443f109cb654ea87b1c3525e214
|
|
BLAKE2b-256 checksum How to use checksums |
1e9b9a367da269e90047f4d727e21ddd9df23ad734643382a1e6b7154c61d96e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.
Transparency logSecurity for svg2png-py 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 3 files in this release have been uploaded with provenance metadata.
Attestation for svg2png_py-1.1.0-cp311-abi3-win_amd64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.