You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
To build applications with Neo4j, you use official drivers that communicate with the database over the Bolt protocol. Neo4j provides drivers for all major programming languages.
Bolt is Neo4j's binary protocol, optimised for graph database communication:
| Feature | Description |
|---|---|
| Binary format | Efficient serialisation (faster than HTTP/JSON) |
| Connection pooling | Reuses connections for better performance |
| Encryption | TLS by default on AuraDB |
| Port | 7687 (default) |
| Language | Package |
|---|---|
| JavaScript / TypeScript | neo4j-driver |
| Python | neo4j |
| Java | org.neo4j.driver:neo4j-java-driver |
| .NET (C#) | Neo4j.Driver |
| Go | github.com/neo4j/neo4j-go-driver |
npm install neo4j-driver
const neo4j = require('neo4j-driver');
const driver = neo4j.driver(
'neo4j://localhost:7687',
neo4j.auth.basic('neo4j', 'your-password')
);
// Verify connectivity
await driver.verifyConnectivity();
console.log('Connected to Neo4j');
const session = driver.session();
try {
// Read query
const result = await session.executeRead(async (tx) => {
return tx.run(
'MATCH (p:Person {name: $name}) RETURN p',
{ name: 'Alice' }
);
});
for (const record of result.records) {
console.log(record.get('p').properties);
}
} finally {
await session.close();
}
await session.executeWrite(async (tx) => {
await tx.run(
'CREATE (p:Person {name: $name, age: $age})',
{ name: 'Bob', age: 25 }
);
});
await driver.close();
pip install neo4j
from neo4j import GraphDatabase
driver = GraphDatabase.driver(
"neo4j://localhost:7687",
auth=("neo4j", "your-password")
)
# Verify connectivity
driver.verify_connectivity()
def get_person(tx, name):
result = tx.run(
"MATCH (p:Person {name: $name}) RETURN p",
name=name
)
return [record["p"] for record in result]
with driver.session() as session:
people = session.execute_read(get_person, "Alice")
for person in people:
print(person["name"], person["age"])
driver.close()
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>5.14.0</version>
</dependency>
import org.neo4j.driver.*;
try (var driver = GraphDatabase.driver(
"neo4j://localhost:7687",
AuthTokens.basic("neo4j", "your-password")))
{
driver.verifyConnectivity();
try (var session = driver.session()) {
var result = session.executeRead(tx -> {
var res = tx.run(
"MATCH (p:Person {name: $name}) RETURN p.name AS name, p.age AS age",
Values.parameters("name", "Alice")
);
return res.list(r -> r.get("name").asString() + " (" + r.get("age").asInt() + ")");
});
result.forEach(System.out::println);
}
}
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.