Skip to main content

Type annotations for lxml striving for completeness

Project description

PyPI version Supported Python Wheel

This repository contains external type annotations for lxml. It can be used by type-checking tools (currently supporting mypy and pyright) to check code that uses lxml, or used within IDEs like VSCode or PyCharm to facilitate development.

Improvements

There are lots of enhancements on top of lxml-stubs:

  • Main goal ① Completes annotation for at least 90% of publicly used lxml API. Besides various completed classes and methods, here are currently implemented extra submodules:
    • lxml.builder
    • lxml.html.builder
    • lxml.html.clean
    • lxml.html.html5parser
    • lxml.html.soupparser
    • lxml.sax
    • Check out project page for future plans and progress
  • Main goal ② All existing contributions reviewed thoroughly, bringing coherency of annotation across the whole package
    • Guarantees error free for pyright basic checking mode as well
    • Much more extensive test cases
  • Modernize package building infrastructure

Installation

From PyPI

This is the normal choice for most people:

pip install -U types-lxml

If there is plan to use html submodule for external libraries (mainly lxml.html.html5parser and lxml.html.soupparser), please install extra dependencies instead:

pip install -U types-lxml[extra]

From downloaded wheel file

Head over to latest release in GitHub and download wheel file (with extension .whl), which can be installed in the same way as PyPI package:

pip install -U types-lxml*.whl

Bleeding edge from GitHub

pip install -U git+https://github.com/abelcheung/types-lxml.git

Special notes

There are two special stub-only classes that do not exist as concrete class in lxml:

  1. lxml.etree.ParserTarget
  2. lxml.etree.SmartStr

They are intended as helpers when writing code, wrapped under if TYPE_CHECKING: .... Please consult their docstring in stub files for detail, or if you are using IDEs, the docstring might have been formatted nicely for reference.

Stub docstring in PyCharm Documentation Tool

Stub docstring in VSCode mouseover tooltip

History

Type annotations for lxml were initially included in typeshed, but as it was still incomplete, it was decided to be ripped out as a separate project. The code was extracted by Jelle Zijlstra and moved to lxml-stubs repository using git filter-branch.

types-lxml is a fork of lxml-stubs that strives for completeness, so that most people would at least find it usable; while the the original lxml-stubs aims to be stable.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

types-lxml-2022.4.10.tar.gz (45.4 kB view hashes)

Uploaded Source

Built Distribution

types_lxml-2022.4.10-py3-none-any.whl (35.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page