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

Release history Release notifications

This version


Download files

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

Files for lxml-xpath-ipaddress, version 0.2.0
Filename, size & hash File type Python version Upload date
lxml_xpath_ipaddress-0.2.0-py3-none-any.whl (6.7 kB) View hashes Wheel py3
lxml-xpath-ipaddress-0.2.0.tar.gz (3.6 kB) View hashes Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page