lxml

6.0.2 · active · verified Sat Mar 28

lxml is a powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API. The current version is 6.0.2, released on March 28, 2026. It follows a regular release cadence, with recent versions 6.0.1 and 6.0.0 released on March 15, 2026, and March 1, 2026, respectively.

Warnings

Install

Imports

Quickstart

This script demonstrates loading an XML file and performing an XPath query using lxml's etree module.

import os
from lxml import etree

# Load XML from a file
with open(os.environ.get('XML_FILE_PATH', 'sample.xml'), 'rb') as f:
    tree = etree.parse(f)

# Perform XPath query
result = tree.xpath('//element[@attribute="value"]')

# Process result
for elem in result:
    print(etree.tostring(elem))

view raw JSON →