Creates a CIDR trie
Project description
lib_cidr_trie
This package contains a trie of prefixes for fast lookups
Usage
from ipaddress import ip_network
from lib_cidr_trie import IPv4CIDRTrie, IPv6CIDRTrie
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:
trie.insert(cidr)
for cidr in cidrs:
assert cidr in trie
assert trie.get_most_specific_trie_supernet(cidr).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:
assert invalid_cidr not in trie
assert trie.get_most_specific_trie_supernet(invalid_cidr) is None
assert ip_network("1.2.4.0/24") in trie
assert ip_network("1.2.0.255") in trie
assert ip_network("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
python3 setup.py develop
To test the development package: Testing
Testing
You can test the package if in development by moving/cd into the directory where setup.py is located and running:
(Note that you must have all dependencies installed first)
python3 setup.py test
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
- 0.0.3 Made it easier to subclass CIDRTrie
- 0.0.2 README update
- 0.0.1 First working version
Credits
License
BSD License (see license file)
TODO
- lib_cidr_trie
- Needs better testing
- Would be nice to have some traversal funcs
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-0.0.3.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for lib_cidr_trie-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c214caeb3a952c2e442876ef1d8af74cc9ff991aad2d350a51e9b7d2be07520 |
|
MD5 | 05c41defbbd98e003f36640546336892 |
|
BLAKE2b-256 | ddc041c39a1b8d911bf43b4b93d142c72cbb334f57cc866714e44fd9c3c0eadf |