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 officialneo4j 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 connectionbolt+s://- Encrypted connection with full certificatebolt+ssc://- Encrypted connection, self-signed certificateneo4j://- Routing driver (for clusters)neo4j+s://- Encrypted routing driver
"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.cypher_query_(str) - The Cypher query to execute**kwargs- Query parameters
EagerResult - Neo4j result object
session
Create a new database session.database(str | None) - Optional database name override
GraphDriverSession - Session object
transaction
Context manager for ACID transactions.AsyncIterator[Transaction] - Transaction context manager
close
Close the driver and release all connections.None
build_indices_and_constraints
Create all required indices and constraints for Graphiti.delete_existing(bool) - If True, delete existing indices before creating new ones
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.None - Raises exception if connection fails
with_database
Create a shallow copy of the driver targeting a different database.database(str) - The name of the database to target
GraphDriver - New driver instance with different database
Properties
provider
GraphProvider.NEO4J enum value.
Operations Properties
The driver exposes specialized operation interfaces:Usage Examples
Basic Connection
With Graphiti
Using Transactions
Azure OpenAI Integration
Environment Variables
Common environment variables for Neo4j configuration: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
Related
Drivers Overview
Learn about the driver architecture
Graphiti
Main Graphiti class documentation
FalkorDB Driver
Alternative Redis-based driver
Kuzu Driver
Embedded analytics driver