{"id":22296155,"url":"https://github.com/kakwa/pygraph_redis","last_synced_at":"2025-07-29T01:32:25.695Z","repository":{"id":7143206,"uuid":"8440605","full_name":"kakwa/pygraph_redis","owner":"kakwa","description":"Simple python library to manipulate directed graphs in redis","archived":false,"fork":false,"pushed_at":"2017-05-24T19:30:32.000Z","size":563,"stargazers_count":23,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-25T09:06:47.469Z","etag":null,"topics":["directed-graph","graph","python","redis"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kakwa.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-26T19:55:33.000Z","updated_at":"2024-11-28T16:31:23.000Z","dependencies_parsed_at":"2022-09-02T11:50:36.678Z","dependency_job_id":null,"html_url":"https://github.com/kakwa/pygraph_redis","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/kakwa/pygraph_redis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakwa%2Fpygraph_redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakwa%2Fpygraph_redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakwa%2Fpygraph_redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakwa%2Fpygraph_redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kakwa","download_url":"https://codeload.github.com/kakwa/pygraph_redis/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakwa%2Fpygraph_redis/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267616577,"owners_count":24116154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["directed-graph","graph","python","redis"],"created_at":"2024-12-03T17:44:24.954Z","updated_at":"2025-07-29T01:32:25.350Z","avatar_url":"https://github.com/kakwa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"pygraph_redis  \n==============\n\n\n\nSimple python library to manipulate directed graphs in redis\n\n.. image:: https://secure.travis-ci.org/kakwa/pygraph_redis.png?branch=master\n    :target: http://travis-ci.org/kakwa/pygraph_redis\n    :alt: Travis CI\n\n.. image:: https://img.shields.io/pypi/v/pygraph_redis.svg\n    :target: https://pypi.python.org/pypi/pygraph_redis\n    :alt: PyPI version\n    \n.. image:: https://badges.gitter.im/Join%20Chat.svg\n   :alt: Join the chat at https://gitter.im/kakwa/pygraph_redis\n   :target: https://gitter.im/kakwa/pygraph_redis?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\n   \n.. image:: https://coveralls.io/repos/kakwa/pygraph_redis/badge.svg\n  :target: https://coveralls.io/r/kakwa/pygraph_redis\n\n\n   \nLicense\n=======\n\npygraph_redis is released under the MIT Public License\n\nDescription\n===========\n\npygraph_redis is a simple library to manipulate directed graphs inside a redis database.\n\nIn this library, a graph is a bunch of nodes, each node knows its predecessors \nand its successors. A node can store some attributs (strings or sets of strings).\n\nDependancies\n============\n\npygraph_redis relies on `redis \u003chttp://github.com/antirez/redis\u003e`_ and `redis-py \u003chttp://github.com/andymccurdy/redis-py\u003e`_.\n\nFor atomicity of transaction, it requires lua scripting support (redis-py \u003e= 2.7.0 and redis \u003e= 2.6.0), but it provides a legacy mode, without atomicity for older redis and redis-py.\n\nWrite atomicity\n===============\n\nWith proper versions, pygraph\\_redis provides the atomicity of transaction when adding or removing a node.\n\nInstallation\n============\n\nto install:\n\n.. sourcecode:: bash\n\n    $ python setup.py install\n\n    or\n\n    $ pip install pygraph_redis\n\nHow to use\n==========\n\nFirst you need a redis database, it's up to you to install it.\n\nThe library itself is quite simple:\n\nCheat Sheet\n-----------\n\n.. sourcecode:: python\n\n    #              initialization\n    #       arg1      |    arg2    |     arg3\n    #--------------------------------------------\n    # redis connexion | graph_name |    logger\n    #    redis obj    |  unicode   |  logger obj \n    \n    mygraph1 = Directed_graph(r_server, u'mygraph1', logger)\n    \n    #optional args:\n    #   arg4    |    arg5  \n    #-----------------------\n    # separator | has_root \n    # unicode   |   bool   \n    \n    mygraph1 = Directed_graph(r_server, \n        u'mygraph1', logger, u'mysep', True)\n    )\n    \n.. sourcecode:: python\n\n    #                    create or add elements to a node\n    #    arg1   |     arg2     |     arg3     |             arg4\n    #---------------------------------------------------------------------------\n    # node name |  successors  | predecessors |           attributs\n    #  unicode  | unicode list | unicode list |      dictionnary of unicode \n    #           |              |              | or set of unicode (key: unicode)\n    \n    mygraph1.write_on_node(u'm1', \n                           [u's2'],\n                           [u'p1'], \n                           {u'a3': set([u'69']), u'a2': u'42'}\n    )\n    \n.. sourcecode:: python\n\n    #             delete elements from a node\n    #    arg1   |     arg2     |     arg3     |      arg4\n    #----------------------------------------------------------\n    # node name |  successors  | predecessors | attributs names\n    #  unicode  | unicode list | unicode list | list of unicode \n    \n    mygraph1.write_off_node(u'm1', [u's2'], [u'p1'], [u'attr3', u'attr2']\n    \n.. sourcecode:: python\n\n    # delete a node\n    #     arg1 \n    #--------------\n    #  node name \n    #   unicode   \n    \n    mygraph1.remove_node(u'm1')\n    \n.. sourcecode:: python\n\n    # get attributs list\n    #     arg1 \n    #--------------\n    #  node name \n    #   unicode   \n    \n    mygraph1.get_attributs_list(u'm1')\n    \n.. sourcecode:: python\n\n    # get an attribut\n    #     arg1     |     arg2\n    #--------------|--------------\n    #  node name   | attribut name\n    #   unicode    |    unicode\n    \n    mygraph1.get_attribut(u'm1', u'a2')\n    \n.. sourcecode:: python\n\n    # get an attribut length\n    #     arg1     |     arg2\n    #--------------|--------------\n    #  node name   | attribut name\n    #   unicode    |    unicode\n    \n    mygraph1.get_attribut_len(u'm1', u'a2')\n    \n.. sourcecode:: python\n\n    # get successors\n    #     arg1 \n    #--------------\n    #  node name \n    #   unicode   \n    \n    mygraph1.get_successors(u'm1')\n    \n.. sourcecode:: python\n\n    # get predecessors\n    #     arg1 \n    #--------------\n    #  node name \n    #   unicode   \n    \n    mygraph1.get_predecessors(u'm1')\n\nInitialization\n--------------\n\nCreate an instance of \"Directed\\_graph\":\n\n.. sourcecode:: python\n\n    #importing directed_graph\n    from pygraph_redis.directed_graph import Directed_graph\n    import redis\n    \n    #creating a basic logger\n    import logging\n    logging.basicConfig(format = u'%(message)s')\n    logger = logging.getLogger(u'redis')\n    logger.parent.setLevel(logging.DEBUG)\n    \n    #creating the redis connexion\n    r_server = redis.Redis(\"localhost\")\n    \n    #creating the graph object\n    mygraph1 = Directed_graph(r_server, u'mygraph1', logger)\n    \n    #creating the graph object with a different separator\n    mygraph2 = Directed_graph(r_server, u'mygraph2', logger, separator = u'mysep')\n    \n    #creating the graph object with a \"root\" (improper name, I know)\n    mygraph2 = Directed_graph(r_server, u'mygraph2', logger, has_root = True)\n    #\"has_root = True\" ensures that every node has a predecessor\n    #if enabled, a node has at least root as a predecessor, \n    #but if it has any other predecessor it doesn't have root as predecessor\n\nNode manipulation\n-----------------\n\nNode creation:\n\n.. sourcecode:: python\n\n    #add node 'm1' to 'mygraph1' with:\n    #successors: 's1' and 's2'\n    #predecessors: 'p1' and 'p2'\n    #attributs:\n    #   * 'attr1': set([u'51',u'69'])\n    #   * 'attr2': '42'    \n    \n    mygraph1.write_on_node(u'm1',\n        [u's1', u's2'],\n        [u'p1', u'p2'],\n        {u'attr1': set([u'51', u'69']), u'attr2': u'42'}\n    )\n\nAbout `successors` and `predecessors`, if node was already declared as a predecessor of one \nof its successors, it's not necessary to add this successor in node successors set.\nSame with `predecessors`.\n\nexample:\n\n\n.. sourcecode:: python\n\n    mygraph1.write_on_node(u'pred',\n        [u'succ'],\n        [],\n        {}\n    )\n\n.. sourcecode:: python\n\n    mygraph1.write_on_node(u'succ',\n        [],\n        [],\n        {}\n    )\n\nGives the same result that:\n\n.. sourcecode:: python\n\n    mygraph1.write_on_node(u'pred',\n        [u'succ'],\n        [],\n        {}\n    )\n\n\n.. sourcecode:: python\n\n    mygraph1.write_on_node(u'succ',\n        [],\n        [u'pred'],\n        {}\n    )\n\nNode edition:\n\n\n.. sourcecode:: python\n\n    #add new elements or edit existing elements of a node\n    #it's exactly the same function as before\n    mygraph1.write_on_node(u'm1', \n        [u's4'], \n        [], \n        {u'attr3': set([u'16', u'32', u'64']), u'attr2': u'5150'}\n    )\n    \n    #remove some elements of a node (successors, predecessors, attributs)\n    mygraph1.write_off_node(u\"m1\", [u\"s1\"], [u\"p2\"],[u'attr2'])\n    \n    #completely delete a node\n    mygraph1.remove_node(u'm1')\n\nNode attributs manipulation\n---------------------------\n\nTo manipulate the attributs of a node:\n\n.. sourcecode:: python\n\n    #create the node 'm2'\n    mygraph1.write_on_node(u'm2',\n        [u's1', u's2'],\n        [u'p1', u'p2'],\n        {u'attr1': set([u'51', u'69']), u'attr2': u'42'}\n    )\n    \n    #get the set of attribut names\n    set_of_attributs = mygraph1.get_attributs_list(u'm2')\n    print set_of_attributs\n    \n    #get a specific attribut\n    attr2 = mygraph1.get_attribut(u'm2', u'attr2')\n    print attr2\n    \n    #get a specific attribut length\n    # 1 if it's a string\n    # cardinal of set if it's a set\n    # 0 if attribut doesn't exists\n    attr2 = mygraph1.get_attribut_len(u'm2', u'attr2')\n    print attr2\n\nGraph navigation\n----------------\n\nTo navigate inside the graph, you have two functions:\n\n.. sourcecode:: python\n\n    #get the predecessors of 'm2'\n    predecessors = mygraph1.get_predecessors(u'm2')\n    print predecessors\n    \n    #get the successors of 'm2'\n    successors = mygraph1.get_successors(u'm2')\n\nif you have the `has_root` flag enable:\n\n.. sourcecode:: python\n\n    #get the \"root\" name\n    root = mygraph1.get_root_name()\n    \n    print root\n    \n    #get the successors of 'root'\n    successors = mygraph1.get_successors(root)\n    print successors\n\nAbout the redis keys\n--------------------\n\nRedis key format:\n\n\n.. sourcecode:: none\n\n  \u003cgraph name\u003e\u003csep\u003e\u003cnode_name\u003e\u003csep\u003e\u003cvariable_name\u003e[\u003csep\u003e\u003cother\u003e]*\n  \n  \u003cgraph name\u003e: name of the graph\n  \u003csep\u003e: the key fields separator \n       (this string should not be in node_name or variable_name,\n        otherwise, there is a redis key collision possibility)\n  \u003cnode_name\u003e: name of the node\n  \u003cvariable_name\u003e: name of the variable\n  [\u003csep\u003e\u003cother\u003e]: optional extension\n\nTo avoid key collision, you must carefully choose the key separator,\nit must not be included in any node name or node attribut name (possible redis key collision).\n\nAbout the logs\n--------------\n\nThis library provides a lot of logs, mainly debug, some info (ex: legacy modes), some warning (ex: possible key collision)\n\n\n.. image:: https://d2weczhvl823v0.cloudfront.net/kakwa/pygraph_redis/trend.png\n   :alt: Bitdeli badge\n   :target: https://bitdeli.com/free\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkakwa%2Fpygraph_redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkakwa%2Fpygraph_redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkakwa%2Fpygraph_redis/lists"}