Skip to main content

No project description provided

Project description

py-svg-hush

py-svg-hush is a Python package for sanitizing SVG files using the svg-hush Rust library.

Installation

py-svg-hush requires Python 3.7 or later. You can install it using pip:

pip install py-svg-hush

Usage

from py_svg_hush import filter_svg

svg_bytes = b"""
<svg xmlns="http://www.w3.org/2000/svg">
    <script>alert('Malicious script')</script>
</svg>
"""

keep_data_url_mime_types = {
    "image": ["jpeg", "png", "gif"],
}

sanitized_svg = filter_svg(svg_bytes, keep_data_url_mime_types)

filter_svg

The filter_svg function sanitizes SVG data by removing potentially malicious elements and attributes, as well as restricting the allowed MIME types of data: URLs in the SVG. It is a simple wrapper around the underlying Rust function.

Parameters

  • svg (bytes): The SVG data to be filtered.
  • keep_data_url_mime_types (Optional[Dict[str, List[str]]]): A dictionary that maps MIME types to lists of allowed subtypes for data: URLs in the SVG. If a data: URL's MIME type and subtype are not in the dictionary it will be dropped. If this parameter is None, all data: URLs are dropped.

Returns

  • (bytes): The sanitized SVG data.

Raises

  • ValueError: If there is an error processing the SVG data.
  • TypeError: If any of the arguments are of the wrong type.

Development

To set up a development environment for py-svg-hush, you can use the following steps:

Clone the repository:

git clone git@github.com:jams2/py-svg-hush.git

Install development dependencies:

pip install .[dev,testing]

Build the Rust library, resulting in a Python module:

maturin develop

Run tests:

pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_svg_hush-0.1.2.tar.gz (15.8 kB view hashes)

Uploaded Source

Built Distributions

py_svg_hush-0.1.2-pp310-pypy310_pp73-musllinux_1_2_x86_64.whl (686.6 kB view hashes)

Uploaded PyPy musllinux: musl 1.2+ x86-64

py_svg_hush-0.1.2-pp310-pypy310_pp73-musllinux_1_2_i686.whl (706.0 kB view hashes)

Uploaded PyPy musllinux: musl 1.2+ i686

py_svg_hush-0.1.2-pp310-pypy310_pp73-musllinux_1_2_armv7l.whl (774.6 kB view hashes)

Uploaded PyPy musllinux: musl 1.2+ ARMv7l

py_svg_hush-0.1.2-pp310-pypy310_pp73-musllinux_1_2_aarch64.whl (697.8 kB view hashes)

Uploaded PyPy musllinux: musl 1.2+ ARM64

