lxml-stubs provides high-quality type annotations (`.pyi` files) for the popular `lxml` library, enabling robust static type checking with tools like MyPy. It is currently at version 0.5.1 and is released irregularly, typically in response to updates in `lxml` or bug fixes in the stubs themselves.
pip install lxml lxml-stubsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `lxml` with type annotations. By installing `lxml-stubs` alongside `lxml`, type checkers like MyPy can correctly infer and validate the types of `lxml` objects and methods.
Always install `pip install lxml lxml-stubs`.
Understand that lxml-stubs is a developer tool to aid in writing type-safe code, not a runtime dependency that changes lxml's behavior.
Check the lxml-stubs GitHub repository for release notes and issues if you encounter unexpected type errors with recent lxml versions. Consider pinning both lxml and lxml-stubs versions in production to ensure compatibility.