Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-31-2019 10:17 AM
Is it possible to execute a python program which references a graph database that was created in Neo4j Desktop? If so, I'd very much appreciate seeing an example of how it was done. If not, is there another edition of Neo4j that I should be working with to do this?
I am using python 3.7.4 on Windows and I'm using Neo4j Desktop 1.2.1
Thank you.
10-31-2019 10:56 AM
you should be able to connect using the Neo4j Bolt Driver for Python and as described at https://neo4j.com/docs/driver-manual/1.7/client-applications/
11-01-2019 08:32 AM
Thanks for your reply Dana. I am able to run the following code using the Neo4j Bolt Driver for Python. Everything works fine. I load the data into a database and then the friend names do get printed.
import sys, time
from neo4j import GraphDatabase
#url = "bolt://localhost:7687"
url = "bolt://localhost:11002"
driver = GraphDatabase.driver(url, auth=("neo4j", "xxxxx"))
def add_friend(tx, name, friend_name):
tx.run("MERGE (a:Person {name: $name}) "
"MERGE (a)-[:KNOWS]->(friend:Person {name: $friend_name})",
name=name, friend_name=friend_name)
def print_friends(tx, name):
for record in tx.run("MATCH (a:Person)-[:KNOWS]->(friend) WHERE a.name = $name "
"RETURN friend.name ORDER BY friend.name", name=name):
print(record["friend.name"])
with driver.session() as session:
session.write_transaction(add_friend, "Arthur", "Guinevere")
session.write_transaction(add_friend, "Arthur", "Lancelot")
session.write_transaction(add_friend, "Arthur", "Merlin")
session.read_transaction(print_friends, "Arthur")
print("Successful completion of program")
But in Neo4j Desktop, I previously loaded the contents of 605,000 rows of data from a csv file into a database called Emails and I want to be able to access that graph database in my python program. If this were possible, I would expect to have to provide the name of my database somewhere but I haven't seen any examples yet where this is being done. I'm wondering if it's even possible to do this with Neo4j Desktop. Maybe I need the Enterprise version? I've been doing a lot of reading... If it is possible to do what I'm asking with Neo4j Desktop and a code example could be provided of how it's done, I'd very much appreciate it.
Don
11-01-2019 09:28 AM
there is not a means to define the database. Rather you define a port to connect on , in your case url = "bolt://localhost:11002
and this port 11002 is bound to a particular Neo4j instance that thus is connected to a particular database.
Currently 1 Neo4j instance can only read 1 database.
All the sessions of the conference are now available online