py-radix


Namepy-radix JSON
Version 0.10.0 PyPI version JSON
download
home_pagehttps://github.com/mjschultz/py-radix
SummaryRadix tree implementation
upload_time2017-10-09 14:48:33
maintainer
docs_urlNone
authorMichael J. Schultz
requires_python
licenseBSD
keywords radix tree trie python routing networking
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            py-radix
========

.. image:: https://travis-ci.org/mjschultz/py-radix.svg?branch=master
   :target: https://travis-ci.org/mjschultz/py-radix

.. image:: https://coveralls.io/repos/mjschultz/py-radix/badge.png?branch=master
   :target: https://coveralls.io/r/mjschultz/py-radix?branch=master

py-radix implements the radix tree data structure for the storage and
retrieval of IPv4 and IPv6 network prefixes.

The radix tree is commonly used for routing table lookups. It efficiently
stores network prefixes of varying lengths and allows fast lookups of
containing networks.

Installation
------------

Installation is a breeze via pip: ::

    pip install py-radix

Or with the standard Python distutils incantation: ::

	python setup.py build
	python setup.py install

The C extension will be built for supported python versions. If you do not
want the C extension, set the environment variable ``RADIX_NO_EXT=1``.

Tests are in the ``tests/`` directory and can be run with
``python setup.py nosetests``.

Usage
-----

A simple example that demonstrates most of the features: ::

	import radix

	# Create a new tree
	rtree = radix.Radix()

	# Adding a node returns a RadixNode object. You can create
	# arbitrary members in its 'data' dict to store your data
	rnode = rtree.add("10.0.0.0/8")
	rnode.data["blah"] = "whatever you want"

	# You can specify nodes as CIDR addresses, or networks with
	# separate mask lengths. The following three invocations are
	# identical:
	rnode = rtree.add("10.0.0.0/16")
	rnode = rtree.add("10.0.0.0", 16)
	rnode = rtree.add(network = "10.0.0.0", masklen = 16)

	# It is also possible to specify nodes using binary packed
	# addresses, such as those returned by the socket module
	# functions. In this case, the radix module will assume that
	# a four-byte address is an IPv4 address and a sixteen-byte
	# address is an IPv6 address. For example:
	binary_addr = inet_ntoa("172.18.22.0")
	rnode = rtree.add(packed = binary_addr, masklen = 23)

	# Exact search will only return prefixes you have entered
	# You can use all of the above ways to specify the address
	rnode = rtree.search_exact("10.0.0.0/8")
	# Get your data back out
	print rnode.data["blah"]
	# Use a packed address
	addr = socket.inet_ntoa("10.0.0.0")
	rnode = rtree.search_exact(packed = addr, masklen = 8)

	# Best-match search will return the longest matching prefix
	# that contains the search term (routing-style lookup)
	rnode = rtree.search_best("10.123.45.6")

	# Worst-search will return the shortest matching prefix
	# that contains the search term (inverse routing-style lookup)
	rnode = rtree.search_worst("10.123.45.6")

	# Covered search will return all prefixes inside the given
	# search term, as a list (including the search term itself,
	# if present in the tree)
	rnodes = rtree.search_covered("10.123.0.0/16")

	# There are a couple of implicit members of a RadixNode:
	print rnode.network	# -> "10.0.0.0"
	print rnode.prefix	# -> "10.0.0.0/8"
	print rnode.prefixlen	# -> 8
	print rnode.family	# -> socket.AF_INET
	print rnode.packed	# -> '\n\x00\x00\x00'

	# IPv6 prefixes are fully supported in the same tree
	rnode = rtree.add("2001:DB8::/3")
	rnode = rtree.add("::/0")

	# Use the nodes() method to return all RadixNodes created
	nodes = rtree.nodes()
	for rnode in nodes:
		print rnode.prefix

	# The prefixes() method will return all the prefixes (as a
	# list of strings) that have been entered
	prefixes = rtree.prefixes()

	# You can also directly iterate over the tree itself
	# this would save some memory if the tree is big
	# NB. Don't modify the tree (add or delete nodes) while
	# iterating otherwise you will abort the iteration and
	# receive a RuntimeWarning. Changing a node's data dict
	# is permitted.
	for rnode in rtree:
  		print rnode.prefix


License
-------

py-radix is licensed under a ISC/BSD licence. The underlying radix tree 
implementation is taken (and modified) from MRTd and is subject to a 4-term 
BSD license. See the LICENSE file for details.

Contributing
------------

Please report bugs via GitHub at https://github.com/mjschultz/py-radix/issues.
Code changes can be contributed through a pull request on GitHub or emailed
directly to me <mjschultz@gmail.com>.

