0

I'm currently working with knowledge graphs with Neo4j using Python Driver. I'm already connected to localhost

URI = "neo4j://localhost:7687"
AUTH = ("neo4j", "neo4j")
   
   
with GraphDatabase.driver(URI, auth=AUTH) as driver:
    driver.verify_connectivity()

driver: Driver = GraphDatabase.driver(URI, auth=AUTH)

Now I would like to display the results as a graph of some queries like the following:

query = 'MATCH (n)-[r]->(c)  where r.filePath = "../data/mydata.json" RETURN *'

driver.execute_query(query)

From what I understood, python driver does not interact directly with neo4j browser. So which is the best way to show the resulting Graph?

1 Answer 1

0

What do you expect the code to stream? The Cypher query doesn't have a RETURN clause.

Try to inspect the summary of the EagerResult object returned from execute_query. Here's an example

from neo4j import GraphDatabase


URI = "neo4j://localhost:7687"
AUTH = ("neo4j", "neo4j")


with GraphDatabase.driver(URI, auth=AUTH) as driver:
    driver.verify_connectivity()
    result = driver.execute_query(
        "CREATE (charlie:Person:Actor {name: 'Charlie Sheen'})"
        "-[:ACTED_IN {role: 'Bud Fox'}]->"
        "(wallStreet:Movie {title: 'Wall Street'})"
        "<-[:DIRECTED]-"
        "(oliver:Person:Director {name: 'Oliver Stone'})"
    )
    print(result.summary.counters)

Which gives me

{'_contains_updates': True, 'labels_added': 5, 'relationships_created': 2, 'nodes_created': 3, 'properties_set': 4}

So it's clearly doing something.

If this doesn't work, it can be helpful to enable the driver's debug logging to see what it's up to. There's a section in the API docs that shows how to do that: https://neo4j.com/docs/api/python-driver/current/api.html#logging

The simplest form looks like this

from neo4j.debug import watch

watch("neo4j")
# from now on, DEBUG logging to stderr is enabled in the driver
1
  • Thank you for your answer. I try to explain myself better: in general, I want the results of my queries to be a visual graph, and not only a list of results. Is there any tool I can use to show the graphic results of my python code?
    – biowhat
    Commented Mar 4 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.