2

Using py2neo to connect to neo4j DB: How can I convert "class 'py2neo.database.Record'" to a dictionary or list in python?

Birish
  • 5,514
  • 5
  • 32
  • 51

2 Answers2

3

You can directly convert a Record to a list:

result = graph.cypher.execute('MATCH (n) RETURN n')

a_record = result[0] # -> this is a Record object

list_of_things_in_record = list(a_record)

print(list_of_things_in_record)
Martin Preusse
  • 9,151
  • 12
  • 48
  • 80
1

Seems the data()-Method in any neo4j.data.Record can convert it into a dict.

with self.driver.session() as session:
    records = session.write_transaction(self._return_nodes, cypher)
    rdict = [rec.data() for rec in records]
    return rdict


 @staticmethod
    def _return_nodes(tx, cypher):        
        return [rec for rec in tx.run(cypher)]
Qohelet
  • 1,459
  • 4
  • 24
  • 41