{"id":13905828,"url":"https://github.com/CodyKochmann/graphdb","last_synced_at":"2025-07-18T03:32:17.857Z","repository":{"id":41211625,"uuid":"108339960","full_name":"CodyKochmann/graphdb","owner":"CodyKochmann","description":"sqlite based graph database for storing native python objects and their relationships to each other","archived":false,"fork":false,"pushed_at":"2021-05-08T14:42:02.000Z","size":1196,"stargazers_count":194,"open_issues_count":14,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-30T07:48:20.299Z","etag":null,"topics":[],"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/CodyKochmann.png","metadata":{"files":{"readme":"README.md","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":"2017-10-26T00:07:32.000Z","updated_at":"2025-04-23T19:23:48.000Z","dependencies_parsed_at":"2022-07-21T21:32:49.464Z","dependency_job_id":null,"html_url":"https://github.com/CodyKochmann/graphdb","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/CodyKochmann/graphdb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodyKochmann%2Fgraphdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodyKochmann%2Fgraphdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodyKochmann%2Fgraphdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodyKochmann%2Fgraphdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodyKochmann","download_url":"https://codeload.github.com/CodyKochmann/graphdb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodyKochmann%2Fgraphdb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265696631,"owners_count":23812812,"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":[],"created_at":"2024-08-06T23:01:24.534Z","updated_at":"2025-07-18T03:32:17.506Z","avatar_url":"https://github.com/CodyKochmann.png","language":"Python","readme":"# graphdb\n\n[![Downloads](https://pepy.tech/badge/graphdb)](https://pepy.tech/project/graphdb)\n[![Downloads](https://pepy.tech/badge/graphdb/month)](https://pepy.tech/project/graphdb)\n[![Downloads](https://pepy.tech/badge/graphdb/week)](https://pepy.tech/project/graphdb)\n\nA sqlite based graph database for storing native python objects and their relationships to each other.\n\n![ ](https://bit.ly/graph_db_png)\n\n## How to install it?\n\n```\npip install graphdb\n```\n\n## How to use it?\n\n```python\nIn [1]: # import GraphDB\n\nIn [2]: from graphdb import GraphDB\n\nIn [3]: # initialize a database\n\nIn [4]: db = GraphDB('/tmp/test_graph.db') # uses ':memory:' if no path\n\nIn [5]: # you can store relations between native python objects\n\nIn [6]: for a in range(10):\n   ...:     b = a + 1\n   ...:     print(a, b)\n   ...:     db.store_relation(a, 'comes_before', b)\n   ...:\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n\nIn [7]: # you have as many relationships between objects as you want\n\nIn [8]: def is_prime(a):\n   ...:     ''' returns true if 'a' is prime '''\n   ...:     return a\u003e1 and all(a % i for i in range(2, a))\n   ...:\n   ...: def preceding_primes(a):\n   ...:     ''' returns a list of prime numbers less than 'a' '''\n   ...:     return [i for i in range(a) if is_prime(i)]\n   ...:\n   ...: for i in range(11):\n   ...:     for p in preceding_primes(i):\n   ...:         db.store_relation(i, 'preceding_prime', p)\n   ...:\n\nIn [9]: # queries to the database are done through attribute chains\n\nIn [10]: db(7).comes_before.preceding_prime(list)\nOut[10]: [2, 3, 5, 7]\n\nIn [11]: # to break the query into pieces, we start with the starting point\n\nIn [12]: db(7)(list) # tells the db to start the query at this object\nOut[12]: [7]\n\nIn [13]: # now we add 'comes_before' to hop to whatever object '7 comes_before'\n\nIn [14]: db(7).comes_before(list)\nOut[14]: [8]\n\nIn [15]: # then we add the 'preceding_prime' to get all connected primes to 8\n\nIn [16]: db(7).comes_before.preceding_prime(list)\nOut[16]: [2, 3, 5, 7]\n\nIn [17]: # since every query outputs iterable elements, it doesn't matter how\n    ...: # many elements you're currently at because elements only stay as long\n    ...: # as the query applies to them\n\nIn [18]: db(7).comes_before.preceding_prime.comes_before(list)\nOut[18]: [3, 4, 6, 8]\n\nIn [19]: db(7).comes_before.preceding_prime.comes_before.comes_before(list)\nOut[19]: [4, 5, 7, 9]\n\nIn [20]: db(7).comes_before.preceding_prime.comes_before.comes_before.comes_before(list)\nOut[20]: [5, 6, 8, 10]\n\nIn [21]: # so what if we add one more 'comes_before' even though we never\n    ...: # assigned '10' a relationship to refer to?\n\nIn [22]: db(7).comes_before.preceding_prime.comes_before.comes_before.comes_before.comes_before(list)\nOut[22]: [6, 7, 9]\n\nIn [23]: # the query simply drops that node since its relational path didn't\n    ...: # apply to the 4th result\n\nIn [24]: # Why does every query end with '(list)'?\n\nIn [25]: # graphdb sets up queries so you can continue to get each next step\n    ...: # until you add '()' to the end of it which then tells graphdb that\n    ...: # you want a materialized view of that spot.\n    ...:\n    ...: # The reason why in this demo '(list)' was being added instead of\n    ...: # '()' was because by default, graphdb returns a native python\n    ...: # generator so you can iterate through each individual object\n\nIn [26]: # just to demonstrate normal behavior\n    ...: db(7).comes_before()\nOut[26]: \u003cgenerator object VList.__call__.\u003clocals\u003e.\u003cgenexpr\u003e at 0x103336f68\u003e\n\nIn [27]: # so we could technically do\n    ...: list(db(7).comes_before())\nOut[27]: [8]\n\nIn [28]: # or the more natural feeling\n\nIn [29]: db(7).comes_before(list)\nOut[29]: [8]\n\nIn [30]: # 'list' isn't the only type you can pass into the query breakpoint,\n    ...: # any container-like type you want to use should work\n\nIn [31]: db(7).comes_before(set)\nOut[31]: {8}\n\nIn [32]: # Are there any filtering mechanisms that can be used to cut down how\n    ...: # many relations graphdb queries produce?\n\nIn [33]: # '.where()' is used to filter relationships. So, for example:\n\nIn [34]: # what we're gonna filter\n    ...: db(8).preceding_prime(list)\nOut[34]: [2, 3, 5, 7]\n\nIn [35]: # this filters preceding_primes of 8 which are larger than 5\n    ...: db(8).preceding_prime.where(lambda i:i\u003e5)(list)\nOut[35]: [7]\n\nIn [36]: # or we can filter items based on their linked objects\n    ...: db(8).preceding_prime.where('comes_before', lambda i:i\u003e5)(list)\nOut[37]: [5, 7]\n\n```\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCodyKochmann%2Fgraphdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCodyKochmann%2Fgraphdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCodyKochmann%2Fgraphdb/lists"}