Package: dict2graph
Dict2graphTransfer (json compatible) Python dicts into a Neo4j graph database.dict2graph also comes with some powerful data transform capabilities.Maintainer: Tim Bleimehl -bleimehl@dzd-ev.deLicence: MITpublic issue tracker:https://github.com/dzd-ev/dict2graph-docs/issuesuser docs:https://dzd-ev.github.io/dict2graph-docs/source code:https://git.connect.dzd-ev.de/dzdpythonmodules/dict2graphimportant upstream modules:https://github.com/kaiserpreusse/graphiohttps://github.com/neo4j/neo4j-python-driverhttps://github.com/py2neo-org/py2neoContent:Dict2graphInstallWhat is dict2graphDifference compared to apoc.load.jsonRecommended workflowWhat dict2graph isnotpy2neo depcrecation warningBasic Usage ExampleLoad a dictTransform the modelInstallpip3 install dict2graphWhat is dict2graphWith dict2graph you can transfer python dicts into a neo4j graph out of the box.And if you are not happy with the structure of the result, dict2graph comes with a bunch of, transformation tools, which are easy to apply to your model.Difference compared to apoc.load.jsonClient side python parsing (nodatabase settingfor file loading is necessary)Iterative transforming of the json model to a graph model. You dont need to understand the complete json structure from the begining to load it into Neo4j.More resiliant against changes and irregularities in the json source.Recommended workflowThe recommended workflow is:Load your dict (or a sample of your larger datasets) as it is, with dict2graph into a neo4j test instanceInspect the result in neo4jAdd dict2graph-transformers to shape your resulting graph modelWipe your neo4j test instanceRepeat the work flow with the changed dict2graph-transformers until your happy with the resultWhat dict2graph isnotdict2graph cannotbe used for de-/serializing your dict into a graph database. There is nograph2dictfunctionality (nore is it planned to have one).Your data/dict will be transformed to be more suitable in a graph represantation. On the way, certain informations can be lost. Reproducing the exact same dict from the graph is not possible in many cases.py2neo depcrecation warningIn past versions ofdict2graph, the awesomepy2neolibrary was the only way to connect to a Neo4j instance.But (sadly) this lib is in a low-maintanance mode. For now it is still supported but marked as deprecated. We recommend to switch to the officialNeo4j Python Driver.Basic Usage ExampleWith formalities out of the way, lets have some simple examples how dict2graph works...Load a dictfromdict2graphimportDict2graphfromneo4jimportGraphDatabase# connect to our neo4j databaseNEO4J_DRIVER=GraphDatabase.driver("neo4j://localhost")# lets create a small random  dictdic={"action":{"id":1,"target":"El Oued","entities":[{"id":"Isabelle Eberhardt"},{"id":"Slimène Ehnni"}],}}# create a dict2graph instance,# parse the dict# and load it into our neo4j instance.Dict2graph().parse(dic).create(NEO4J_DRIVER)This will result in following graph:Transform the modelWe now have loaded the dict data into a Neo4j Graph. But usally we dont need stuff like explicitlists in a graph. Also it is common to uppercase relationship types and capitalize labels.So we need to make some adjustments to improve the graph represenation of the dict.This is wheredict2graph.Transformers come into play.fromdict2graphimportDict2graph,Transformer,NodeTrans,RelTransfrompy2neoimportGraphNEO4J_DRIVER=GraphDatabase.driver("neo4j://localhost")data={"action":{"id":1,"target":"El Oued","entities":[{"id":"Isabelle Eberhardt"},{"id":"Slimène Ehnni"}],}}d2g=Dict2graph()d2g.add_transformation([Transformer.match_nodes().do(NodeTrans.CapitalizeLabels()),Transformer.match_rels().do(RelTrans.UppercaseRelationType()),Transformer.match_nodes().do(NodeTrans.PopListHubNodes()),])d2g.parse(data)d2g.create(NEO4J_DRIVER)Now that looks more like a graph we are used to, isn't it?There are a lot of more powerfulTransformersand you can evenmake your own🚀!Have a deeper look into the docs tolearn more how Transformers work.