elementpath
XPath 1.0/2.0/3.0/3.1 parsers and selectors for ElementTree and lxml
What it is and what it does
elementpath is an XPath parser and selector library that extends ElementTree and lxml with support for XPath 2.0, 3.0, and 3.1 expressions. While lxml already provides XPath 1.0 natively, elementpath fills the gap for higher XPath versions on both standard ElementTree and lxml data structures. The package implements a Pratt-style top-down operator precedence parser and exposes a simple API: the `select()` function returns results in standard XPath format (a list or elementary datatype), while `iter_select()` provides a generator for iteration. For repeated queries, you can instantiate a `Selector` object with a compiled XPath expression and apply it to multiple XML trees.
The library defaults to XPath 2.0 but allows you to specify alternative parsers via the `parser` argument. XPath 3.0 and 3.1 are available through subpackages to keep the default import focused. It has no runtime dependencies, installs cleanly, and is actively maintained with support for Python 3.10 through 3.15.
Use it for:
- Query XML documents using XPath 2.0+ expressions when ElementTree's built-in XPath 1.0 support is insufficient.
- Migrate XPath queries from other tools to Python by using standard XPath 2.0/3.0 syntax on ElementTree data.
- Apply the same compiled XPath selector to multiple XML documents efficiently using the Selector class.
- Use advanced XPath 3.0 features like math functions when processing scientific or technical XML data.
- Extract nested XML elements and attributes with complex path expressions without manual tree traversal.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides XPath 1.0, 2.0, 3.0, and 3.1 selectors for querying ElementTree and lxml XML data structures using standard XPath expressions.
Yes. The package is actively maintained, has no dependencies, supports current Python versions, carries no known vulnerabilities, and solves a real gap—providing XPath 2.0+ support for ElementTree and lxml. Install it if you need to query XML with XPath expressions beyond version 1.0.
Install
elementpath on PyPI
pip
pip install elementpathuv
uv add elementpathpoetry
poetry add elementpathInstalling elementpath
Before you install
Low install friction with no runtime dependencies. Active maintenance with a release 6 days ago and recent commits. Supports Python 3.10 through 3.15.
License in practice
MIT license is permissive, allowing use in commercial and proprietary projects with minimal restrictions.
Quickstart
pip install elementpath
import elementpath
from xml.etree import ElementTree
root = ElementTree.XML('<A><B1/><B2><C/><D/></B2></A>')
results = elementpath.select(root, '/A/B2/*')
Requires Python 3.10 or later.
Verify before relying
- Performance characteristics when querying large XML documents or complex XPath expressions.
- Completeness of XPath 3.0/3.1 feature coverage relative to the official specifications.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 6 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 8,932,722/month — #1,576 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: elementpath-5.1.4-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
cssselectcssselect parses CSS3 selectors and translates…
permissive · top 1,000 on PyPI
lxmllxml provides Python bindings to libxml2 and…
permissive · top 1,000 on PyPI
saxoncheSaxonC-HE is a Python wrapper for Saxon, an XML…
unclear · top 5,000 on PyPI
parselParsel extracts data from HTML, JSON, and XML…
permissive · top 5,000 on PyPI
itemloadersItemloaders extracts and standardizes…
permissive · top 5,000 on PyPI
cssselect2cssselect2 parses and matches CSS4 selectors…
permissive · top 1,000 on PyPI
xmlunittestExtends Python's unittest framework to compare…
permissive · top 5,000 on PyPI
objectpathObjectPath is a query language for finding and…
permissive · top 15,000 on PyPI
jsonpathImplements JSONPath, a query language for…
permissive · top 5,000 on PyPI
meld3meld3 is an HTML/XML templating system that…
permissive · top 15,000 on PyPI