Connecting Neo4j with Python

This note is about how to connnect Python program to Noe4j graph database. To connect with any program, you should know your URL, Neo4j bolt port, username, and password. We also need a driver to connect with. There are several libraries available and in this note I use Neo4j Python Driver.

You can install Neo4j Python driver using this following commmand :

pip install neo4j

After instalation you can write your program. The simplest program is creating a node or vertex. This code will create a person node, named Alice.

from neo4j import GraphDatabase

uri="bolt://your.host:1234"
driver = GraphDatabase.driver(uri,auth=("your-user","your-password"))

session = driver.session()
session.run("create (s:person{name:'Alice'})")

session.close()

save your program as , for example, neopy.py. Make sure your Neo4j is up, run the program with this following command :

python neopy.py

Check your graph database and you will get a node!

Leave a Reply

Your email address will not be published.