Skip to main content

A short description of your package

Project description

Current Version: 1.0.0

IPPrefixTrie is a project developed and sponsored by Interstellio IO. It serves a dual purpose—as an educational resource and as a functional library for managing and querying IP prefixes using an IP prefix trie (binary prefix tree). It is licensed under the GNU Lesser General Public License (LGPL).

This implementation is not a Radix tree or Patricia tree; it is a binary prefix tree, meaning it does not use path compression but explicitly represents each bit in the prefix. This structure is commonly used in networking applications where prefix-based lookups are required.

Supported Features:

  • IPv4 and Ipv6 prefixes.

  • Exact Prefix Matches.

  • Longest Prefix Match.

  • Or Longer Prefix Matches.

  • Metadata per prefix. (for example your own defined dictionary that could contain paths etc.)

We welcome anyone who wishes to optimise or introduce other types of trees.

Documentation: https://ipprefixtrie.readthedocs.io

Installation

To install the IPPrefixTrie module, use the following command:

pip install ipprefixtrie

Usage

Here’s a quick example of how to use the IPPrefixTrie module:

from ipprefixtrie import IPPrefixTrie

trie = IPPrefixTrie()
trie.insert("192.168.1.0/24", {"desc": "Private IPv4 range"})
trie.insert("2001:db8::/32", {"desc": "Documentation IPv6 range"})

# Lookup an exact prefix
print(trie.get_exact("192.168.1.0/24"))  # Returns: ('192.168.1.0/24', {'desc': 'Private IPv4 range'})

# Get longest matching prefix
print(trie.get_longest("192.168.1.100"))  # Returns: ('192.168.1.0/24', {'desc': 'Private IPv4 range'})

# Find more specific prefixes
print(list(trie.get_orlonger("192.168.1.0/24")))

What is a Binary Prefix Tree?

A binary prefix tree is a data structure designed for prefix-based searching. Each node in the tree represents a bit of an IP address, making it well-suited for longest prefix match (LPM) operations, commonly used in network routing, firewall rules, and access control lists (ACLs).

Unlike Radix or Patricia trees, a binary prefix tree maintains an explicit path for every bit in the IP address, making it more straightforward but potentially more significant in memory footprint. This makes it useful for both practical implementations and educational learning, where a clear and intuitive understanding of IP prefix operations is required.

Educational and Practical Purpose

This project is also designed for learning and experimentation with IP prefix management while also serving as a practical tool for prefix-based lookups. While not optimised for high-performance production environments, it serves as an excellent reference for:

  • Understanding network prefix matching in Python.

  • Exploring how trie-based data structures work.

  • Implementing basic networking concepts like routing tables and firewall rules.

License

IPPrefixTrie is released under the LGPL License, meaning you are free to use, modify, and distribute it under the terms of the GNU Lesser General Public License.

For more details, see: https://www.gnu.org/licenses/lgpl-3.0.html

Contributing

Contributions to this project are welcome! If you’d like to report issues or suggest improvements, please submit a pull request or open an issue on the repository.

All code should follow the PEP-8 standard as outlined here: https://peps.python.org/pep-0008/

Contact

For inquiries about IPPrefixTrie, please contact Interstellio IO at:

Website: [https://www.interstellio.io](https://www.interstellio.io) Email: opensource@interstellio.io

You can also view the MAINTAINERS file for contacts.

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

ipprefixtrie-1.0.0.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

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

ipprefixtrie-1.0.0-py2.py3-none-any.whl (22.6 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: ipprefixtrie-1.0.0.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for ipprefixtrie-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1e78c5f6e252eefd68b60a03a360a7e87e278f5c220517598bd3aee2cbf47f12
MD5 28777be4fd8cbce820dca33d6b87794e
BLAKE2b-256 5e15d1659d02b9a561b9da82f5e92ea0327e7217700e67216ac16c6eb1c6b663

See more details on using hashes here.

File details

Details for the file ipprefixtrie-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: ipprefixtrie-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for ipprefixtrie-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4ecee1d37ca00b29e20e6335d884491ed5a51f6d8317692881288305e0acac15
MD5 af0fa754c7d6099b48e854ecab94f9a6
BLAKE2b-256 5cce31ef3baba4757a51c2542cadccc1af2df15136e3d233a198995926e758ec

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