The main portions of the directory tree are as follows: ::

    .
    ├── radix/*.py      # Pure Python code
    ├── radix/_radix.c  # C extension code (compatible with pure python code)
    ├── radix/_radix/*  # C extension code (compatible with pure python code)
    ├── tests/          # Tests (regression and unit)
    └── setup.py        # Standard setup.py for installation/testing/etc.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mjschultz/py-radix",
    "name": "py-radix",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "radix tree trie python routing networking",
    "author": "Michael J. Schultz",
    "author_email": "mjschultz@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/bf/4e/47d9e7f4dfd0630662e19d2cc1b2f1d307ec52df11f4a66f6ed6f0cce138/py-radix-0.10.0.tar.gz",
    "platform": "",
    "description": "py-radix\n========\n\n.. image:: https://travis-ci.org/mjschultz/py-radix.svg?branch=master\n   :target: https://travis-ci.org/mjschultz/py-radix\n\n.. image:: https://coveralls.io/repos/mjschultz/py-radix/badge.png?branch=master\n   :target: https://coveralls.io/r/mjschultz/py-radix?branch=master\n\npy-radix implements the radix tree data structure for the storage and\nretrieval of IPv4 and IPv6 network prefixes.\n\nThe radix tree is commonly used for routing table lookups. It efficiently\nstores network prefixes of varying lengths and allows fast lookups of\ncontaining networks.\n\nInstallation\n------------\n\nInstallation is a breeze via pip: ::\n\n    pip install py-radix\n\nOr with the standard Python distutils incantation: ::\n\n\tpython setup.py build\n\tpython setup.py install\n\nThe C extension will be built for supported python versions. If you do not\nwant the C extension, set the environment variable ``RADIX_NO_EXT=1``.\n\nTests are in the ``tests/`` directory and can be run with\n``python setup.py nosetests``.\n\nUsage\n-----\n\nA simple example that demonstrates most of the features: ::\n\n\timport radix\n\n\t# Create a new tree\n\trtree = radix.Radix()\n\n\t# Adding a node returns a RadixNode object. You can create\n\t# arbitrary members in its 'data' dict to store your data\n\trnode = rtree.add(\"10.0.0.0/8\")\n\trnode.data[\"blah\"] = \"whatever you want\"\n\n\t# You can specify nodes as CIDR addresses, or networks with\n\t# separate mask lengths. The following three invocations are\n\t# identical:\n\trnode = rtree.add(\"10.0.0.0/16\")\n\trnode = rtree.add(\"10.0.0.0\", 16)\n\trnode = rtree.add(network = \"10.0.0.0\", masklen = 16)\n\n\t# It is also possible to specify nodes using binary packed\n\t# addresses, such as those returned by the socket module\n\t# functions. In this case, the radix module will assume that\n\t# a four-byte address is an IPv4 address and a sixteen-byte\n\t# address is an IPv6 address. For example:\n\tbinary_addr = inet_ntoa(\"172.18.22.0\")\n\trnode = rtree.add(packed = binary_addr, masklen = 23)\n\n\t# Exact search will only return prefixes you have entered\n\t# You can use all of the above ways to specify the address\n\trnode = rtree.search_exact(\"10.0.0.0/8\")\n\t# Get your data back out\n\tprint rnode.data[\"blah\"]\n\t# Use a packed address\n\taddr = socket.inet_ntoa(\"10.0.0.0\")\n\trnode = rtree.search_exact(packed = addr, masklen = 8)\n\n\t# Best-match search will return the longest matching prefix\n\t# that contains the search term (routing-style lookup)\n\trnode = rtree.search_best(\"10.123.45.6\")\n\n\t# Worst-search will return the shortest matching prefix\n\t# that contains the search term (inverse routing-style lookup)\n\trnode = rtree.search_worst(\"10.123.45.6\")\n\n\t# Covered search will return all prefixes inside the given\n\t# search term, as a list (including the search term itself,\n\t# if present in the tree)\n\trnodes = rtree.search_covered(\"10.123.0.0/16\")\n\n\t# There are a couple of implicit members of a RadixNode:\n\tprint rnode.network\t# -> \"10.0.0.0\"\n\tprint rnode.prefix\t# -> \"10.0.0.0/8\"\n\tprint rnode.prefixlen\t# -> 8\n\tprint rnode.family\t# -> socket.AF_INET\n\tprint rnode.packed\t# -> '\\n\\x00\\x00\\x00'\n\n\t# IPv6 prefixes are fully supported in the same tree\n\trnode = rtree.add(\"2001:DB8::/3\")\n\trnode = rtree.add(\"::/0\")\n\n\t# Use the nodes() method to return all RadixNodes created\n\tnodes = rtree.nodes()\n\tfor rnode in nodes:\n\t\tprint rnode.prefix\n\n\t# The prefixes() method will return all the prefixes (as a\n\t# list of strings) that have been entered\n\tprefixes = rtree.prefixes()\n\n\t# You can also directly iterate over the tree itself\n\t# this would save some memory if the tree is big\n\t# NB. Don't modify the tree (add or delete nodes) while\n\t# iterating otherwise you will abort the iteration and\n\t# receive a RuntimeWarning. Changing a node's data dict\n\t# is permitted.\n\tfor rnode in rtree:\n  \t\tprint rnode.prefix\n\n\nLicense\n-------\n\npy-radix is licensed under a ISC/BSD licence. The underlying radix tree \nimplementation is taken (and modified) from MRTd and is subject to a 4-term \nBSD license. See the LICENSE file for details.\n\nContributing\n------------\n\nPlease report bugs via GitHub at https://github.com/mjschultz/py-radix/issues.\nCode changes can be contributed through a pull request on GitHub or emailed\ndirectly to me <mjschultz@gmail.com>.\n\nThe main portions of the directory tree are as follows: ::\n\n    .\n    \u251c\u2500\u2500 radix/*.py      # Pure Python code\n    \u251c\u2500\u2500 radix/_radix.c  # C extension code (compatible with pure python code)\n    \u251c\u2500\u2500 radix/_radix/*  # C extension code (compatible with pure python code)\n    \u251c\u2500\u2500 tests/          # Tests (regression and unit)\n    \u2514\u2500\u2500 setup.py        # Standard setup.py for installation/testing/etc.",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Radix tree implementation",
    "version": "0.10.0",
    "split_keywords": [
        "radix",
        "tree",
        "trie",
        "python",
        "routing",
        "networking"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "aa2aa43dc8bbd557d317468544affac0",
                "sha256": "b6c6e6100061e677bc5f6b90d9df10291c764af903268e6f8b599b530865aeae"
            },
            "downloads": -1,
            "filename": "py_radix-0.10.0-cp36-cp36m-manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "aa2aa43dc8bbd557d317468544affac0",
            "packagetype": "bdist_wheel",
            "python_version": "cp36",
            "requires_python": null,
            "size": 64549,
            "upload_time": "2021-04-02T19:09:40",
            "upload_time_iso_8601": "2021-04-02T19:09:40.183328Z",
            "url": "https://files.pythonhosted.org/packages/d3/e3/ee1cf0cf2870a2d0247cdacb2b8187496444c69614eaa36d72e4c455a1cb/py_radix-0.10.0-cp36-cp36m-manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "9f4475c1cecd89822a77e668e45386aa",
                "sha256": "c36ef71ec45eb586afc9431dbb51aebfe73caf5940b381bdcd96ef76d13aa787"
            },
            "downloads": -1,
            "filename": "py_radix-0.10.0-cp37-cp37m-manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "9f4475c1cecd89822a77e668e45386aa",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": null,
            "size": 65699,
            "upload_time": "2021-04-02T19:09:42",
            "upload_time_iso_8601": "2021-04-02T19:09:42.554799Z",
            "url": "https://files.pythonhosted.org/packages/f9/07/5259708410b58829f62024e116ad5137148ef5480f4ec611d09b151db488/py_radix-0.10.0-cp37-cp37m-manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "ba9ce94c7da759595fe851ee3d63e090",
                "sha256": "48f1d341328cf69479343ef75dc06939dd50e507b0c1d5e985ffe8fec797d1c6"
            },
            "downloads": -1,
            "filename": "py_radix-0.10.0-cp38-cp38-manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "ba9ce94c7da759595fe851ee3d63e090",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 65960,
            "upload_time": "2021-04-02T19:09:44",
            "upload_time_iso_8601": "2021-04-02T19:09:44.213234Z",
            "url": "https://files.pythonhosted.org/packages/d8/a5/148451bcbdb4e5d3c876b44213c04868888f1b363b3fd9e912ce065399c7/py_radix-0.10.0-cp38-cp38-manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "65dd6ad36b814a9c4619cdf910d8afc2",
                "sha256": "0c4956f6489bed71798a68f2e9217037a8631a2b057b42484a5833b013f2415c"
            },
            "downloads": -1,
            "filename": "py_radix-0.10.0-cp39-cp39-manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "65dd6ad36b814a9c4619cdf910d8afc2",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": null,
            "size": 65268,
            "upload_time": "2021-04-02T19:09:45",
            "upload_time_iso_8601": "2021-04-02T19:09:45.932749Z",
            "url": "https://files.pythonhosted.org/packages/a5/32/30b72197869c2a1f04734835156643693defbf393debc1f379fb824c054b/py_radix-0.10.0-cp39-cp39-manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "3f9c6e07ee0e779b5a3de551f38be5ba",
                "sha256": "b8dbd1344bb30c6a1097d4103203c7b117d92931620365985018de4bef5aede3"
            },
            "downloads": -1,
            "filename": "py-radix-0.10.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3f9c6e07ee0e779b5a3de551f38be5ba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 21815,
            "upload_time": "2017-10-09T14:48:33",
            "upload_time_iso_8601": "2017-10-09T14:48:33.035403Z",
            "url": "https://files.pythonhosted.org/packages/bf/4e/47d9e7f4dfd0630662e19d2cc1b2f1d307ec52df11f4a66f6ed6f0cce138/py-radix-0.10.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2017-10-09 14:48:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "mjschultz",
    "github_project": "py-radix",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "appveyor": true,
    "lcname": "py-radix"
}
        
Elapsed time: 0.02229s