Skip to main content

Treat XPath expressions as Python objects

Project description

ci pypi

pip install xpath-expressions

This is a small, lightweight Python 3.5+ library to aide in the manipulations of xpath expressions, allowing you to manipulate them as Python objects with Python expressions. For example:

from xpath import Expression as E, Attribute as A

root_node = E('/root')
all_children = root_node.children         # /root/*
root_node_name = root_node.name           # name(/root)
an_attribute = root_node.attributes[1]    # /root/@*[1]

attrs = A('abc') == 'def'                 # @abc='def'
filtered = root_node.children[attrs]      # /root/*[@abc='def']

# The library handles quoting for you:
attr2 = A('abc') == "def'"
filtered2 = root_node.children[attrs]     # /root/*[@abc="def'"]

# You can also use xpath functions:
from xpath.functions import string_length
length = string_length(root_node.name)    # string-length(name(/root/))
is_length_5 = length == 5                 # string-length(name(/root/)) == 5

There is a lot more you can do, check out the main Expression class.

Not all functions are defined in the xpath.functions` module. To add your own, simply define: ``myfunc = Function('my-func'). Please make a merge request if you want some more added to the library!

Why

Manipulating xpath expressions as strings is error-prone and annoying. This library makes it really simple.

It was split out from XCat into a separate module.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xpath-expressions-0.2.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

xpath_expressions-0.2.2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file xpath-expressions-0.2.2.tar.gz.

File metadata

File hashes

Hashes for xpath-expressions-0.2.2.tar.gz
Algorithm Hash digest
SHA256 84475bde91ca391451f03d7da6c09983ca476344dcc3ff04c126fd2f9dd326f3
MD5 3e2b6da2ae5ce67182d7908c37132d40
BLAKE2b-256 345e0623e770113a404d6bea8d24d9678fb8a020010a9d96b604c6f4935ab794

See more details on using hashes here.

File details

Details for the file xpath_expressions-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for xpath_expressions-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fcf8035e25dbf6354321f3ee82d8ae52d0caa8f66883cdefb7226a1ff48ad08a
MD5 ffe95b1ff1953e7503457ca8808290cf
BLAKE2b-256 ff91aff12d7c3efba8111cfc5b131da2c129e97427ab89f117b246427fc08589

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page