--- id: nh3 version: "0.3.6" license: MIT license_treatment: permissive maintenance: active --- # nh3 — Python binding to Ammonia HTML sanitizer Rust crate License: permissive · Maintenance: active · Popularity: top 1,000 on PyPI ## Install pip install nh3 uv add nh3 poetry add nh3 ## Description # nh3 ![CI](https://github.com/messense/nh3/workflows/CI/badge.svg) [![PyPI](https://img.shields.io/pypi/v/nh3.svg)](https://pypi.org/project/nh3) [![Documentation Status](https://readthedocs.org/projects/nh3/badge/?version=latest)](https://nh3.readthedocs.io/en/latest/?badge=latest) Python bindings to the [ammonia](https://github.com/rust-ammonia/ammonia) HTML sanitization library. ## Installation ```bash pip install nh3 ``` ## Usage See [the documentation](https://nh3.readthedocs.io/en/latest/). ## Performance A quick benchmark showing that nh3 is about 20 times faster than the deprecated [bleach](https://pypi.org/project/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 nh3 sanitizes HTML by removing potentially dangerous tags and attributes, wrapping the Rust ammonia library for high-performance HTML cleaning in Python. 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. [View on SkillFed](https://skillfed.io/packages/nh3) · [View on PyPI](https://pypi.org/project/nh3/)