Skip to main content

LXML xpath extension library for ipaddress

Project description

LXML Extension Library for IP address

This library contains LXML extension functions that wrap the Python ipaddress library.

With this library in place, you can do XPath expressions to find IP items within our XML data. For example:

from lxml import etree
from lxml_xpath_ipaddress import ip_ns

# given "config" is an LXML XML structure, you can run the XPath to find all IPv4 network items:

config = etree.parse('tests/config.xml')

items = config.xpath('//*[ip:ip4-net(.)', namespaces=ip_ns)

# >>>

# Find all items that are in either the 172.18/16 or 101.10.201/24 subnets

items = config.xpath('//*[ip:in-subnet(., "") or ip:in-subnet(., "")]',

# >>>


$ pip install lxml-xpath-ipaddress

LXML Extension Functions

Either IPv4 or IPv6

  • ip-any(value)
  • ip-net(value)
  • ip-host(value)


  • ip4-any(value)
  • ip4-net(value)
  • ip4-host(value)


  • ip6-any(value)
  • ip6-net(value)
  • ip6-host(value)

Subnet Checking

  • in-subnet(value, subnet-string)

Python Functions

The library contains these functions as general purpose functions as well, so that they can be used in other applications. See the module doc-strings for use.

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

lxml-xpath-ipaddress-0.2.0.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

lxml_xpath_ipaddress-0.2.0-py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 3

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