Skip to main content
The Neo4jDriver class provides connectivity to Neo4j graph databases with full ACID transaction support.

Overview

Neo4j is the industry-standard graph database platform. The Neo4jDriver leverages the official neo4j Python driver to provide:
  • Full ACID transaction support
  • Automatic index and constraint creation
  • Connection pooling
  • Concurrent query execution
  • Health checks

Constructor

Parameters

str
required
The connection URI for the Neo4j database.Supported URI schemes:
  • bolt:// - Unencrypted connection
  • bolt+s:// - Encrypted connection with full certificate
  • bolt+ssc:// - Encrypted connection, self-signed certificate
  • neo4j:// - Routing driver (for clusters)
  • neo4j+s:// - Encrypted routing driver
Example: "bolt://localhost:7687"
str | None
required
The username for Neo4j authentication.Can be None for databases without authentication (not recommended for production).Example: "neo4j"
str | None
required
The password for Neo4j authentication.Can be None for databases without authentication (not recommended for production).Example: "password"
str
default:"neo4j"
The name of the Neo4j database to connect to.Neo4j supports multiple databases. The default database is typically named "neo4j".Example: "graphiti"

Methods

execute_query

Execute a Cypher query and return results.
Parameters:
  • cypher_query_ (str) - The Cypher query to execute
  • **kwargs - Query parameters
Returns: EagerResult - Neo4j result object

session

Create a new database session.
Parameters:
  • database (str | None) - Optional database name override
Returns: GraphDriverSession - Session object

transaction

Context manager for ACID transactions.
Returns: AsyncIterator[Transaction] - Transaction context manager

close

Close the driver and release all connections.
Returns: None

build_indices_and_constraints

Create all required indices and constraints for Graphiti.
Parameters:
  • delete_existing (bool) - If True, delete existing indices before creating new ones
Returns: None
This method is automatically called during driver initialization. You typically don’t need to call it manually unless you want to rebuild indices.

health_check

Verify connectivity to the Neo4j database.
Returns: None - Raises exception if connection fails

with_database

Create a shallow copy of the driver targeting a different database.
Parameters:
  • database (str) - The name of the database to target
Returns: GraphDriver - New driver instance with different database

Properties

provider

Returns the GraphProvider.NEO4J enum value.

Operations Properties

The driver exposes specialized operation interfaces:
These properties provide access to database-specific implementations of graph operations.

Usage Examples

Basic Connection

With Graphiti

Using Transactions

Azure OpenAI Integration

Environment Variables

Common environment variables for Neo4j configuration:
Load in your application:

Thread Safety

The Neo4jDriver is thread-safe and uses connection pooling. You can safely:
  • Share a single driver instance across multiple coroutines
  • Execute concurrent queries
  • Create multiple sessions from the same driver

Drivers Overview

Learn about the driver architecture

Graphiti

Main Graphiti class documentation

FalkorDB Driver

Alternative Redis-based driver

Kuzu Driver

Embedded analytics driver