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
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
- 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
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
lib_cidr_trie-1.0.0.tar.gz
(5.9 kB
view details)
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 488e831ab4d6b997ba67577ba1baa22aa6b71a9dbf5debd274971f32817b4e2b |
|
MD5 | f66ebf4582ea08432bf78c79e6e8d05a |
|
BLAKE2b-256 | 64a1d69fa9afaf48b2a2b7415a291068b9ce415bb59fed0b268ba4973cdb4107 |
File details
Details for the file lib_cidr_trie-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: lib_cidr_trie-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89b137a768541c98918b520a38757091b04a579fd16ec8c7c20a86a9b48afa6d |
|
MD5 | 6c5f5f049a1e8b0feee258f103d8ac1f |
|
BLAKE2b-256 | 73f97b47a53eb9a9817eadd3d58d2a619e58cc0f6046a19e13fa8d8c0ca48256 |