Connection Pooling and Error Handling
Learn to manage Neo4j driver connection pools efficiently and handle errors and retries when integrating Neo4j with applications.
The Driver Is Long-Lived
A common mistake is creating a new driver per request. The Neo4j driver manages a connection pool and should be created once and reused for your app's lifetime.
from neo4j import GraphDatabase
driver = GraphDatabase.driver('neo4j://localhost:7687', auth=('neo4j', 'password'))
# reuse driver everywhere; close at shutdownWhat a Connection Pool Does
The driver keeps a pool of open connections and hands them out to sessions on demand. This avoids the cost of opening a TCP connection per query.
All lessons in this course
- Connecting with the Python Driver
- Performing CRUD Operations Programmatically
- Handling Transactions and Sessions
- Connection Pooling and Error Handling