{ "info": { "author": "Tom Kerr", "author_email": "tckerr@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7" ], "description": "Pilot\r\n=====\r\n\r\nPilot is a python library for traversing object trees and graphs. It is\r\ncurrently in pre-alpha.\r\n\r\nhttps://pypi.python.org/pypi/pilot\r\n\r\n1. `Usage <#usage>`__\r\n2. `Documentation <#documentation>`__\r\n\r\n - `Classes <#classes>`__\r\n - `Callbacks <#callbacks>`__\r\n - `Nodes <#nodes>`__\r\n\r\nUsage\r\n=====\r\n\r\nDownload and include the library:\r\n\r\n::\r\n\r\n $ pip install pilot\r\n\r\nThe first step is to define a callback:\r\n\r\n::\r\n\r\n >>> def my_callback(node):\r\n ... print node.key, \"-->\", node.val\r\n ...\r\n\r\nNow, define the pilot object and execute a flight:\r\n\r\n::\r\n\r\n >>> data = {'test': 1}\r\n >>> pilot = Pilot(my_callback)\r\n >>> new_data = pilot.fly(data)\r\n None --> {'test': 1}\r\n test --> 1\r\n >>> type(new_data)\r\n \r\n >>> new_data.__node__\r\n \r\n\r\nSee the documentation for more details!\r\n\r\nDocumentation\r\n=============\r\n\r\nCreating a pilot: ``pilot = Pilot(*callbacks, **settings)``\r\n-----------------------------------------------------------\r\n\r\nCallbacks and keyword arguments (settings) can be passed into the pilot\r\nconstructor.\r\n\r\n**Settings options**:\r\n\r\n- ``run_callbacks`` *(true\\|false)*: Set this to false to skip\r\n callbacks completely.\r\n- ``callbacks``: an array of detailed callback objects. See the\r\n Callback section for more information. If this key is specified *and*\r\n there are callbacks passed into the constructor via args, an\r\n exception will be raised. If finer control on callbacks is required,\r\n use this setting.\r\n- ``traversal_mode``: the mode for traversing the tree. Options are\r\n ``depth`` for *depth-first* processing and ``breadth`` for\r\n *breadth-first* processing.\r\n- ``structure``: Options are ``tree`` (default) and ``graph``. Graphs\r\n add nodes as \"neighbors\" rather than parent/child.\r\n- ``node_visit_limit``: An integer that defines how many times to allow\r\n visits to nodes. (Only applicable to graphs.) Set to ``-1`` to allow\r\n infinite. Note that infinite trees will process indefinitely - use\r\n ``Pilot.halt()`` in a callback to end the processing manually.\r\n- ``callback_sort``: A function that will sort callbacks into an\r\n execution order. Note that callback sorting will only apply to a set\r\n of callbacks running on a property and position basis, since that is\r\n the callback execution stack grouping.\r\n- ``callback_sort_mode`` *(0\\|1)*: This parameter describes the\r\n callback sorting function's required args. Options are ``0`` for a\r\n standard lambda sort function and ``1`` for a ``cmp`` function.\r\n\r\nThe configuration defaults to the following:\r\n\r\n::\r\n\r\n structure = \"Tree\"\r\n node_visit_limit = 1\r\n traversal_mode = 'depth'\r\n run_callbacks = True\r\n callback_sort: lambda self, x: x.priority\r\n callback_sort_mode = 0\r\n\r\n``pilot.fly(self, object, rootkey=None, rootpath=None, rootparent=None)``\r\n-------------------------------------------------------------------------\r\n\r\nTraverse an object and execute callbacks during the traversal. The\r\nflight will convert every property into a ``Node``, and will make that\r\nnode available on the property through ``property.__node__``. Note that\r\nthis means the process will ocassionally change the underlying classes\r\nof objects to support adding the ``__node__`` property. As of now, most\r\ntypes are supported -- if the conversion process fails, it may be\r\nbecause Pilot is unable to modify the underlying class. See the\r\ndocumentation on the **Node** class for more details.\r\n\r\n``Pilot.halt()`` *(static method)*:\r\n-----------------------------------\r\n\r\nCalling this method within a callback will halt processing completely.\r\nThis allows for early exit of the traversal, which is required for\r\nlimited processing of infinite trees.\r\n\r\nCallbacks\r\n---------\r\n\r\nCallbacks are special functions that execute on the object tree/graph as\r\nit is being traversed, and are constructed from predefined functions.\r\nEach callback executes at different times based on several configuration\r\noptions listed below. Callbacks are passed a single argument, the\r\n**Node** for the object. The general form of a callback object is:\r\n\r\n::\r\n\r\n def my_callback(node):\r\n do_some_things()\r\n\r\n from pilot import Callback\r\n callback = Callback(my_callback)\r\n\r\nSee the \"Usage\" section of the documentation for a shorthand way to apss\r\ncallbacks into the Pilot.\r\n\r\nHere's an example, using custom callbacks:\r\n\r\n::\r\n\r\n data = [\r\n {'name': 'Jim', 'friends': [{},{}]},\r\n {'name': 'Jane', 'friends': [{},{},{}]},\r\n {'name': 'Joe', 'friends': []}\r\n ]\r\n\r\n def count_friends(node):\r\n try:\r\n node.val['name']\r\n except: # not a person \r\n return\r\n person = node.val\r\n friends = person.get('friends', None)\r\n if friends:\r\n print person.get(\"name\") + \" has \" + str(len(friends)) + \" friends.\"\r\n else:\r\n print person.get(\"name\") + \" has no friends.\"\r\n\r\n from pilot import Callback, Pilot\r\n callback = Callback(count_friends, containers=['dict'])\r\n pilot = Pilot(callbacks=[callback])\r\n newdata = pilot.fly(data)\r\n\r\nHere are the keyword args you can supply in a callback configuration,\r\nmost of which act as filters:\r\n\r\n- ``containers``: a list of containers to run on. Options are\r\n ``'dict'``, ``'list'``, and ``'value'``. If unspecifed, the callback\r\n will run on any container.\r\n- ``keys``: an array of keys to run on. The callback will check the key\r\n of the property against this list. If unspecified, the callback will\r\n run on any key.\r\n- ``positions``: a list of positions in the traversal to run on.\r\n Options are ``'pre'`` (before any list/object is traversed), and\r\n ``'post'`` (after any list/object is traversed). For properties of\r\n container-type ``'value'``, these two run in immediate succession. If\r\n unspecifed, the callback will run ``'post'``.\r\n- ``priority``: an integer that represents the callback's place in the\r\n execution order. Lower priorities execute first.\r\n- ``run_for_orphans``: a boolean that determines whether the callback\r\n should run on oprhan nodes.\r\n\r\nIf any of the filters are not sufficient, additional checks can be done\r\nin the callback.\r\n\r\nNodes\r\n-----\r\n\r\nNode objects represent a single node in the tree, providing metadata\r\nabout the value, its parents, siblings, children, and more. Nodes have\r\nthe following properties:\r\n\r\n- ``key``: The key of this property as defined on it's parent. For\r\n example, if this callback is running on the ``'weight'`` property of\r\n a ``person``, the ``key`` would be ``'weight'``. Note that this will\r\n be ``None`` for properties in list.\r\n- ``value``: The value of the property. To use the above example, the\r\n value would be something like ``'183'``.\r\n- ``container``: The type of container of the property expressed in an\r\n integer. See the following enumeration for container types:\r\n ``from pilot.definitions import ContainerType``\r\n- ``encountered``: The number of times the pilot has processed the\r\n node.\r\n- ``id``: A unique id for the node (within the context of piot).\r\n\r\nYou may also call the following methods off of a node object. Keep in\r\nmind that some of the node accessors may not be populated based on where\r\nyou are in your traversal. If you want to wait for the relationship tree\r\nto be fully established, run operations on the output of a flight, which\r\nwill be a data object with each value annotated with a ``__node__``\r\nproperty:\r\n\r\n- ``is_orphan()``: Returns a boolean of whether the node is an orphan\r\n (no parents.)\r\n\r\nNode relationship accessors\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\n- ``parent()``: The first node under which the property exists.\r\n ``node.parent`` is another instance of node, and will have all the\r\n same properties. This is a convenience method that's useful in trees,\r\n where only one parent is possible.\r\n- ``parents()``: A method that returns parents of a node. An optional\r\n search parameters object can be passed in to filter the list to all\r\n who have matching key-values. For example,\r\n ``node.parents(key='name', val='Tom')`` will return all parents where\r\n ``key == 'name'`` and ``val == 'Tom'``.\r\n- ``children()``: A method that returns children of a node (i.e. all\r\n nodes whose parent is this node.) An optional search parameters\r\n object can be passed in to filter the list to all who have matching\r\n key-values. For example, ``node.children(key='name', val='Tom')``\r\n will return all children where ``key == 'name'`` and\r\n ``val == 'Tom'``.\r\n- ``neighbors()``: A method that returns adjacent (non-parent,\r\n non-child) nodes, for use in graphs. An optional search parameters\r\n object can be passed in to filter the list to all who have matching\r\n key-values. For example, ``node.neighbors(key='name', val='Tom')``\r\n will return all neighbors where ``key == 'name'`` and\r\n ``val == 'Tom'``.\r\n- ``siblings()``: A method that returns all nodes that exist alongside\r\n the current node within its parents. For parents of container\r\n ``'object'``, this includes all other properties of the parent\r\n object. For parents of type ``'array'``, this includes all other\r\n nodes in that array.\r\n- ``orphans()``: A method that returns all connected root nodes.\r\n- ``ancestors()``: A method that returns a list of all ancestor nodes,\r\n going back to the root.\r\n- ``descendants()``: A method that returns a list of all descendant\r\n nodes.\r\n\r\nEach relationship accessor can be pased the following keyword arguments:\r\n\r\n- ``filters=None``: A dictionary of key:val that will be matched\r\n against each encountered node's val (as of now this is only useful\r\n for dict types).\r\n- ``as_value=False``: Boolean that will make the call return node\r\n values rather than node objects.\r\n- ``as_generator=False``: Boolean that will make the call return a\r\n generator object for the relationship. This is useful when the\r\n relationship list is large or inifinite, since it will not attempt to\r\n build the list entirely at call time.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/tckerr/Pilot", "keywords": "object development tree graph parse walk traverse data", "license": "", "maintainer": "", "maintainer_email": "", "name": "pilot", "package_url": "https://pypi.org/project/pilot/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pilot/", "project_urls": { "Homepage": "https://github.com/tckerr/Pilot" }, "release_url": "https://pypi.org/project/pilot/0.0.8/", "requires_dist": null, "requires_python": "", "summary": "Pilot is a python library for traversing object trees and graphs", "version": "0.0.8" }, "last_serial": 2819151, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "e5872d3933c18d6a70582805ea4f6918", "sha256": "c7027c26a0350bf7d83eb00308a73f7063e7adb8c5e1d1738a98fa07f505cc6f" }, "downloads": -1, "filename": "pilot-0.0.1-py2-none-any.whl", "has_sig": false, "md5_digest": "e5872d3933c18d6a70582805ea4f6918", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 6694, "upload_time": "2016-02-07T04:17:49", "url": "https://files.pythonhosted.org/packages/63/82/b762ab89639bf9c8b34baac88ab56fb9fbf6b4f0e57d98768920abc8789d/pilot-0.0.1-py2-none-any.whl" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "699dbdd5ebbd7161c8a44cde9849f3d1", "sha256": "0dea2e3e6d71e9715b9aabb87bc0f40f0fb235508296ee3e4f15ad6f610002f0" }, "downloads": -1, "filename": "pilot-0.0.2-py2-none-any.whl", "has_sig": false, "md5_digest": "699dbdd5ebbd7161c8a44cde9849f3d1", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 6754, "upload_time": "2016-02-07T05:16:17", "url": "https://files.pythonhosted.org/packages/35/7e/8ba117465b01b215591b1cc87bba0166fb15049605e0ad907d98dc2baae1/pilot-0.0.2-py2-none-any.whl" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "2de0491414698c36a505183677bfb1e5", "sha256": "c600a2f430d45b1c8f6c0707a4041050c77493054bd28c1a70958f7a8ebcbf45" }, "downloads": -1, "filename": "pilot-0.0.3-py2-none-any.whl", "has_sig": false, "md5_digest": "2de0491414698c36a505183677bfb1e5", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 6783, "upload_time": "2016-02-07T05:35:35", "url": "https://files.pythonhosted.org/packages/14/c9/3fc1e47768408d5331fed61c33ec40c250d5635d96cc62742a6d2eca7d92/pilot-0.0.3-py2-none-any.whl" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "c45eb21ee0d3a17852f5ed42a1a7f100", "sha256": "5f29314024ef082259daed5fa56de492e43558140f2df66b6fc557003047b16d" }, "downloads": -1, "filename": "pilot-0.0.4-py2-none-any.whl", "has_sig": false, "md5_digest": "c45eb21ee0d3a17852f5ed42a1a7f100", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 6821, "upload_time": "2016-02-07T05:41:46", "url": "https://files.pythonhosted.org/packages/8d/90/9333d25ccaca8dc68b0298dc72f709586950c3e4e2c6572128eb7aa6538c/pilot-0.0.4-py2-none-any.whl" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "896dbc136522a1b512712b6cb2eb8435", "sha256": "7265c6b7b522a3df70463b046de769868bdffe4bce568725461f7f67a5dc1258" }, "downloads": -1, "filename": "pilot-0.0.5-py2-none-any.whl", "has_sig": false, "md5_digest": "896dbc136522a1b512712b6cb2eb8435", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 8725, "upload_time": "2016-02-07T16:54:39", "url": "https://files.pythonhosted.org/packages/75/c4/004956a4c8b265d62758ba553f76b843e708a9666dc45689883c83bd6e3f/pilot-0.0.5-py2-none-any.whl" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "5d302f4c152ee29d28538ad387231bf5", "sha256": "79d380b63c63a4064fb20f765cb2f2dd98194d23e4862c465fe6c6b0c56e6ad6" }, "downloads": -1, "filename": "pilot-0.0.6-py2-none-any.whl", "has_sig": false, "md5_digest": "5d302f4c152ee29d28538ad387231bf5", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 15720, "upload_time": "2016-02-07T16:59:26", "url": "https://files.pythonhosted.org/packages/45/7d/84980f5a8af6c29378d98a6ee726c78595dc7e117bd284a636b66680c49a/pilot-0.0.6-py2-none-any.whl" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "2cd7a637f6f878ff2ca5b4d68607f71c", "sha256": "d797b1868f34425d8726c302002db78f36684e463898e82f16e9a3df82003e5a" }, "downloads": -1, "filename": "pilot-0.0.7-py2-none-any.whl", "has_sig": false, "md5_digest": "2cd7a637f6f878ff2ca5b4d68607f71c", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 15715, "upload_time": "2016-02-07T17:09:18", "url": "https://files.pythonhosted.org/packages/81/94/fa44dea1740a20ffaa861b7401f31f49cf9e7442d6c3426fe08a658e10e3/pilot-0.0.7-py2-none-any.whl" } ], "0.0.8": [ { "comment_text": "", "digests": { "md5": "2c71e1bfddba7891c0594aa7b4653229", "sha256": "e74db69405e3f1b55967c65d0fd9214962edee9f57201e237c0567bfa8de6d5d" }, "downloads": -1, "filename": "pilot-0.0.8-py2-none-any.whl", "has_sig": false, "md5_digest": "2c71e1bfddba7891c0594aa7b4653229", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 15944, "upload_time": "2016-02-13T14:30:09", "url": "https://files.pythonhosted.org/packages/ea/d7/070e79c25eeedc238e41ba3373dbab9a9a20f4e7fc93642867931b321230/pilot-0.0.8-py2-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2c71e1bfddba7891c0594aa7b4653229", "sha256": "e74db69405e3f1b55967c65d0fd9214962edee9f57201e237c0567bfa8de6d5d" }, "downloads": -1, "filename": "pilot-0.0.8-py2-none-any.whl", "has_sig": false, "md5_digest": "2c71e1bfddba7891c0594aa7b4653229", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 15944, "upload_time": "2016-02-13T14:30:09", "url": "https://files.pythonhosted.org/packages/ea/d7/070e79c25eeedc238e41ba3373dbab9a9a20f4e7fc93642867931b321230/pilot-0.0.8-py2-none-any.whl" } ] }