Skip to main content

No project description provided

Project description

routelookup

A simple, pure Python implementation of routing table-style IP prefix lookups.

Features

  • Portable
  • No dependencies outside the standard library
  • Longest-prefix lookup is O(1) on average
  • routelookup.pytricia is a drop-in replacement for Pytricia for IPv4 and IPv6 addresses, and passes the Pytricia test suite.
  • Includes support for both ipaddress and netaddr and can be easily extended to support other libraries.

Contributing

Feature requests and bug reports are not being accepted. If you find a bug, please submit a pull request.

Usage

RouteTable

>>> from ipaddress import IPv4Network
>>> from routelookup.routetable.base import BaseRouteTable
>>> from routelookup.addrmodule.ipaddress import IpaddressAddrHandler
>>> table = BaseRouteTable(IpaddressAddrHandler())
>>> table["192.168.1.0/24"] = "hello"  # supports strings
>>> table[IPv4Network("192.168.1.128/25")] = "world"  # supports IPv4Network objects too
>>> "10.0.0.1" in table
False
>>> "192.168.1.5" in table
True
>>> table["192.168.1.192/26"]
'world'
>>> table[IPv4Network("192.168.1.192/26")]
'world'
>>> table.lookup_worst("192.168.1.192/26")
'hello'
>>> list(table.items())
[(IPv4Network('192.168.1.0/24'), 'hello'), (IPv4Network('192.168.1.128/25'), 'world')]
>>>

routelookup.pytricia

>>> from routelookup.pytricia import PyTricia
>>> table = PyTricia()
>>> table["10.0.0.0/8"] = "hello"
>>> table["10.1.0.0/16"] = "world"
>>> "10.1.1.0/24" in table
True
>>> table["10.1.1.0/24"]
'world'
>>> table.get_key("10.1.1.0/24")
'10.1.0.0/16'
>>> table.children("10.0.0.0/8")
['10.1.0.0/16']
>>>

Credits

Code in routelookup/python_ipaddress.py is derived from Python's ipaddress standard library, Copyright (c) 2001 Python Software Foundation; All Rights Reserved.

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

routelookup-1.0.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

routelookup-1.0.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file routelookup-1.0.0.tar.gz.

File metadata

  • Download URL: routelookup-1.0.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.16 Linux/6.12.5-200.fc41.x86_64

File hashes

Hashes for routelookup-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7e40a84c8255bf73b452de5a292e3ef6e98d516e9f265c07d6aae02106f29573
MD5 2edc12cff2e7a95e9f769a6fe602defd
BLAKE2b-256 2cc908a441a8cfbe9897986623c81d3199a0f99f7e6e52317941586a94790163

See more details on using hashes here.

File details

Details for the file routelookup-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: routelookup-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.10.16 Linux/6.12.5-200.fc41.x86_64

File hashes

Hashes for routelookup-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61815fcc89dcae283eb6d95d7565ea3aafed438b0c1aa1e2e1daccebaa4c80f8
MD5 7536b0fdb801d814b518cdab7de10123
BLAKE2b-256 59318752aeafd218761ff619f8bacf29b387510b9c3148b5431f5f0848c5f10b

See more details on using hashes here.

Supported by

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