No project description provided
Project description
routelookup
A simple, pure Python implementation of routing table-style IP prefix lookups. Compatible with Python 3.10 and higher.
Features
- Portable
- No dependencies outside the standard library
- Longest-prefix lookup is O(1) on average
routelookup.pytriciais a drop-in replacement for Pytricia for IPv4 and IPv6 addresses, and passes the Pytricia test suite.- Includes support for both
ipaddressandnetaddrand can be easily extended to support other libraries.
Contributing
Feature requests and bug reports are not being accepted without a pull request.
Usage
RouteTable
>>> from ipaddress import IPv4Network
>>> from routelookup.routetable 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 module, Copyright (c) 2001 Python Software Foundation; All Rights Reserved.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file routelookup-1.0.1.tar.gz.
File metadata
- Download URL: routelookup-1.0.1.tar.gz
- Upload date:
- Size: 8.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a15ff52d19b63c70b8423193f169d4ecc7f1f8af68d1ad6738deaa02cd438d42
|
|
| MD5 |
83cc0330f537a02084fbcfa17654eac7
|
|
| BLAKE2b-256 |
5562fac944835d9aed920024daf70cbff7a456dd2b0a0fe9fe28645fa12becf7
|
File details
Details for the file routelookup-1.0.1-py3-none-any.whl.
File metadata
- Download URL: routelookup-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.1 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8262d9722c5c5db27e4c5c77f7f9ab20598b6328a93ecdcfa1c798004bece44b
|
|
| MD5 |
2425d7e4cfc6f2fd8cb18510ffb2d9f6
|
|
| BLAKE2b-256 |
28725caa45f6c6762d7a62386ef9a848050dd7f9808dd0e373dba0d5f5a9cabc
|