Package: primal-grakn
primal-graknA convenience wrapper around the officialgrakn-python client.FeaturesLess code / boilerplate.Response data looks and acts like primitive data structures (python lists / dicts etc.). Thus more immediately intelligble, accessable, and JSON-serialisable.Some added conveniences such as match_or_insert function.Still access all underlying grakn-python client functionality where needed.WhyThegrakn-python clientprovides a complete and efficient object-oriented method of interaction with a Grakn instance. It can require a lot of code and recursion to get data. This extension aims to provide convenience through reducing code involved in connecting to Grakn and working with response data. It reflects a manner of working with Grakn through python that I have found to be preferrable.UsageExampleimportprimal_grakn.primal_graknasgraknwithgrakn.Graph(uri='myuri',keyspace='mykeyspace')asgraph:query='insert $a isa animal has name\"squirrel\";'# Escape your quotes, or use a raw stringconcept_map=graph.execute('match $a isa animal; get;')print(concept_map)[{'a':{'id':'V4144','type':'animal','base_type':'entity','attributes':[{'id':'V4216','label':'name','value':'squirrel'}]}}]print(concept_map.object)# Get the underlying ConceptMap objectprint(concept_map['a'].object)# Get the underlying Concept objectgraph.commit()# Don't forget to commit changes if you make them. N.B. this also closes the sessionAPIprimal_grakn.GraphNameTypeDescriptionParamsExampleGraphClassInitiates the session.kwarg: uri :string: Default='localhost:48555'kwarg: keyspace :string: Default=Nonekwarg: credentials :dict: Default={}Graph.executeMethodExecutes a query.arg: query :stringexecute('match $a isa animal')Graph.commitMethodCommits the changes and ends the session.Graph.match_or_insertMethodGiven a graql query string, match if it exists in the graph, or else insert it.arg: query :string: graql query without a prepended 'match' or 'insert' statementmatch_or_insert('$a isa animal has name \"squirrel\";')primal_grakn.ConceptDictDictionary respresenation of a Grakn Concept object.NameTypeDescriptionParamsExampleConceptDict.objectGrakn Concept objectCorresponding grakn-python objectAn explanation about explanationsAt the time of writing, the explanation data structures Grakn provides are undocumented. Briefly, the Grakn ConceptMap object exposes the set of facts as a tree. The top level of this tree includes the inferred facts from the response, and the compositional facts are nested within deeper levels.At present, we provide two structures to access these facts: one is .explanation, which is the explanation tree as it is exposed by grakn-python, parsed into the form of a python dictionary. The second is .flat_explanation, where the tree is flattened into a list. I found this much more convenient for my purposes, as it meant I could filter the list for only the types of concepts I was interested in for my explanation, and then sort the list into the logical order (Grakn does not provide any ordering in its explanation output).If you don't need information about the depth of inferences underlying your response, use .flat_explanation.I feel this is an area where ripe for improvement both as regards the Grakn API and third party packages such as this.InstallationClone the repogitclonehttps://github.com/cyclecycle/pygrakn.gitRequirementsGrakn running.Official python-grakn client:pip install graknContributionsAre welcome :)