
Neo4j Driver Python Skill
Implement correct Neo4j Python driver v6 patterns—sessions, transactions, async FastAPI lifespan, errors, and type mapping—in production graph apps.
Overview
Neo4j Driver Python Skill is an agent skill most often used in Build (also Ship perf, Operate errors) that documents official Neo4j Python Driver v6 connection, transaction, async, and error-handling patterns.
Install
npx skills add https://github.com/neo4j-contrib/neo4j-skills --skill neo4j-driver-python-skillWhat is this skill?
- Driver v6.x lifecycle: singleton GraphDatabase, verify_connectivity, Aura/bolt/Kerberos auth options
- execute_query with RoutingControl, result_transformer_, and trailing-underscore API conventions
- Managed execute_read/execute_write vs implicit session.run for LOAD CSV and IN TRANSACTIONS batches
- AsyncGraphDatabase with FastAPI lifespan and asyncio.gather patterns
- Error taxonomy: ConstraintError, ServiceUnavailable, TransientError, GQL status codes plus UNWIND batch writes and bookm
- Neo4j Python Driver v6.x (Jan 2026+); pip package name neo4j
- Python ≥ 3.10 required
Adoption & trust: 1 installs on skills.sh; 80 GitHub stars; 3/3 security scanners passed (skills.sh audits); trending (+100% hot-view momentum).
What problem does it solve?
Your agent keeps generating fragile Neo4j Python—wrong package name, leaking sessions, mishandling BigInt/temporal types, or missing retries on TransientError.
Who is it for?
Builders adding graph persistence to FastAPI or worker services on Aura or self-hosted Neo4j using driver v6 defaults.
Skip if: Cypher query design-only tasks, driver v4/v5 migration projects, or GraphRAG pipelines that need neo4j-graphrag-skill instead.
When should I use this skill?
You are writing or reviewing Python that uses the official Neo4j driver for connections, queries, async APIs, batch UNWIND writes, or production error handling.
What do I get? / Deliverables
You ship driver code with verified connectivity, correct transaction boundaries, async lifespan hooks, and predictable error handling ready to pair with neo4j-cypher-skill queries.
- Driver singleton/module with verify_connectivity
- Read/write transaction helpers or execute_query wrappers
- Documented error-handling and type-mapping conventions for your codebase
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Graph database client code is authored when the backend exists; canonical shelf is Build/backend even though the same patterns matter during ship hardening and operate incident response. Backend subphase holds service-layer driver lifecycle, pooling, and Cypher execution—not separate Cypher authoring (see neo4j-cypher-skill).
Where it fits
Bootstrap a FastAPI service with AsyncGraphDatabase lifespan and verify_connectivity against Aura before writing routes.
Tune connection pool sizes and session usage after load tests show exhaustion under parallel execute_write calls.
Map TransientError and ServiceUnavailable to retries and alerts when the graph cluster blips during peak traffic.
How it compares
Driver connectivity and transaction reference—not a Cypher tutor and not the separate neo4j-graphrag package skill.
Common Questions / FAQ
Who is neo4j-driver-python-skill for?
Solo and indie developers wiring Python APIs, workers, or agents to Neo4j who want v6-correct execute_query, async, and error patterns out of the box.
When should I use neo4j-driver-python-skill?
During Build backend setup; again in Ship when tuning pools under load; and in Operate when debugging ServiceUnavailable or constraint failures in production traces.
Is neo4j-driver-python-skill safe to install?
It guides database access patterns—never embed live credentials in prompts; review Security Audits on this Prism page and rotate secrets used in examples.
Workflow Chain
Then invoke: neo4j cypher skill
SKILL.md
READMESKILL.md - Neo4j Driver Python Skill
# neo4j-driver-python-skill Skill for writing Python applications that connect to Neo4j using the official Neo4j Python Driver. **Covers:** - Installation and driver lifecycle (singleton pattern, `verify_connectivity`) - URI schemes and auth options (Aura, bolt, bearer, Kerberos) - `execute_query` — default API with `RoutingControl`, `result_transformer_`, trailing-underscore convention - Managed transactions (`execute_read` / `execute_write`) — retry safety, result lifetime, `@unit_of_work` - Implicit transactions (`session.run`) — `LOAD CSV`, `CALL {} IN TRANSACTIONS` - Async driver (`AsyncGraphDatabase`) — FastAPI lifespan pattern, `asyncio.gather` - Error handling — `ConstraintError`, `ServiceUnavailable`, `TransientError`, GQL status codes - Result access — `Record`, `record.data()`, JSON serialization gotchas - Data type mapping — Python ↔ Cypher, temporal types, graph objects (`Node`, `Relationship`) - UNWIND batch writes (`list[dict]` only) - Connection pool tuning and session exhaustion - Causal consistency and bookmarks **Version / compatibility:** - Driver v6.x (Jan 2026+) — package name is `neo4j`, not `neo4j-driver` - Python ≥ 3.10 required **Not covered:** - Cypher query authoring → use `neo4j-cypher-skill` - Driver version upgrades / breaking changes → use `neo4j-migration-skill` - GraphRAG pipelines (`neo4j-graphrag` package) → use `neo4j-graphrag-skill` **Install:** ```bash pip install neo4j ``` # Async Driver — Full Reference ## Setup ```python from neo4j import AsyncGraphDatabase, RoutingControl import asyncio URI = "neo4j+s://xxx.databases.neo4j.io" AUTH = ("neo4j", "password") # Singleton — never create per-request driver = AsyncGraphDatabase.driver(URI, auth=AUTH) await driver.verify_connectivity() # on shutdown: await driver.close() ``` ## Async Managed Transactions ```python async def get_people(tx): result = await tx.run("MATCH (p:Person) RETURN p.name AS name") return await result.values() # consume INSIDE callback async def create_person(tx, name: str): await tx.run("MERGE (p:Person {name: $name})", name=name) async def run_queries(driver): async with driver.session(database="neo4j") as session: people = await session.execute_read(get_people) await session.execute_write(create_person, "Carol") ``` ## Async Result Methods | Method | Returns | Notes | |---|---|---| | `await result.values()` | `list[list]` | One inner list per row | | `await result.data()` | `list[dict]` | One dict per record, keyed by column name | | `await result.single()` | `Record` | Raises if 0 or 2+ results | | `await result.single(strict=False)` | `Record \| None` | None for 0, raises for 2+ | | `await result.fetch(n)` | `list[Record]` | Up to n records | | `await result.consume()` | `ResultSummary` | Discards remaining | | `async for record in result` | iterates `Record` | Lazy streaming | ## FastAPI Lifespan Pattern ```python from contextlib import asynccontextmanager from fastapi import FastAPI, Depends from neo4j import AsyncGraphDatabase, RoutingControl _driver = None @asynccontextmanager async def lifespan(app: FastAPI): global _driver _driver = AsyncGraphDatabase.driver(URI, auth=AUTH) await _driver.verify_connectivity() yield await _driver.close() app = FastAPI(lifespan=lifespan) def get_driver(): return _driver @app.get("/people") async def get_people(driver=Depends(get_driver)): records, _, _ = await driver.execute_query( "MATCH (p:Person) RETURN p.name AS name", database_="neo4j", routing_=RoutingControl.READ, ) return [r["name"] for r in records] ``` ## Concurrency with asyncio.gather ```python async def run_concurrent(driver): results = await asyncio.gather( driver.execute_query("MATCH (a:Artist) RETURN a.name AS name", database_="neo4j"), driver.execute_query("MATCH (v:Venue) RETURN v.name AS name", database_="neo4j"), ) artists = [r["name"] for r in results[0].record