Registry / serialization / elementpath

elementpath

JSON →
library5.1.4pypypi✓ verified 31d ago

ElementPath is a comprehensive Python library providing XPath 1.0, 2.0, 3.0, and 3.1 parsers and selectors. It works seamlessly with both Python's built-in `ElementTree` and the more performant `lxml` library. Currently at version 5.1.1, it maintains a regular release cadence, typically releasing new versions monthly or bi-monthly, often including bug fixes, performance improvements, and Python version compatibility updates.

pip install elementpath
INSTALL
IMPORT
SIG · ELEMENTPATH
E
elementpath
serializationpythonv5.1.4
Install
1.8s avg
Import
367ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v5.1.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.390s · 19.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.8s · import 0.344s · 20MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

select
✓ from elementpath import select
The primary function for selecting nodes using an XPath expression.
Selector
✓ from elementpath import Selector
Used for creating reusable XPath selector objects, especially for complex or frequently used expressions.
XPathContext
✓ from elementpath.xpath_context import XPathContext
For advanced usage involving custom contexts, variables, or functions.

This example demonstrates how to parse an XML string using `ElementTree` and then use `elementpath.select` to query elements with an XPath expression. It prints the text content of all 'item' elements found.

import xml.etree.ElementTree as ET from elementpath import select xml_string = """ <root> <item id="1">First item</item> <item id="2">Second item</item> <item id="3">Third item</item> </root> """ # Parse the XML string using ElementTree root = ET.fromstring(xml_string) # Select all 'item' elements under 'root' items = select(root, '/root/item') # Extract text from selected items results = [item.text for item in items] print(results) # Expected output: ['First item', 'Second item', 'Third item']
Debug
Known issues
breakingPython 3.8 and 3.9 compatibility was dropped in recent major versions. `elementpath` v5.0.0 dropped support for Python 3.8, and v5.1.0 dropped support for Python 3.9.
fix
Ensure your Python environment is running Python 3.10 or newer. Upgrade your Python interpreter if you encounter `ImportError` or other compatibility issues.
affects: >=5.0.0
breakingThe internal XML parser was replaced. `SafeXMLParser` was removed and replaced with `SafeExpatParser` in version 5.0.0. This is an internal change but could affect users who relied on direct access to or configuration of the previous parser.
fix
Review any code that directly interacts with `elementpath`'s internal parsing mechanisms. Most users relying on the high-level `select` or `Selector` APIs should not be affected.
affects: >=5.0.0
breakingInternal node tree structure changed significantly with the introduction of `XPathNodeTree` as the backbone for node representation. This impacts advanced users extending the library or introspecting its internal data structures.
fix
If you have custom node handling or extensions, you may need to update your code to align with the new `XPathNodeTree` structure. Consult the official documentation for details on the new node model.
affects: >=5.0.0
gotchaXPath expressions often require explicit handling of XML namespaces. If your XML document uses namespaces and your XPath expressions don't account for them, you might get no results or incorrect ones.
fix
Provide a namespace map when calling `select` or `Selector`. For example: `select(root, '/ns:root/ns:item', namespaces={'ns': 'http://example.com/ns'})`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'elementpath'
The 'elementpath' library has not been installed in your Python environment.
fix
pip install elementpath
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'select'
The `select` function is a module-level function in `elementpath`, not a method on `ElementTree` or `lxml` Element objects.
fix
import elementpath as ep; ep.select(element_object, 'your_xpath_expression')
elementpath.xpath_base.ElementPathTypeError: The type of the context item is not appropriate for the XPath expression.
The XPath expression is attempting an operation (e.g., arithmetic, comparison) with an incompatible data type or an incorrect context item.
fix
Review and correct your XPath expression to ensure data types (e.g., node-set, string, number, boolean) are used appropriately for the intended operation.
elementpath.xpath_parser.XPathSyntaxError: Syntax error at line 1, column ...: Unexpected token ...
The provided XPath expression contains a syntax error, making it unparsable by the elementpath engine.
fix
Carefully check the XPath expression for typos, missing characters, or incorrect structure according to XPath specifications (e.g., XPath 3.1).
Upgrade
Version history
5.1.4latest on PyPI · released Aug 8, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
Resources
elementpath — pip install elementpath · libregistry