nh3
Python binding to Ammonia HTML sanitizer Rust crate
Install
nh3 on PyPI
pip
pip install nh3uv
uv add nh3poetry
poetry add nh3Package 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
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 ±...
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.
Similar packages
permissive · top 1,000 on PyPI
xxhashpermissive · top 1,000 on PyPI
Jinja2permissive · top 100 on PyPI
diskcachepermissive · top 1,000 on PyPI
opt-einsumpermissive · top 1,000 on PyPI
url-normalizepermissive · top 1,000 on PyPI
tqdmcopyleft · top 100 on PyPI
nest-asynciopermissive · top 1,000 on PyPI
uvlooppermissive · top 1,000 on PyPI
rignorepermissive · top 1,000 on PyPI