How to use dictionary parameters in Python Neo4J

I am using py2neo to run a Cypher query in Python. Currently, I am passing the values of $user_id and $name.

query = "MATCH (user:User{id:$user_id, name: $name}) MATCH (user)-[rout]->() WITH user, collect(DISTINCT {relationship: type(rout), node: endNode(rout)}) AS extended_info RETURN { user: user, extended_info: extended_info } AS result"

graph.run(query, parameters= {"user_id": 1, "name": "Vivek"}).data()

Instead of just passing the values, I want to pass a dictionary of key and value. Something like this:

{id:1, name: "Vivek"}

And use it directly in the query. This will provide me with the flexibility to write a single query for filtering for one or multiple properties.

query = "MATCH (user:User{$params}) MATCH (user)-[rout]->() WITH user, collect(DISTINCT {relationship: type(rout), node: endNode(rout)}) AS extended_info RETURN { user: user, extended_info: extended_info } AS result"

graph.run(query, parameters= {id:1, name: "Vivek"}).data()

Is there a way to do it using py2neo? Or is there any other way to write a single query for a match query?

Hi @vmaskara,

Welcome to the community!

This is definitely resolved in py2neo 5.0b1. I believe that there's been a syntax change between versions.

$ pip intall py2neo==5.0b1

(for people of the future find the latest version here: GitHub - py2neo-org/py2neo: Py2neo is a comprehensive Neo4j driver library and toolkit for Python.)

Have you tried upgrading? Try this and check to see if your queries are working as expected. Hopefully this does the trick.

All the best

In the latest version this is achieved with

query = "MATCH (user:User $params ) MATCH (user)-[rout]->() WITH user, collect(DISTINCT {relationship: type(rout), node: endNode(rout)}) AS extended_info RETURN { user: user, extended_info: extended_info } AS result"

graph.run(query, params= {id:1, name: "Vivek"})