skillfed

types-lxml

Complete lxml external type annotation

types-lxml v2026.2.16 3.8M downloads/30d#2,492 on PyPI84
Permissive license Apache-2.0 Active released

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-lxml

uv

uv add types-lxml

poetry

poetry add types-lxml

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Typing :: Stubs Only

Tags

lxml type stubslxml type annotationsstatic type checking xmllxml mypy plugintype hints for lxmllxml ide supportlxml type hints
type-stubslxmlstatic-analysis

More Markup packages