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

To test the package after installation:

cd roa_collector
pytest roa_collector
ruff roa_collector
black roa_collector
mypy roa_collector

If you want to run it across multiple environments, and have python 3.10 and 3.11 installed:

cd roa_collector
tox

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.1.0 Removed a few type ignores for mypy, added PrefixType to dunder init
  • 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.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

lib_cidr_trie-1.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lib_cidr_trie-1.1.0.tar.gz
  • Upload date:
  • Size: 7.2 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.1.0.tar.gz
Algorithm Hash digest
SHA256 c3ecfdfb4e89ca15f981bb56632e3aec66e50f990e24bd6f179ec69b117f0497
MD5 2199ba11b1416c363e6e762704d7f2f9
BLAKE2b-256 17355383ca99b994178777c450558fde0109d8f7617ac2515ee8559b95905442

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lib_cidr_trie-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for lib_cidr_trie-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c8c4baad131480f5702145de314226b0c64890f48de1324563ac2083fc76290
MD5 c0606fde255d7cc92bbdf9280a56a4ee
BLAKE2b-256 7c5fd9b0da060eed32e52b13fd8dfaf13dea3155f150de8ef322393ffc19ae92

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