types-lxml
Complete lxml external type annotation
What it is and what it does
types-lxml is a stub package that provides complete external type annotations for the lxml library, allowing Python type checkers and IDEs to understand and validate code that uses lxml's XML and HTML processing APIs. It works with multiple type checkers—mypy, pyright, basedpyright, pyrefly, and ty—and includes a mypy plugin that adds specialized type-checking behavior for lxml-specific patterns.
The package is built around four goals: complete annotation coverage (no longer marked as partial), support for multiple type checkers, extensive review and testing against real runtime behavior, and developer-friendly features like contextual docstrings and warnings for problematic usage patterns. It includes both a standard build and a multi-subclass variant for projects that create multiple lxml element subclasses, and supports Python 3.9 through 3.14.
Use it for:
- Enable static type checking in IDEs and CI pipelines for projects using lxml for XML or HTML parsing.
- Catch type errors in lxml code before runtime, such as incorrect method calls or type mismatches.
- Get IDE autocomplete and inline documentation for lxml APIs in Visual Studio Code and other editors.
- Use the mypy plugin to enforce correct patterns for lxml element class lookups and inheritance.
- Validate lxml code against multiple type checkers to ensure broad compatibility.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides complete external type annotations for lxml, enabling static type checking and IDE support for code using lxml's XML and HTML processing functionality.
Yes. types-lxml is actively maintained, has no known vulnerabilities, installs with low friction, and is essential for any project using lxml that wants static type checking. The Apache-2.0 license poses no restriction. Install it if you use lxml and rely on type checking or IDE support.
Install
types-lxml on PyPI
pip
pip install types-lxmluv
uv add types-lxmlpoetry
poetry add types-lxmlInstalling types-lxml
Before you install
Low friction installation as a pure-Python wheel. Actively maintained with recent releases; last commit 2026-06-29. Supports current Python versions (3.9–3.14) and works with multiple type checkers including mypy, pyright, basedpyright, pyrefly, and ty.
License in practice
Apache-2.0 permissive license allows use in most projects without significant restrictions. Safe for both open-source and commercial codebases.
Quickstart
pip install types-lxml
# In mypy.ini or pyproject.toml, enable the plugin:
# [mypy]
# plugins = mypy_plugin_lxml.main
import lxml.etree as etree
root = etree.Element('root')
Requires Python 3.9 or later. Mypy plugin requires explicit configuration in mypy config file to enable.
Verify before relying
- Whether the package's mypy plugin is required for basic type checking or only for advanced features like XMLParser.set_element_class_lookup() behavior.
- Performance impact of enabling the mypy plugin on type-check times for large projects.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — typing_extensions, cssselect, beautifulsoup4, types-html5lib |
| Maintenance | actively maintained — 178 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,813,233/month — #2,492 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: types_lxml-2026.2.16-py3-none-any.whl
Keywords: lxml, typing, stubs, annotation
Tags
More Markup packages
PyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
markdown-it-pyA Python markdown parser that converts markdown…
permissive · top 100 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
et-xmlfileet_xmlfile writes large XML files with minimal…
permissive · top 1,000 on PyPI
tomlkitParses and edits TOML files while preserving…
permissive · top 1,000 on PyPI
docstring-parserParses Python docstrings in ReST, Google,…
permissive · top 1,000 on PyPI
lxml-stubsProvides type annotations for the lxml package…
permissive · top 5,000 on PyPI
types-PygmentsProvides type hints for the Pygments syntax…
permissive · top 5,000 on PyPI
types-setuptoolsProvides type annotations for the setuptools…
permissive · top 1,000 on PyPI
types-openpyxlProvides type hints for openpyxl, enabling…
permissive · top 5,000 on PyPI
types-beautifulsoup4Provides type hints for beautifulsoup4 code via…
permissive · top 5,000 on PyPI
types-braintreeProvides type hints for the braintree payment…
permissive · top 15,000 on PyPI
types-yt-dlpProvides type hints for yt-dlp, enabling static…
permissive · top 15,000 on PyPI
types-dateparserProvides type stubs for the dateparser package,…
permissive · top 5,000 on PyPI
types-geventProvides type stubs for the gevent library,…
permissive · top 15,000 on PyPI
basedpyrightBasedpyright is a static type checker for…
permissive · top 5,000 on PyPI