{ "info": { "author": "Pierre-Francois Carpentier", "author_email": "carpentier.pf@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3" ], "description": "pygraph_redis \r\n==============\r\n\r\nSimple python library to manipulate directed graphs in redis\r\n\r\n.. image:: https://secure.travis-ci.org/kakwa/pygraph_redis.png?branch=master\r\n :target: http://travis-ci.org/kakwa/pygraph_redis\r\n :alt: Travis CI\r\n\r\n.. image:: https://pypip.in/d/pygraph_redis/badge.png\r\n :target: https://pypi.python.org/pypi/pygraph_redis\r\n :alt: Number of PyPI downloads\r\n\r\nLicense\r\n=======\r\n\r\npygraph_redis is released under the MIT Public License\r\n\r\nDescription\r\n===========\r\n\r\npygraph_redis is a simple library to manipulate directed graphs inside a redis database.\r\n\r\nIn this library, a graph is a bunch of nodes, each node knows its predecessors \r\nand its successors. A node can store some attributs (strings or sets of strings).\r\n\r\nDependancies\r\n============\r\n\r\npygraph_redis relies on `redis `_ and `redis-py `_.\r\n\r\nFor atomicity of transaction, it requires lua scripting support (redis-py >= 2.7.0 and redis >= 2.6.0), but it provides a legacy mode, without atomicity for older redis and redis-py.\r\n\r\nWrite atomicity\r\n===============\r\n\r\nWith proper versions, pygraph\\_redis provides the atomicity of transaction when adding or removing a node.\r\n\r\nInstallation\r\n============\r\n\r\nto install:\r\n\r\n.. sourcecode:: bash\r\n\r\n $ python setup.py install\r\n\r\n or\r\n\r\n $ pip install pygraph_redis\r\n\r\nHow to use\r\n==========\r\n\r\nFirst you need a redis database, it's up to you to install it.\r\n\r\nThe library itself is quite simple:\r\n\r\nCheat Sheet\r\n-----------\r\n\r\n.. sourcecode:: python\r\n\r\n # initialization\r\n # arg1 | arg2 | arg3\r\n #--------------------------------------------\r\n # redis connexion | graph_name | logger\r\n # redis obj | unicode | logger obj \r\n \r\n mygraph1 = Directed_graph(r_server, u'mygraph1', logger)\r\n \r\n #optional args:\r\n # arg4 | arg5 \r\n #-----------------------\r\n # separator | has_root \r\n # unicode | bool \r\n \r\n mygraph1 = Directed_graph(r_server, \r\n u'mygraph1', logger, u'mysep', True)\r\n )\r\n \r\n.. sourcecode:: python\r\n\r\n # create or add elements to a node\r\n # arg1 | arg2 | arg3 | arg4\r\n #---------------------------------------------------------------------------\r\n # node name | successors | predecessors | attributs\r\n # unicode | unicode list | unicode list | dictionnary of unicode \r\n # | | | or set of unicode (key: unicode)\r\n \r\n mygraph1.write_on_node(u'm1', \r\n [u's2'],\r\n [u'p1'], \r\n {u'a3': set([u'69']), u'a2': u'42'}\r\n )\r\n \r\n.. sourcecode:: python\r\n\r\n # delete elements from a node\r\n # arg1 | arg2 | arg3 | arg4\r\n #----------------------------------------------------------\r\n # node name | successors | predecessors | attributs names\r\n # unicode | unicode list | unicode list | list of unicode \r\n \r\n mygraph1.write_off_node(u'm1', [u's2'], [u'p1'], [u'attr3', u'attr2']\r\n \r\n.. sourcecode:: python\r\n\r\n # delete a node\r\n # arg1 \r\n #--------------\r\n # node name \r\n # unicode \r\n \r\n mygraph1.remove_node(u'm1')\r\n \r\n.. sourcecode:: python\r\n\r\n # get attributs list\r\n # arg1 \r\n #--------------\r\n # node name \r\n # unicode \r\n \r\n mygraph1.get_attributs_list(u'm1')\r\n \r\n.. sourcecode:: python\r\n\r\n # get an attribut\r\n # arg1 | arg2\r\n #--------------|--------------\r\n # node name | attribut name\r\n # unicode | unicode\r\n \r\n mygraph1.get_attribut(u'm1', u'a2')\r\n \r\n.. sourcecode:: python\r\n\r\n # get an attribut length\r\n # arg1 | arg2\r\n #--------------|--------------\r\n # node name | attribut name\r\n # unicode | unicode\r\n \r\n mygraph1.get_attribut_len(u'm1', u'a2')\r\n \r\n.. sourcecode:: python\r\n\r\n # get successors\r\n # arg1 \r\n #--------------\r\n # node name \r\n # unicode \r\n \r\n mygraph1.get_successors(u'm1')\r\n \r\n.. sourcecode:: python\r\n\r\n # get predecessors\r\n # arg1 \r\n #--------------\r\n # node name \r\n # unicode \r\n \r\n mygraph1.get_predecessors(u'm1')\r\n\r\nInitialization\r\n--------------\r\n\r\nCreate an instance of \"Directed\\_graph\":\r\n\r\n.. sourcecode:: python\r\n\r\n #importing directed_graph\r\n from pygraph_redis.directed_graph import Directed_graph\r\n import redis\r\n \r\n #creating a basic logger\r\n import logging\r\n logging.basicConfig(format = u'%(message)s')\r\n logger = logging.getLogger(u'redis')\r\n logger.parent.setLevel(logging.DEBUG)\r\n \r\n #creating the redis connexion\r\n r_server = redis.Redis(\"localhost\")\r\n \r\n #creating the graph object\r\n mygraph1 = Directed_graph(r_server, u'mygraph1', logger)\r\n \r\n #creating the graph object with a different separator\r\n mygraph2 = Directed_graph(r_server, u'mygraph2', logger, separator = u'mysep')\r\n \r\n #creating the graph object with a \"root\" (improper name, I know)\r\n mygraph2 = Directed_graph(r_server, u'mygraph2', logger, has_root = True)\r\n #\"has_root = True\" ensures that every node has a predecessor\r\n #if enabled, a node has at least root as a predecessor, \r\n #but if it has any other predecessor it doesn't have root as predecessor\r\n\r\nNode manipulation\r\n-----------------\r\n\r\nNode creation:\r\n\r\n.. sourcecode:: python\r\n\r\n #add node 'm1' to 'mygraph1' with:\r\n #successors: 's1' and 's2'\r\n #predecessors: 'p1' and 'p2'\r\n #attributs:\r\n # * 'attr1': set([u'51',u'69'])\r\n # * 'attr2': '42' \r\n \r\n mygraph1.write_on_node(u'm1',\r\n [u's1', u's2'],\r\n [u'p1', u'p2'],\r\n {u'attr1': set([u'51', u'69']), u'attr2': u'42'}\r\n )\r\n\r\nAbout `successors` and `predecessors`, if node was already declared as a predecessor of one \r\nof its successors, it's not necessary to add this successor in node successors set.\r\nSame with `predecessors`.\r\n\r\nexample:\r\n\r\n\r\n.. sourcecode:: python\r\n\r\n mygraph1.write_on_node(u'pred',\r\n [u'succ'],\r\n [],\r\n {}\r\n )\r\n\r\n.. sourcecode:: python\r\n\r\n mygraph1.write_on_node(u'succ',\r\n [],\r\n [],\r\n {}\r\n )\r\n\r\nGives the same result that:\r\n\r\n.. sourcecode:: python\r\n\r\n mygraph1.write_on_node(u'pred',\r\n [u'succ'],\r\n [],\r\n {}\r\n )\r\n\r\n\r\n.. sourcecode:: python\r\n\r\n mygraph1.write_on_node(u'succ',\r\n [],\r\n [u'pred'],\r\n {}\r\n )\r\n\r\nNode edition:\r\n\r\n\r\n.. sourcecode:: python\r\n\r\n #add new elements or edit existing elements of a node\r\n #it's exactly the same function as before\r\n mygraph1.write_on_node(u'm1', \r\n [u's4'], \r\n [], \r\n {u'attr3': set([u'16', u'32', u'64']), u'attr2': u'5150'}\r\n )\r\n \r\n #remove some elements of a node (successors, predecessors, attributs)\r\n mygraph1.write_off_node(u\"m1\", [u\"s1\"], [u\"p2\"],[u'attr2'])\r\n \r\n #completely delete a node\r\n mygraph1.remove_node(u'm1')\r\n\r\nNode attributs manipulation\r\n---------------------------\r\n\r\nTo manipulate the attributs of a node:\r\n\r\n.. sourcecode:: python\r\n\r\n #create the node 'm2'\r\n mygraph1.write_on_node(u'm2',\r\n [u's1', u's2'],\r\n [u'p1', u'p2'],\r\n {u'attr1': set([u'51', u'69']), u'attr2': u'42'}\r\n )\r\n \r\n #get the set of attribut names\r\n set_of_attributs = mygraph1.get_attributs_list(u'm2')\r\n print set_of_attributs\r\n \r\n #get a specific attribut\r\n attr2 = mygraph1.get_attribut(u'm2', u'attr2')\r\n print attr2\r\n \r\n #get a specific attribut length\r\n # 1 if it's a string\r\n # cardinal of set if it's a set\r\n # 0 if attribut doesn't exists\r\n attr2 = mygraph1.get_attribut_len(u'm2', u'attr2')\r\n print attr2\r\n\r\nGraph navigation\r\n----------------\r\n\r\nTo navigate inside the graph, you have two functions:\r\n\r\n.. sourcecode:: python\r\n\r\n #get the predecessors of 'm2'\r\n predecessors = mygraph1.get_predecessors(u'm2')\r\n print predecessors\r\n \r\n #get the successors of 'm2'\r\n successors = mygraph1.get_successors(u'm2')\r\n\r\nif you have the `has_root` flag enable:\r\n\r\n.. sourcecode:: python\r\n\r\n #get the \"root\" name\r\n root = mygraph1.get_root_name()\r\n \r\n print root\r\n \r\n #get the successors of 'root'\r\n successors = mygraph1.get_successors(root)\r\n print successors\r\n\r\nAbout the redis keys\r\n--------------------\r\n\r\nRedis key format:\r\n\r\n\r\n.. sourcecode:: bash\r\n\r\n []*\r\n \r\n : name of the graph\r\n : the key fields separator \r\n (this string should not be in node_name or variable_name,\r\n otherwise, there is a redis key collision possibility)\r\n : name of the node\r\n : name of the variable\r\n []: optional extension\r\n\r\nTo avoid key collision, you must carefully choose the key separator,\r\nit must not be included in any node name or node attribut name (possible redis key collision).\r\n\r\nAbout the logs\r\n--------------\r\n\r\nThis library provides a lot of logs, mainly debug, some info (ex: legacy modes), some warning (ex: possible key collision)\r\n\r\n\r\n.. image:: https://d2weczhvl823v0.cloudfront.net/kakwa/pygraph_redis/trend.png\r\n :alt: Bitdeli badge\r\n :target: https://bitdeli.com/free", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/kakwa/pygraph_redis", "keywords": "", "license": "Copyright (c) 2013 Pierre-Francois Carpentier \r\n\r\nPermission is hereby granted, free of charge, to any person obtaining\r\na copy of this software and associated documentation files (the\r\n\"Software\"), to deal in the Software without restriction, including\r\nwithout limitation the rights to use, copy, modify, merge, publish,\r\ndistribute, sublicense, and/or sell copies of the Software, and to\r\npermit persons to whom the Software is furnished to do so, subject to\r\nthe following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be\r\nincluded in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\r\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", "maintainer": "", "maintainer_email": "", "name": "pygraph_redis", "package_url": "https://pypi.org/project/pygraph_redis/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pygraph_redis/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/kakwa/pygraph_redis" }, "release_url": "https://pypi.org/project/pygraph_redis/0.2.1/", "requires_dist": null, "requires_python": null, "summary": "Python Library to manipulate directed graphs in redis", "version": "0.2.1" }, "last_serial": 1428897, "releases": { "0.2.0": [], "0.2.1": [ { "comment_text": "", "digests": { "md5": "f1f45ed32d355d7a5da38a1a76fe5ff6", "sha256": "1e213b856c5b188fd127040be83828c7ababefc1c44733831aa978412098d837" }, "downloads": -1, "filename": "pygraph_redis-0.2.1.tar.gz", "has_sig": false, "md5_digest": "f1f45ed32d355d7a5da38a1a76fe5ff6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10246, "upload_time": "2014-01-22T23:25:28", "url": "https://files.pythonhosted.org/packages/33/37/41be9d269771b0ccd226c262c0c9ebf7feef904bcbad0f2d3db573fe1a5e/pygraph_redis-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f1f45ed32d355d7a5da38a1a76fe5ff6", "sha256": "1e213b856c5b188fd127040be83828c7ababefc1c44733831aa978412098d837" }, "downloads": -1, "filename": "pygraph_redis-0.2.1.tar.gz", "has_sig": false, "md5_digest": "f1f45ed32d355d7a5da38a1a76fe5ff6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10246, "upload_time": "2014-01-22T23:25:28", "url": "https://files.pythonhosted.org/packages/33/37/41be9d269771b0ccd226c262c0c9ebf7feef904bcbad0f2d3db573fe1a5e/pygraph_redis-0.2.1.tar.gz" } ] }