{"id":16685285,"url":"https://github.com/fractalego/parvusdb","last_synced_at":"2025-04-09T23:52:44.408Z","repository":{"id":57450923,"uuid":"96784098","full_name":"fractalego/parvusdb","owner":"fractalego","description":"A simple in-memory graph database (wrapper for python-igraph)","archived":false,"fork":false,"pushed_at":"2019-07-06T22:12:03.000Z","size":32,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T23:52:39.048Z","etag":null,"topics":["edges","graph-database","in-memory-database","vertex"],"latest_commit_sha":null,"homepage":null,"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/fractalego.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-10T14:02:09.000Z","updated_at":"2025-02-13T02:19:10.000Z","dependencies_parsed_at":"2022-09-26T17:31:15.870Z","dependency_job_id":null,"html_url":"https://github.com/fractalego/parvusdb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractalego%2Fparvusdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractalego%2Fparvusdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractalego%2Fparvusdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fractalego%2Fparvusdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fractalego","download_url":"https://codeload.github.com/fractalego/parvusdb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131454,"owners_count":21052819,"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","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":["edges","graph-database","in-memory-database","vertex"],"created_at":"2024-10-12T14:46:44.335Z","updated_at":"2025-04-09T23:52:44.392Z","avatar_url":"https://github.com/fractalego.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ParvusDB a simple, in-memory graph database\n\n## Requirements \n* python-igraph\n* hy\n* python 3.5\n\n## Installation\npip3 install parvusdb\n\n\n## What is ParvusDB\n\nParvusDB is a small python3 library for handling graph operations. It acts as an in-memory \ngraph database. It is meant to be used for small graphs (a few hundred nodes)\n\n## Graph format\nGraphs are written as a collection of _edges_ and _vertices_. A vertex is written as\n```\n{}(a)\n```\n\nwhere `a` is the name of the vertex. This name is used for the operations on the vertex iself.\nA vertex can have properties written inside the brackets\n```\n{'tag': 'PERSON', 'text': 'john'}(a)\n```\n\nThe text inside the brackets is in the JSON format. \nEach of these properties is associated to the node and stored inside the graph\n\nThe edges are written as\n```\n{}(a,b)\n```\n\nwhere `a` is the _source_ node name and `b` is the _target_ node name. \nAs for the vertex, properties can be added inside the brackets\n```\n{'relation': 'LIVES_AT'}(a,b)\n```\n\nA vertex can have a name too, though it must be given as a property\n ```\n{'relation': 'LIVES_AT', 'name': 'r1'}(a,b)\n```\n\n\nA triplet can therefore be written in the form.\n ```\n{'tag': 'PERSON', 'text': 'john'}(a), {'relation': 'LIVES_AT'}(a,b), {'tag': 'PLACE', 'text': 'London'}(b)\n```\n \n## Keywords of the graph database\nThere are 6 commands (they must be typed in upper case)\n* CREATE\n* DELETE\n* MATCH\n* RETURN\n* SET\n* WHERE\n\n### The keyword CREATE\nThis command creates the graph on the right hand side\n```\nCREATE {'tag': 'PERSON', 'text': 'john'}(a), {'relation': 'LIVES_AT'}(a,b), {'tag': 'PLACE', 'text': 'London'}(b);\n```\n\n### The keyword MATCH\nThis command matches a graph with the topology and properties specified in the right hand side\n```\nMATCH {'tag': 'PERSON'}(a), {'relation': 'LIVES_AT', 'name': 'r1'}(a,b), {'tag': 'PLACE'}(b);\n```\n\n### The keyword DELETE\nThis keyword deletes the vertex or edge with the names on the right hand side\n```\nDELETE a, b, r1\n```\n\n### The keyword WHERE\nThis keyword let the user specify a LISP code as a condition for the match. \nFor example, if we want the \"text\" parameter of the node `a` to be in a list of names\n```\nMATCH {'tag': 'PERSON'}(a), {'relation': 'LIVES_AT', 'name': 'r1'}(a,b), {'tag': 'PLACE'}(b)\n  WHERE (in (get a \"text\") [\"john\" \"joseph\" \"joachim\"]);\n```\n\n### The keyword SET\nThis command let us modify the content of a graph.\nFor example, if we want to change the text of the node `a`   \n```\nMATCH {'tag': 'PERSON'}(a), {'relation': 'LIVES_AT', 'name': 'r1'}(a,b), {'tag': 'PLACE'}(b)\nSET (assoc a \"text\" \"not john anymore\");\n```\n\n### The keyword RETURN\nThis command let returns the properties of a specific node or edge\n```\nMATCH {'tag': 'PERSON'}(a), {'relation': 'LIVES_AT', 'name': 'r1'}(a,b), {'tag': 'PLACE'}(b)\nRETURN a, r1;\n```\n\nThe return value would be a list of the form\n```\n[{'a': {'tag': 'PERSON', 'text': 'john'}, 'r1': {'relation': 'LIVES_AT'}}]\n```\n\nIf no vertex or edge name is specified, the system return the whole graph (in the 'parvusdb format' ).\n\n## Python3 code examples\n\nLet's add a triplet to a graph\n```python\nfrom igraph import Graph\nfrom parvusdb import GraphDatabase\n\n\nif __name__ == '__main__':\n    g = Graph(directed=True)\n    db = GraphDatabase(g)\n\n    creation_string = \"\"\"\n    CREATE {'tag': 'PERSON', 'text': 'john'}(a), {'relation': 'LIVES_AT'}(a,b), \n           {'tag': 'PLACE', 'text': 'London'}(b) \n    RETURN;\n    \"\"\"\n    lst = db.query(creation_string)\n    print(lst)\n```\n\nwhich brings the output\n```bash\n[{'GRAPH': \"{'tag': 'PERSON', 'text': 'john'}(a), {'tag': 'PLACE', 'text': 'London'}(b), {'relation': 'LIVES_AT'}(a,b)\"}]\n```\n\nThen we can try to match elements of the triplet\n```python\nfrom igraph import Graph, plot\nfrom parvusdb import GraphDatabase\n\n\nif __name__ == '__main__':\n    g = Graph(directed=True)\n    db = GraphDatabase(g)\n\n    creation_string = \"\"\"\n    CREATE {'tag': 'PERSON', 'text': 'john'}(a), {'relation': 'LIVES_AT'}(a,b),\n           {'tag': 'PLACE', 'text': 'London'}(b);\n    \"\"\"\n    \n    match_string = \"\"\"\n    MATCH {}(a), {'relation': 'LIVES_AT'}(a,b), {}(b) \n    RETURN a,b;\n    \"\"\"\n    \n    lst = db.query(creation_string)\n    lst = db.query(match_string)\n    print(lst)\n```\n\nwith output\n```bash\n[{'a': {'name': 'a', 'tag': 'PERSON', 'text': 'john'}, 'b': {'name': 'b', 'tag': 'PLACE', 'text': 'London'}}]\n```\n\nWe can limit the matching process by using WHERE\n\n```python\nfrom igraph import Graph, plot\nfrom parvusdb import GraphDatabase\n\n\nif __name__ == '__main__':\n    g = Graph(directed=True)\n    db = GraphDatabase(g)\n\n    \n    creation_string = \"\"\"\n    CREATE {'tag': 'PERSON', 'text': 'john'}(a), {'relation': 'LIVES_AT'}(a,b),\n           {'tag': 'PLACE', 'text': 'London'}(b)\n    CREATE {'tag': 'PERSON', 'text': 'joseph'}(v1), {'relation': 'LIVES_AT'}(v1,v2),\n           {'tag': 'PLACE', 'text': 'London'}(v2)\n    \"\"\"\n    \n    match_string = \"\"\"\n    MATCH {}(_a), {'relation': 'LIVES_AT'}(_a,_b), {}(_b)\n      WHERE (= (get _a \"text\") \"joseph\")\n    RETURN _a,_b;\n    \"\"\"\n    \n    lst = db.query(creation_string)\n    lst = db.query(match_string)\n    print(lst)\n```\n\nwith output\n```python\n[{'_b': {'text': 'London', 'tag': 'PLACE', 'name': 'v2'}, '_a': {'text': 'joseph', 'tag': 'PERSON', 'name': 'v1'}}]\n```\n\n## TODO\n* Handling of errors in GraphDatabase.query_lines()\n* Ability to add LISP code outside WHERE and SET statements\n* Create a stand-alone command line for the database\n\n## Known issues\n* The igraph library does not like multiple edges on the same nodes, \n  therefore the MATCH function would not work correctly in those cases\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffractalego%2Fparvusdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffractalego%2Fparvusdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffractalego%2Fparvusdb/lists"}