py_svg_hush
What it is and what it does
py-svg-hush is a Python wrapper around Cloudflare's svg-hush Rust library that removes potentially malicious content from SVG files. It provides a single function, filter_svg, which takes SVG bytes and an optional dictionary of allowed MIME types for data URLs, then returns sanitized SVG bytes. The package strips dangerous elements and attributes while enforcing a whitelist of permitted data URL MIME types—any data URL whose type is not in the whitelist is dropped entirely.
The package is built as a compiled extension using Rust bindings, which means installation requires downloading or building wheels for your platform and Python version. It supports Python 3.10 through 3.14 on CPython and PyPy, with prebuilt wheels available for common architectures. The API is minimal and straightforward: one function call with two parameters, raising ValueError or TypeError on invalid input.
Use it for:
- Sanitize user-uploaded SVG files in a web application before storing or displaying them.
- Strip embedded scripts and event handlers from SVG graphics in a content management system.
- Enforce a whitelist of allowed image MIME types in SVG data URLs to prevent unexpected content injection.
- Batch-process a collection of SVG files to remove known attack vectors before distribution.
- Validate SVG safety in a document processing pipeline that accepts external graphics.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Sanitizes SVG files by removing malicious elements, attributes, and restricting data URL MIME types through a Python wrapper around the svg-hush Rust library.
Yes, if you need to sanitize untrusted SVG input and can accept the license uncertainty. The package is straightforward, has no runtime dependencies, and benefits from battle-tested Rust logic. However, verify the license terms before use in proprietary or commercial contexts, and confirm that svg-hush's threat model matches your security requirements. The aging maintenance status (182 days since last release) is not a blocker for a stable utility, but monitor the repository for security updates.
Install
py-svg-hush on PyPI
pip
pip install py-svg-hushuv
uv add py-svg-hushpoetry
poetry add py-svg-hushInstalling py_svg_hush
Before you install
Medium install friction due to compiled Rust bindings; wheels are available for Python 3.10–3.14 across Linux, macOS, and Windows. Last commit was 182 days ago and the project is marked as aging, though the repository remains active and unarchived.
License in practice
License status is unclear—no SPDX identifier or raw license text is recorded in the package metadata, so the legal terms for use and redistribution cannot be determined from the fact sheet.
Quickstart
pip install py-svg-hush
from py_svg_hush import filter_svg
svg_bytes = b'<svg>...</svg>'
keep_data_url_mime_types = {"image": ["jpeg", "png", "gif"]}
sanitized = filter_svg(svg_bytes, keep_data_url_mime_types)
Requires Python 3.10 or later.
Verify before relying
- Whether the underlying svg-hush Rust library's security model and threat coverage are documented or audited.
- What specific malicious elements and attributes are removed by filter_svg beyond data URL filtering.
- Whether the package is actively maintained or in maintenance-only mode given the 182-day gap since last release.
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | aging — 182 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 82,483/month — #14,160 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: py_svg_hush-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; py_svg_hush-0.3.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl; py_svg_hush-0.3.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl; py_svg_hush-0.3.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl; py_svg_hush-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; py_svg_hush-0.3.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl; py_svg_hush-0.3.0-cp310-cp310-musllinux_1_2_aarch64.whl; py_svg_hush-0.3.0-cp310-cp310-musllinux_1_2_armv7l.whl; py_svg_hush-0.3.0-cp310-cp310-musllinux_1_2_i686.whl; py_svg_hush-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl; py_svg_hush-0.3.0-cp310-cp310-win_amd64.whl; py_svg_hush-0.3.0-cp311-cp311-macosx_10_12_x86_64.whl; py_svg_hush-0.3.0-cp311-cp311-macosx_11_0_arm64.whl; py_svg_hush-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; py_svg_hush-0.3.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl; py_svg_hush-0.3.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl; py_svg_hush-0.3.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl; py_svg_hush-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; py_svg_hush-0.3.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl; py_svg_hush-0.3.0-cp311-cp311-musllinux_1_2_aarch64.whl
Tags
More Security packages
Provides Python bindings to the FreeDesktop.org…
permissive · top 1,000 on PyPI
msalMSAL for Python handles OAuth2 and OpenID…
permissive · top 1,000 on PyPI
joserfcjoserfc implements JOSE standards (JWS, JWE,…
permissive · top 1,000 on PyPI
AuthlibAuthlib provides a complete implementation of…
permissive · top 1,000 on PyPI
argon2-cffi-bindingsProvides low-level CFFI bindings to the…
permissive · top 1,000 on PyPI
adalADAL for Python authenticates applications with…
permissive · top 1,000 on PyPI
nh3nh3 sanitizes HTML by removing unsafe tags and…
permissive · top 1,000 on PyPI
scourScour optimizes and cleans SVG files by…
permissive · top 15,000 on PyPI
resvg_pyConverts SVG documents to raster image bytes…
unclear · top 5,000 on PyPI
html-sanitizerSanitizes HTML fragments by enforcing an…
permissive · top 5,000 on PyPI
lxml-html-cleanCleans and sanitizes HTML by removing unwanted…
permissive · top 5,000 on PyPI
bleachBleach sanitizes untrusted HTML by escaping or…
permissive · top 1,000 on PyPI
CairoSVGCairoSVG converts SVG files to PDF, EPS, PS,…
copyleft · top 5,000 on PyPI
svgelementssvgelements parses SVG files and provides…
permissive · top 5,000 on PyPI
faiconsProvides Font Awesome 6.2.0 icons as SVG…
permissive · top 15,000 on PyPI
typstCompiles Typst markup documents to PDF, PNG,…
unclear · top 15,000 on PyPI