Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Connecting to a local Neo4j database from a local jupyter notebook

Node Clone

I've got a local Neo4j instance running, and I want to connect to it via jupyter.

Eventually I want to do this from within AWS, but for now I'd settle for getting it going locally.

Here's the access information for my Neo4j instance:

I've tried this in two ways, with Graph from py2neo and GraphDatabase from Neo4j.

With graphdb = Graph() I get this error:

ClientError: [Security.Unauthorized] The client is unauthorized due to authentication failure.

With graphdb = Graph("bolt://") I get the same error:

ClientError: [Security.Unauthorized] The client is unauthorized due to authentication failure.

So then I reset my password and gave graphdb = Graph("bolt://", secure=True, auth=("neo4j", "my password")) a shot, which generated this error:

ConnectionUnavailable: Cannot open connection to ConnectionProfile('bolt+s://neo4j@')

Interestingly, using GraphDatabase does at least connect: driver = GraphDatabase.driver("bolt://", auth=("neo4j", "my password"))

Now, I'm open to doing everything via GraphDatabase functionality, but it looks like most of the people doing similar work (reading and writing out of a graph database with Python and Neo4j) are doing most of this with py2neo.

Plus, it bothers me that I can't get a simple connection going.

But if the community thinks there's no reason to worry with py2neo because GraphDatabase can do everything I need, I'm fine going that way.


Hi @trent.fowler!

Maybe @clair.sullivan's blog post on loading data into Neo4j with Python would be helpful? Create a Graph Database in Neo4j Using Python

The syntax is a bit confusing, but you're on the right path with using GraphDatabase.driver to open the connection. It's usually easiest to set up some helper functions that handle passing queries to your GraphDatabase object - Clair's example has a great demo of how to set that up.

Py2Neo is great if you're working with a single instance, and don't need to deal with clusters or transaction functions - but we usually recommend using the officially supported driver.

This looks really promising, thanks Alicia!

Just to add on a bit here...

...py2neo is great if you are doing data science tasks because it has things like the ability to directly create a Pandas dataframe from the result. However, the official Python driver has the ability to do transactional writes, which is important if you do something like go to Aura.