py_svg_hush-0.1.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (524.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

py_svg_hush-0.1.2-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (582.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

py_svg_hush-0.1.2-pp310-pypy310_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (574.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

py_svg_hush-0.1.2-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (524.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

py_svg_hush-0.1.2-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (526.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

py_svg_hush-0.1.2-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl (547.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

py_svg_hush-0.1.2-pp39-pypy39_pp73-musllinux_1_2_x86_64.whl (686.6 kB view hashes)

Uploaded PyPy musllinux: musl 1.2+ x86-64

py_svg_hush-0.1.2-pp39-pypy39_pp73-musllinux_1_2_i686.whl (705.9 kB view hashes)

Uploaded PyPy musllinux: musl 1.2+ i686

py_svg_hush-0.1.2-pp39-pypy39_pp73-musllinux_1_2_armv7l.whl (774.6 kB view hashes)

Uploaded PyPy musllinux: musl 1.2+ ARMv7l

py_svg_hush-0.1.2-pp39-pypy39_pp73-musllinux_1_2_aarch64.whl (697.8 kB view hashes)

Uploaded PyPy musllinux: musl 1.2+ ARM64

py_svg_hush-0.1.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (523.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

py_svg_hush-0.1.2-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (582.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

py_svg_hush-0.1.2-pp39-pypy39_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (574.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

py_svg_hush-0.1.2-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (524.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

py_svg_hush-0.1.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (526.2 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

py_svg_hush-0.1.2-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl (546.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

py_svg_hush-0.1.2-cp312-none-win_amd64.whl (363.8 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

py_svg_hush-0.1.2-cp312-none-win32.whl (349.8 kB view hashes)

Uploaded CPython 3.12 Windows x86

py_svg_hush-0.1.2-cp312-cp312-musllinux_1_2_x86_64.whl (686.4 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

py_svg_hush-0.1.2-cp312-cp312-musllinux_1_2_i686.whl (705.5 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

py_svg_hush-0.1.2-cp312-cp312-musllinux_1_2_armv7l.whl (774.6 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ ARMv7l

py_svg_hush-0.1.2-cp312-cp312-musllinux_1_2_aarch64.whl (698.0 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ ARM64

py_svg_hush-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (523.5 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

py_svg_hush-0.1.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (581.4 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

py_svg_hush-0.1.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (574.3 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

py_svg_hush-0.1.2-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (524.1 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

py_svg_hush-0.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (525.9 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

py_svg_hush-0.1.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl (546.4 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.5+ i686

py_svg_hush-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (472.3 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

py_svg_hush-0.1.2-cp312-cp312-macosx_10_12_x86_64.whl (481.1 kB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

py_svg_hush-0.1.2-cp311-none-win_amd64.whl (363.8 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

py_svg_hush-0.1.2-cp311-none-win32.whl (349.9 kB view hashes)

Uploaded CPython 3.11 Windows x86

py_svg_hush-0.1.2-cp311-cp311-musllinux_1_2_x86_64.whl (686.5 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

py_svg_hush-0.1.2-cp311-cp311-musllinux_1_2_i686.whl (705.7 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

py_svg_hush-0.1.2-cp311-cp311-musllinux_1_2_armv7l.whl (774.6 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ ARMv7l

py_svg_hush-0.1.2-cp311-cp311-musllinux_1_2_aarch64.whl (698.1 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ ARM64

py_svg_hush-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (523.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

py_svg_hush-0.1.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (581.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

py_svg_hush-0.1.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (574.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

py_svg_hush-0.1.2-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (524.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

py_svg_hush-0.1.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (526.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

py_svg_hush-0.1.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (546.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.5+ i686

py_svg_hush-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (472.3 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

py_svg_hush-0.1.2-cp311-cp311-macosx_10_12_x86_64.whl (481.1 kB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

py_svg_hush-0.1.2-cp310-none-win_amd64.whl (363.8 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

py_svg_hush-0.1.2-cp310-none-win32.whl (349.9 kB view hashes)

Uploaded CPython 3.10 Windows x86

py_svg_hush-0.1.2-cp310-cp310-musllinux_1_2_x86_64.whl (686.4 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

py_svg_hush-0.1.2-cp310-cp310-musllinux_1_2_i686.whl (705.7 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

py_svg_hush-0.1.2-cp310-cp310-musllinux_1_2_armv7l.whl (774.6 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ ARMv7l

py_svg_hush-0.1.2-cp310-cp310-musllinux_1_2_aarch64.whl (698.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ ARM64

py_svg_hush-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (523.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

py_svg_hush-0.1.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (581.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

py_svg_hush-0.1.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (574.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

py_svg_hush-0.1.2-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (524.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

py_svg_hush-0.1.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (526.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

py_svg_hush-0.1.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (546.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ i686

py_svg_hush-0.1.2-cp310-cp310-macosx_11_0_arm64.whl (472.3 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

py_svg_hush-0.1.2-cp39-none-win_amd64.whl (363.9 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

py_svg_hush-0.1.2-cp39-none-win32.whl (349.9 kB view hashes)

Uploaded CPython 3.9 Windows x86

py_svg_hush-0.1.2-cp39-cp39-musllinux_1_2_x86_64.whl (686.5 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

py_svg_hush-0.1.2-cp39-cp39-musllinux_1_2_i686.whl (705.6 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ i686

py_svg_hush-0.1.2-cp39-cp39-musllinux_1_2_armv7l.whl (774.6 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ ARMv7l

py_svg_hush-0.1.2-cp39-cp39-musllinux_1_2_aarch64.whl (698.0 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ ARM64

py_svg_hush-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (523.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

py_svg_hush-0.1.2-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (581.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

py_svg_hush-0.1.2-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (574.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

py_svg_hush-0.1.2-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (524.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

py_svg_hush-0.1.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (526.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

py_svg_hush-0.1.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (546.4 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

py_svg_hush-0.1.2-cp39-cp39-macosx_11_0_arm64.whl (472.5 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page