nh3
Python binding to Ammonia HTML sanitizer Rust crate
Decision gist · record as of 2026-08-14
Yes. nh3 is actively maintained, has no known vulnerabilities, carries a permissive MIT license, and solves a real security problem with a proven Rust implementation. The medium install friction is offset by prebuilt wheels for common platforms and the absence of runtime dependencies. Use it whenever you need to sanitize untrusted HTML.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.8 or later.
- Medium install friction due to compiled wheels, but prebuilt binaries are available for common platforms (CPython 3.8+, PyPy, macOS, Linux, Windows).
- Last release 53 days ago; repository is active with 391 stars.
License · maintenance · safety
MIT (permissive) — MIT license is permissive; you can use, modify, and distribute nh3 freely with minimal restrictions.
last release 2026-06-22 (53 days) · last repo commit 2026-08-10 · 391 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 54,059,510 downloads/mo, #545 on PyPI
Alternatives
Verify before relying
pip install nh3
import nh3
clean_html = nh3.clean('<p>Hello <script>alert(1)</script></p>')- Specific configuration options and allowed tag/attribute lists supported by nh3.clean()
- Whether nh3 provides escape or encoding functions beyond basic sanitization
- Performance characteristics on different HTML sizes and complexity levels
What it is and what it does
nh3 is a Python wrapper around the Rust ammonia HTML sanitization library. It removes potentially dangerous HTML tags and attributes—such as script tags, event handlers, and other XSS vectors—from user-supplied or untrusted HTML content. The package has no runtime dependencies and is distributed as precompiled wheels for most platforms, making installation straightforward.
The library is designed for developers who need to safely display user-generated HTML in web applications, content management systems, or any context where untrusted HTML must be rendered without security risk. It operates as a thin binding to ammonia's Rust implementation, which means sanitization happens at native speed rather than through Python logic.
Use it for
- Sanitize user comments or forum posts before displaying them on a website
- Clean HTML pasted from rich-text editors to prevent XSS attacks
- Filter email HTML content to remove malicious scripts before rendering
- Prepare user-submitted HTML for safe storage or republication
- Validate and clean HTML in content import workflows
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
nh3 is actively maintained, has no known vulnerabilities, carries a permissive MIT license, and solves a real security problem with a proven Rust implementation. The medium install friction is offset by prebuilt wheels for common platforms and the absence of runtime dependencies. Use it whenever you need to sanitize untrusted HTML.
Install
nh3 on PyPI
Before you install
Medium install friction due to compiled wheels, but prebuilt binaries are available for common platforms (CPython 3.8+, PyPy, macOS, Linux, Windows). Last release 53 days ago; repository is active with 391 stars.
Requires Python 3.8 or later.
License in practice
MIT license is permissive; you can use, modify, and distribute nh3 freely with minimal restrictions.
Quickstart
pip install nh3
import nh3
clean_html = nh3.clean('<p>Hello <script>alert(1)</script></p>')
Verify before relying
- Specific configuration options and allowed tag/attribute lists supported by nh3.clean()
- Whether nh3 provides escape or encoding functions beyond basic sanitization
- Performance characteristics on different HTML sizes and complexity levels
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 53 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 54,059,510 / month, #545 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyProgramming Language :: RustTopic :: Software Development :: Libraries :: Python Modules |
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
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “remove unsafe html tags”
- nh3nh3 sanitizes HTML by removing unsafe tags and attributes, exposing…
- html-sanitizerSanitizes HTML fragments by enforcing an allowlist of safe tags and…
- lxml-html-cleanCleans and sanitizes HTML by removing unwanted tags and attributes…
Give your agent the search over MCP, or paste the wish link into any chat.
More Python Modules packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
PyYAML parses and emits YAML 1.1 data format, enabling serialization and deserialization of configuration files and Python objects to and from human-readable YAML text.
Pydantic validates Python data structures against type hints, coercing and checking input at runtime to ensure it matches a declared schema.
Provides reusable metadata objects for use with PEP-593 `typing.Annotated` to express common constraints like bounds, collection sizes, and predicates on types.
Install it if you use or build libraries that need to express type constraints in a standardized, inspectable way—or if you want to annotate your own types with…
Provides runtime tools to inspect and introspect Python type annotations, enabling programmatic examination of type hints at execution time.
See also bleach · py_svg_hush · primer3-py · lxml-html-clean · django-bleach · bleach-allowlist · django-markdownify · sanitize-filename · types-bleach · html-sanitizer