skillfed

elementpath

XPath 1.0/2.0/3.0/3.1 parsers and selectors for ElementTree and lxml

elementpath v5.1.4 8.9M downloads/30d#1,576 on PyPI91
Permissive license MIT Active released

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 elementpath

uv

uv add elementpath

poetry

poetry add elementpath

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: Science/ResearchOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: LibrariesTopic :: Text Processing :: Markup :: XML

Tags

xpath selector for elementtreexpath 2.0 3.0 xml querylxml xpath parserxml path expression evaluatorelementtree xpath supportxpath query language implementation
xml-parsingxpath-query

More Libraries packages