Skip to main content

Contains a trie of prefixes for fast lookups

Project description

Informational Badges:

PyPI version PyPy PyPI - Python Version Tests Linux macOS Intel macOS ARM Windows

Some Linting Badges (Where I could find them):

Ruff Code style: black Checked with mypy Imports: isort Pylint try/except style: tryceratops

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

  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.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


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.2.5.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: lib_cidr_trie-1.2.5.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for lib_cidr_trie-1.2.5.tar.gz
Algorithm Hash digest
SHA256 706d04a3bf721949a9db3e53ecf3523557dd63474f1bb9e6e074216f1d164613
MD5 66c8e567c87832a51ade317ea1b76b88
BLAKE2b-256 316e4ff609ff8e6e60673850410f7461bedeb3fe1d467c6aa3b05e9f9f90ce83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lib_cidr_trie-1.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f16c2599c065d02908247c3d0ba7cc5dd841f573dfd8c2f2acb1b25f6ea8ddfb
MD5 7d0298a048a33fc6529544443268c142
BLAKE2b-256 4fa44522358106cc32f492e841e448f6b3c7741f3335daad143825fae37254fe

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