Skip to main content

Neo4j Bolt driver for Python

Project description

Neo4j Bolt Driver for Python

This repository contains the official Neo4j driver for Python.

Starting with 5.0, the Neo4j Drivers will be moving to a monthly release cadence. A minor version will be released on the last Friday of each month so as to maintain versioning consistency with the core product (Neo4j DBMS) which has also moved to a monthly cadence.

As a policy, patch versions will not be released except on rare occasions. Bug fixes and updates will go into the latest minor version and users should upgrade to that. Driver upgrades within a major version will never contain breaking API changes.

See also: https://neo4j.com/developer/kb/neo4j-supported-versions/

  • Python 3.11 supported.

  • Python 3.10 supported.

  • Python 3.9 supported.

  • Python 3.8 supported.

  • Python 3.7 supported.

Installation

To install the latest stable version, use:

pip install neo4j

Quick Example

from neo4j import GraphDatabase

driver = GraphDatabase.driver("neo4j://localhost:7687",
                              auth=("neo4j", "password"))

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):
    query = ("MATCH (a:Person)-[:KNOWS]->(friend) WHERE a.name = $name "
             "RETURN friend.name ORDER BY friend.name")
    for record in tx.run(query, name=name):
        print(record["friend.name"])

with driver.session(database="neo4j") as session:
    session.execute_write(add_friend, "Arthur", "Guinevere")
    session.execute_write(add_friend, "Arthur", "Lancelot")
    session.execute_write(add_friend, "Arthur", "Merlin")
    session.execute_read(print_friends, "Arthur")

driver.close()

Connection Settings Breaking Change (4.x)

  • The driver’s default configuration for encrypted is now false (meaning that driver will only attempt plain text connections by default).

  • Connections to encrypted services (such as Neo4j Aura) should now explicitly be set to encrypted.

  • When encryption is explicitly enabled, the default trust mode is to trust the CAs that are trusted by operating system and use hostname verification.

  • This means that encrypted connections to servers holding self-signed certificates will now fail on certificate verification by default.

  • Using the new neo4j+ssc scheme will allow to connect to servers holding self-signed certificates and not use hostname verification.

  • The neo4j:// scheme replaces bolt+routing:// and can be used for both clustered and single-instance configurations with Neo4j 4.0.

See, https://neo4j.com/docs/migration-guide/4.0/upgrade-driver/#upgrade-driver-breakingchanges

See, https://neo4j.com/docs/driver-manual/current/client-applications/#driver-connection-uris for changes in default security settings between 3.x and 4.x

Connecting with Python Driver 4.x to Neo4j 3.5 (EOL)

Using the Python Driver 4.x and connecting to Neo4j 3.5 with default connection settings for Neo4j 3.5.

# the preferred form

driver = GraphDatabase.driver("neo4j+ssc://localhost:7687", auth=("neo4j", "password"))

# is equivalent to

driver = GraphDatabase.driver("neo4j://localhost:7687", auth=("neo4j", "password"), encrypted=True, trust=False)

Connecting with Python Driver 1.7 (EOL) to Neo4j 4.x

Using the Python Driver 1.7 and connecting to Neo4j 4.x with default connection settings for Neo4j 4.x.

driver = GraphDatabase.driver("neo4j://localhost:7687", auth=("neo4j", "password"), encrypted=False)

Other Information

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neo4j-driver-5.8.0.tar.gz (187.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page