Skip to main content

Contains a trie of prefixes for fast lookups

Project description

lib_cidr_trie

This package contains a trie of prefixes for fast lookups

Usage

trie = IPv4CIDRTrie()
cidrs = [ip_network(x) for x in ["1.2.0.0/16", "1.2.3.0/24", "1.2.3.4"]]
for cidr in cidrs:
    # for mypy
    assert isinstance(cidr, IPv4Network)
    trie.insert(cidr)
for cidr in cidrs:
    assert isinstance(cidr, IPv4Network)
    assert cidr in trie
    node = trie.get_most_specific_trie_supernet(cidr)
    assert node is not None and node.prefix == cidr

invalid_cidrs = [ip_network(x) for x in ["1.0.0.0/8", "255.255.255.255"]]
for invalid_cidr in invalid_cidrs:
    # for mypy
    assert isinstance(invalid_cidr, IPv4Network)
    assert invalid_cidr not in trie
    assert trie.get_most_specific_trie_supernet(invalid_cidr) is None

assert IPv4Network("1.2.4.0/24") in trie
assert IPv4Network("1.2.0.255") in trie
assert IPv4Network("1.3.0.0/16") not in trie

Installation

Install python and pip if you have not already. Then run:

pip3 install lib_cidr_trie

This will install the package and all of it's python dependencies.

If you want to install the project for development:

git clone https://github.com/jfuruness/lib_cidr_trie.git
cd lib_cidr_trie
pip3 install -e .[test]
pre-commit install

To test the development package: Testing

Testing

After installing the package for development,

cd lib_cidr_trie
python3 -m pytest lib_cidr_trie

Development/Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request
  6. Email me at jfuruness@gmail.com because I don't check github messages

History

  • lib_cidr_trie
  • 1.0.0 Added linters, updated package structure, fixed typing issues
  • 0.0.3 Made it easier to subclass CIDRTrie
  • 0.0.2 README update
  • 0.0.1 First working version

License

BSD License (see license file)

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

lib_cidr_trie-1.0.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

lib_cidr_trie-1.0.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lib_cidr_trie-1.0.0.tar.gz
Algorithm Hash digest
SHA256 488e831ab4d6b997ba67577ba1baa22aa6b71a9dbf5debd274971f32817b4e2b
MD5 f66ebf4582ea08432bf78c79e6e8d05a
BLAKE2b-256 64a1d69fa9afaf48b2a2b7415a291068b9ce415bb59fed0b268ba4973cdb4107

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lib_cidr_trie-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89b137a768541c98918b520a38757091b04a579fd16ec8c7c20a86a9b48afa6d
MD5 6c5f5f049a1e8b0feee258f103d8ac1f
BLAKE2b-256 73f97b47a53eb9a9817eadd3d58d2a619e58cc0f6046a19e13fa8d8c0ca48256

See more details on using hashes here.

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