Python is one of the Neo4j supported languages and an official driver is provided. Official drivers connect to the databases using BOLT protocol (HTTP is not available).

📘

About connection parameters

We've used test credentials for all the following examples. Please replace them with your real connection parameters.

You'll find all the required information to connect to your database on our admin panel if you navigate to the Connection section. More on connecting to your database here

This section is intended to provide a small working example to connect to a GrapheneDB database using the Python driver. To get more detailed information, visit the driver web page: https://pypi.org/project/neo4j/

📘

Bolt protocol is available in 3.0.0 or higher versions of Neo4j. You can check your Neo4j version if you navigate to the Overview page of your database.

The easiest way to install the Python drivers for Neo4j is via PyPI (Python Package Index):

$ pip install neo4j

📘

Check the driver releases for the newest driver version available.

Setting up the connection:

from neo4j import GraphDatabase

uri = "bolt://db-jidgsytyxo1r31sd4ker.graphenedb.com:24786"
user = "admin"
pass = "b.P0shGn2gvpUD.9RAHyuY4QXkkUK7w"
driver = GraphDatabase.driver(uri, auth=(user, pass), encrypted=True)

You can also use the new bolt+s URI scheme to enable encryption with a full certificate check:

from neo4j import GraphDatabase

uri = "bolt+s://db-jidgsytyxo1r31sd4ker.graphenedb.com:24786"
user = "admin"
pass = "b.P0shGn2gvpUD.9RAHyuY4QXkkUK7w"
driver = GraphDatabase.driver(uri, auth=(user, pass))

You can test the connection by running a simple query of the Movies dataset example:

session = driver.session()
query = "MATCH (:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(tomHanksMovies) RETURN movies"

def print_count(tx):
    for record in tx.run(query):
        print(record["movies"]["title"])

with driver.session() as session:
    session.read_transaction(print_count)

Updated about a month ago

Python


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.