skillfed

nh3

Python binding to Ammonia HTML sanitizer Rust crate

nh3 Permissive license MIT Active 391 v0.3.6 released

Install

nh3 on PyPI

pip

pip install nh3

uv

uv add nh3

poetry

poetry add nh3

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.8)
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance actively maintained — 52 days since the last release
Last repo commit
First released
Popularity one of the top 1,000 most-downloaded packages on PyPI (30-day window, as of 2026-08-13)
Known vulnerabilities none known (OSV.dev, checked 2026-08-13)

Evidence: nh3-0.3.6-cp314-cp314t-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl; nh3-0.3.6-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; nh3-0.3.6-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl; nh3-0.3.6-cp314-cp314t-musllinux_1_2_aarch64.whl; nh3-0.3.6-cp314-cp314t-musllinux_1_2_armv7l.whl; nh3-0.3.6-cp314-cp314t-musllinux_1_2_i686.whl; nh3-0.3.6-cp314-cp314t-musllinux_1_2_x86_64.whl; nh3-0.3.6-cp314-cp314t-win32.whl; nh3-0.3.6-cp314-cp314t-win_amd64.whl; nh3-0.3.6-cp314-cp314t-win_arm64.whl; nh3-0.3.6-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl; nh3-0.3.6-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; nh3-0.3.6-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl; nh3-0.3.6-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl; nh3-0.3.6-cp38-abi3-manylinux_2_17_ppc64.manylinux2014_ppc64.whl; nh3-0.3.6-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl; nh3-0.3.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; nh3-0.3.6-cp38-abi3-manylinux_2_31_riscv64.whl; nh3-0.3.6-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl; nh3-0.3.6-cp38-abi3-musllinux_1_2_aarch64.whl

Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyProgramming Language :: RustTopic :: Software Development :: Libraries :: Python Modules

About nh3

from the package's own PyPI description — quoted content, verbatim

nh3

CI (image) PyPI (image) Documentation Status (image)

Python bindings to the ammonia HTML sanitization library.

Installation

pip install nh3

Usage

See the documentation.

Performance

A quick benchmark showing that nh3 is about 20 times faster than the deprecated bleach package. Measured on a MacBook Air (M2, 2022).

```ipython Python 3.11.0 (main, Oct 25 2022, 16:25:24) [Clang 14.0.0 (clang-1400.0.29.102)] Type 'copyright', 'credits' or 'license' for more information IPython 8.9.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import requests

In [2]: import bleach

In [3]: import nh3

In [4]: html = requests.get("https://www.google.com").text

In [5]: %timeit bleach.clean(html) 2.85 ms ± 22.8 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [6]: %timeit nh3.clean(html) 138 µs ±...

Read as markdown · JSON record · Source repository

AI interpretation — verify before relying

AI-generated interpretation of the package facts above; every digit, version, license, or vulnerability id it cites is grounded in the facts already shown on this page

nh3 sanitizes HTML by removing potentially dangerous tags and attributes, wrapping the Rust ammonia library for high-performance HTML cleaning in Python.

Medium install friction due to compiled Rust bindings, but wheels are pre-built for most common platforms (Python 3.8+, CPython and PyPy). Last release 52 days ago with active repository maintenance.

MIT license permits commercial and private use with minimal restrictions; you must include a copy of the license in distributions.

Usage

pip install nh3
import nh3
cleaned = nh3.clean('<p>Hello <script>alert(1)</script></p>')

Requires Python 3.8 or later; pre-built wheels available for most platforms but source builds require a Rust toolchain.

Verdict: nh3 is a well-maintained, actively developed HTML sanitizer offering significant performance gains over older alternatives. No known vulnerabilities, permissive MIT license, and broad platform support via pre-built wheels make it a solid choice for XSS prevention—though compiled dependencies add modest install friction.

Needs verification

  • Whether the performance benchmark (20× faster than bleach) holds for typical real-world HTML payloads beyond the Google homepage test case.
  • Specific configuration options and tag/attribute allowlist customization capabilities not detailed in the excerpt.
html sanitizationremove malicious html tagsxss preventionhtml cleaning librarysanitize user input htmlammonia rust bindingssafe html filtering

Similar packages