Contains a trie of prefixes for fast lookups
Project description
Informational Badges:
Some Linting Badges (Where I could find them):
If you like this package please leave a github star so I know to continue maintaining it :)
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 lib_cidr_trie
pytest lib_cidr_trie
ruff check lib_cidr_trie
ruff format lib_cidr_trie
mypy lib_cidr_trie
You can run isolated builds across multiple environments with:
cd lib_cidr_trie
tox --skip-missing-interpreters
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
-
1.2.6 Fixed a bug in the pyproject.toml that screwed up non-local installs
-
1.2.5 Updated README
-
1.2.4 Updated docs and test deps
-
1.2.3 Updated package metadata and fixed some formatting for linters
-
1.1.2 Python version updates
-
1.1.1 Dependency updates
-
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
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
Built Distribution
File details
Details for the file lib_cidr_trie-1.2.6.tar.gz
.
File metadata
- Download URL: lib_cidr_trie-1.2.6.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3be8116a4fb8104fda3e139f65de30aeb61200f7d9c4ea0a094836ca2bfe7487 |
|
MD5 | 2737c6cdae5fc36db1d35c53fc30e9ee |
|
BLAKE2b-256 | 67c17525e476b3de9d328f52f4d6a3b85063af6ba193d44ef895a85b466e0d14 |
File details
Details for the file lib_cidr_trie-1.2.6-py3-none-any.whl
.
File metadata
- Download URL: lib_cidr_trie-1.2.6-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b602dd51aacc26f223212fca5fae4f27d1507587e1f87b0db29ba530ea6a15d3 |
|
MD5 | fc9931eeaa42269064c056b5c3740fbd |
|
BLAKE2b-256 | b89dcb85768e0a0703e5bba00a4f70ca82ca3bf2872272b5dbf2d18ad661eb83 |