talira

XML and HTML processing for Python

open sourceBSD-3-Clausefree

lxml is a Python binding for the C libraries libxml2 and libxslt, combining their speed and XML feature coverage with a Pythonic API that is mostly compatible with ElementTree. It parses and serialises XML and HTML, including incremental and event-based parsing, supports XPath and XSLT with Python extension functions, validates against DTD, RelaxNG, XML Schema and Schematron, and adds lxml.objectify for working with XML as Python objects and lxml.html for HTML parsing, link handling, forms, diffs and CSS selectors.

Problems it solves

  • parse a large XML file in Python quickly and query it with XPath
  • validate XML documents against an XML Schema from Python
  • run an XSLT stylesheet on XML from a Python script
  • pull data out of messy HTML pages in Python

Features

  • ElementTree-compatible API
  • XPath and XSLT, with Python extension functions
  • validation with DTD, RelaxNG, XML Schema and Schematron
  • lxml.html for HTML parsing, links, forms and diffs
  • CSS selectors via lxml.cssselect
  • incremental and event-based parsing with iterparse

Alternatives

The same job

These do what lxml does.

  1. xmltodict Work with XML in Python as if it were JSON: parse it into dicts and back
  2. Beautiful Soup Python library for pulling data out of HTML and XML

Compare lxml with the top 3