Language Guides These guides and tutorials are designed to provide detailed examples of how to integrate Neo4j with your preferred programming language. Neo4j officially supports the drivers for .Net, Java, JavaScript and Python for the binary Bolt protocol. Our community… Learn More →

icon mdm Language Guides


These guides and tutorials are designed to provide detailed examples of how to integrate Neo4j with your preferred programming language. Neo4j officially supports the drivers for .Net, Java, JavaScript and Python for the binary Bolt protocol. Our community contributors provide drivers for all major programming languages for all protocols and APIs. In this section, we provide an introduction and a consistent example application for several languages and Neo4j drivers.

How to connect to Neo4j?


If you’ve installed and started Neo4j as a server on your system, you can already work interactively with the database via the built-in Neo4j Browser application on localhost:7474.

To build an application you want to connect to Neo4j from your technology stack. Fortunately it is very easy.

The binary Bolt Protocol

Starting with Neo4j 3.0 we support a binary protocol called Bolt. It is based on the PackStream serialization and supports protocol versioning, authentication and TLS via certificats.

The binary protocol is enabled in Neo4j by default, so you can use any language driver that supports it.

Neo4j officially provides drivers for .Net, Java, JavaScript and Python.

See also the for an detailed overview of the official drivers Neo4j Driver Manual

For more details on the protocol implementation, see the implementers documentation.

.Net
Java
JavaScript
Python

Neo4j .Net Driver

The Neo4j .NET driver is officially supported by Neo4j and connects to the database using the binary protocol. It aims to be minimal, while being idiomatic to .NET.

PM> Install-Package Neo4j.Driver-1.0.2
using Neo4j.Driver.V1;

using (var driver = GraphDatabase.Driver("bolt://localhost", AuthTokens.Basic("neo4j", "neo4j")))
using (var session = driver.Session())
{
    session.Run("CREATE (a:Person {name:'Arthur', title:'King'})");
    var result = session.Run("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title");

    foreach (var record in result)
    {
        Output.WriteLine($"{record["title"].As<string>()} {record["name"].As<string>()}");
    }
}

Name

Version

Authors

Neo4jDotNetDriver

1.0.2

The Neo4j Team, Chris Skardon, Martin Jensen

Package

Example

StackOverflow

Docs

API

Source

For more details on other drivers see Neo4j with .NET.

Neo4j Java Driver

The Neo4j Java driver is officially supported by Neo4j and connects to the database using the binary protocol. It aims to be minimal, while being idiomatic to Java.

When using Maven, add this to your pom.xml file:

<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>1.0.3</version>

For Gradle or Grails, this is how to add the dependency:

compile 'org.neo4j.driver:neo4j-java-driver:1.0.3'

For other build systems, see information available at Maven Central.

import org.neo4j.driver.v1.*;

Driver driver = GraphDatabase.driver( "bolt://localhost", AuthTokens.basic( "neo4j", "neo4j" ) );
Session session = driver.session();

session.run( "CREATE (a:Person {name:'Arthur', title:'King'})" );

StatementResult result = session.run( "MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" );
while ( result.hasNext() )
{
    Record record = result.next();
    System.out.println( record.get( "title" ).asString() + " " + record.get("name").asString() );
}

session.close();
driver.close();

Name

Version

Authors

neo4j-java-driver

1.0.3

The Neo4j Team

Package

Example

StackOverflow

Docs

API

Source

For more details on other drivers see Neo4j with Java or read about using Neo4j with the Spring Framework.

Neo4j JavaScript Driver

The Neo4j JavaScript driver is officially supported by Neo4j and connects to the database using the binary protocol. It aims to be minimal, while being idiomatic to JavaScript, allowing you to subscribe to a stream of responses, errors and completion events.

npm install neo4j-driver@1.0.2
var neo4j = require('neo4j-driver').v1;

var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
var session = driver.session();
session
  .run( "CREATE (a:Person {name:'Arthur', title:'King'})" )
  .then( function()
  {
    return session.run( "MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" )
  })
  .then( function( result ) {
    console.log( result.records[0].get("title") + " " + result.records[0].get("name") );
    session.close();
    driver.close();
  })

Name

Version

Authors

neo4j-driver

1.0.2

The Neo4j Team

Package

StackOverflow

Docs

API

Source

For more details on other drivers see Neo4j with JavaScript.

Neo4j Python Driver

The Neo4j Python driver is officially supported by Neo4j and connects to the database using the binary protocol. It aims to be minimal, while being idiomatic to Python.

pip install neo4j-driver
from neo4j.v1 import GraphDatabase, basic_auth

  driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"))
  session = driver.session()

  session.run("CREATE (a:Person {name:'Arthur', title:'King'})")

  result = session.run("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title")
  for record in result:
      print("%s %s" % (record["title"], record["name"]))

  session.close()

Name

Version

Authors

neo4j-driver

1.0.2

The Neo4j Team, Nigel Small

Package

StackOverflow

Docs

API

Source

For more details on other drivers see Neo4j with Python.

All Neo4j Drivers


Thanks to the Neo4j contributor community, there are additionally drivers for almost every popular programming language, most of which mimic existing database driver idioms and approaches. Get started with your stack now, see the dedicated page for more detail.

.NET

Java

Spring

JavaScript

Python

Ruby

PHP

R

Go

C/C++

Example Project Description

To demonstrate connection to and usage of Neo4j in different programming languages we’ve created an example application. It is a simple, one-page webapp, that uses Neo4j’s movie demo database (movie, actor, director) as data set. The same front-end web page in all applications consumes 3 REST endpoints provided by backend implemented in the different programming languages and drivers.

  • movie search by title
  • single movie listing
  • graph visualization of the domain

uploadsmovie application

Domain Model

(:Person {name})-[:ACTED_IN {roles}]->(:Movie {title,released})

GitHub

The source code for all the different language examples is available on GitHub as individual repositories that can be cloned and directly used as starting points.

Using the HTTP API

If you want to access Neo4j programmatically, you can also use the HTTP-API, which allow you to:

  • POST one or more Cypher statements with parameters, multiple per request to the server
  • Keep transactions open over multiple requests
  • Choose different result formats
  • Execute management operations or introspect the database

Let’s look at one of the underlying remote API endpoints that Neo4j offers to execute queries. These APIs can be then used directly via a HTTP library or a driver for your language.

A simple HTTP Cypher request, executable in the Neo4j Browser would look like this:

:POST /db/data/transaction/commit {"statements":[
      {"statement":"CREATE (p:Person {firstName:{name}}) RETURN p",
       "parameters":{"name":"Daniel"}}
    ]}

Some of the language drivers use the HTTP API under the hood, but make them available in a more convenient way.