# lxml — card for AI agents

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

Category: Scraping, browsers and parsing · PyPI package `lxml` · latest version 6.1.3 (checked 2026-11-01)
Install: `pip install lxml`
License: BSD-3-Clause (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (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.

## What it is
- lxml is a Python library for reading, writing and transforming XML and HTML. The website describes it as "a Pythonic binding for the C libraries libxml2 and libxslt". The maintainers say it pairs the speed and standards coverage of those C libraries with an API that is "mostly compatible but superior to the well-known ElementTree API". The project is BSD-3-Clause licensed, and its GitHub repository dates from 2011-02-11.
- Most work happens in `lxml.etree`. It follows ElementTree on top of the native libxml2 tree and adds XPath, XSLT, Relax NG, XML Schema and c14n. Separate modules cover other jobs. `lxml.objectify` is a data-binding API. `lxml.html` handles HTML parsing, forms, links and diffs. `lxml.cssselect` adds CSS selectors. There are also parsers backed by BeautifulSoup and html5lib.
- It suits Python developers who need standards-heavy XML work, such as validation, XSLT or namespaces, or HTML scraping through XPath and CSS selectors. The docs also describe a SAX-compliant API and a C-level API for writing extensions in C or Cython.

## Caveats
- 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.
- Very little funding: The README reports well over 250 million monthly PyPI downloads, against EUR 3868.43 of total income in 2025. That works out to 1.46 € per million downloads.
- Version info disagrees across pages: The website names 7.0.0a3 (2026-06-16) as the latest version and says the latest release supports CPython 3.6 to 3.12. The GitHub releases page lists lxml-6.1.3-1, published 2026-09-02. Check which release you pin.

## Numbers (AgentGid data)
- Gid Score: 72.2 (#305 of all tools, 9 of 141 in its category)
- Used in 79 public projects set up for AI coding agents (1.3%)
- Downloads last week: 97,465,999 (as of 2026-11-24), +18.5% over 4 weeks
- GitHub stars: 3,077 (as of 2026-11-24)
- Last push: 2026-11-23

## Often used with
Beautiful Soup 70.9%, Requests 60.8%, python-dotenv 58.2%, Pydantic 46.8%, Uvicorn 43.0%, Pillow 41.8%

## Checked alternatives (same job)
- Beautiful Soup: https://agentgid.com/tools/beautifulsoup4/agent.md
- html5lib: https://agentgid.com/tools/html5lib/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/lxml/
- Homepage: https://lxml.de/
- Repository: https://github.com/lxml/lxml
- Source: https://github.com/lxml/lxml#readme
- Source: https://github.com/lxml/lxml
- Source: https://github.com/lxml/lxml/releases
- Source: https://lxml.de/

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
