Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 4 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

lxml

High-performance XML and HTML processing library combining libxml2/libxslt with Python.

Scraping, browsers and parsingPYPI

GitHubWebsite

1. License

License from PyPI license field.

github.com/lxml/lxml

From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error

What lxml does

lxml puts the C libraries libxml2 and libxslt behind a Python API modeled on ElementTree, and its README publishes a candid income report: well over 250 million downloads a month, EUR 3868.43 of project income in 2025.

lxml popularity

72 / 100
Gid Score, #305 overall
97.5M
downloads a week, pypi
3,077
GitHub stars
79
agent projects use it
lxml: downloads per weekPyPI, lxml 98,367,746
lxml: GitHub starslxml/lxml 3,077

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How lxml is used

  • lxml is a dependency in 79 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (4.9% of the 1,623 Python ones), #4 of 141 in scraping, browsers and parsing.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 933; those are left out of every share on this page.
  • The most used alternative in our scan is Beautiful Soup (133 projects).
  • Projects that use it most often also use Beautiful Soup (70.9%), Requests (60.8%), python-dotenv (58.2%).

By coding agent

42 projects, 1.3%
37 projects, 1.2%
27 projects, 1.1%
5 projects, 1.5%

Often used with

In 70.9% of its projects
In 60.8% of its projects
In 58.2% of its projects
In 46.8% of its projects
In 43.0% of its projects
In 41.8% of its projects
In 40.5% of its projects
In 39.2% of its projects

lxml in practice

Strengths

C engines, ElementTree-shaped API

The maintainers say lxml combines the speed and XML feature completeness of libxml2 and libxslt with a native Python API. That API is mostly compatible with ElementTree, so ElementTree tutorials largely carry over.

Several schema languages for validation

The docs cover validation at parse time and validation against DTD, RelaxNG, XML Schema and Schematron, all in the same library as XPath and XSLT.

Python functions inside XPath and XSLT

You can call your own Python code from XPath expressions and XSLT stylesheets through extension functions.

Several HTML parsers to choose from

Besides <code>lxml.html</code>, the docs describe a BeautifulSoup-backed <code>soupparser</code>. It can serve as a fallback or for encoding detection only. There is also an html5lib parser.

Watch out for

XML Schema support has gaps

Standards compliance depends on libxml2 and libxslt. The FAQ says libxml2's XML Schema support is not complete.

XPath 1.0 and XSLT 1.0

The FAQ's list of implemented standards names XPath 1.0 and XSLT 1.0, plus EXSLT. Plan your expressions and stylesheets around those versions.

Not a perfect ElementTree clone

The FAQ admits there are places where lxml cannot match ElementTree behavior. These are listed in a separate compatibility document.

More about lxml

Funding
  • GitHub Sponsors: https://github.com/scoder
  • Tidelift: https://tidelift.com/funding/github/pypi/lxml
  • 22 GitHub sponsors

See all

Head to head
Packages around it
  • beautifulsoup4: HTML parsing
  • requests: HTTP client
  • python-dotenv: .env config loading
  • pydantic: data validation
  • numpy: numeric arrays
  • aiohttp: async HTTP client/server
More in Scraping, browsers and parsing

Alternatives

lxml This page

BSD-3-ClauseGid 7297.5M/wk

Beautiful Soup

Python HTML/XML parsing and screen-scraping library for web data extraction.

MITGid 7876.1M/wk

html5lib

HTML parser based on WHATWG specification for parsing and processing HTML.

MITGid 566.9M/wk

Compare lxml with another tool

Get started

Install it.

pip install lxml

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## lxml
- Import the main module with `from lxml import etree`; the FAQ's examples assume it.
- Write against the ElementTree API first. Use lxml-only features (XPath, XSLT, Relax NG, XML Schema, c14n) when needed, knowing they tie the code to lxml.
- Keep XPath expressions and XSLT stylesheets to XPath 1.0 and XSLT 1.0, the versions in the FAQ's standards list.
- Do not assume complete XML Schema validation: the FAQ says libxml2's support "is currently not 100% complete".
- Before parsing untrusted input or exposing lxml in a web service, read the FAQ entries "Is lxml vulnerable to XML bombs?" and "How do I use lxml safely as a web-service endpoint?".
- Before sharing XSLT stylesheets across threads, read the FAQ's Threading section ("Why can't I reuse XSLT stylesheets in other threads?").
- Report bugs on Launchpad (bugs.launchpad.net/lxml), the issue tracker the README points to.