Connect to Neo4j

Neo4j language guides

Neo4j provides official libraries for Python, JavaScript, Java, .NET, and Go.

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.

You should be familiar with graph database concepts and the property graph model. You should have created an Neo4j AuraDB cloud instance, or installed Neo4j locally.

Learn with GraphAcademy

We have a range of Neo4j Developer courses that teach you to build connect to Neo4j using each of our officially supported Drivers.

Building Neo4j Applications with Java Building Neo4j Applications with Node.js Building Neo4j Applications with Python Building Neo4j Applications with .NET Building Neo4j Applications with Go

How to connect to Neo4j?

If you’ve created an AuraDB instance, or installed and started Neo4j as a server on your system, you can already work interactively with the database via the built-in Neo4j Browser, which you find in the AuraDB console, or if you’re running locally, on localhost:7474.

To build an application, you want to connect to Neo4j from your technology stack, use a driver which connects to Neo4j via Bolt or HTTP.

The binary Bolt Protocol

Starting with Neo4j v3.0, we support a binary protocol called Bolt. It is based on the PackStream serialization and supports the Cypher® type system, protocol versioning, authentication, and TLS via certificates. For Neo4j Clusters, Bolt provides smart client routing with load balancing and failover.

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

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

Neo4j Drivers

Neo4j provides official drivers for a number of popular programming languages. Below you can find links to their reference documentation:

Always use the latest version of the driver, as it will always work both with the previous Neo4j long-term support release and with the current and next major releases. The latest 5.x driver supports connection to any Neo4j 5 and 4.4 instance, and will also be compatible with Neo4j 6.

To demonstrate connection to and usage of Neo4j in different programming languages, an example application is created. It is a simple, one-page webapp, that uses Neo4j’s Movie demo database (movie, actor, director) as a dataset. The same front-end web page in all applications consumes three 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 model

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

The Query API

The Query API allows you to query a Neo4j server through HTTP/HTTPS.

For more information, see Documentation → Query API.

Example request

POST http://localhost:7474/db/neo4j/query/v2
Authorization: Basic bmVvNGo6dmVyeXNlY3JldA==
Content-Type: application/json
{
  "statement": "MERGE (n:Person {name: $name, age: $age}) RETURN n AS alice",
  "parameters": {
    "name": "Alice",
    "age": 42
  }
}

Example response

202: Accepted
Content-Type: application/json
{
  "data": {
    "fields": [
      "alice"
    ],
    "values": [
      {
        "elementId": "4:ff04df25-ff2b-4b55-98f8-6888297b025e:0",
        "labels": [
          "Person"
        ],
        "properties": {
          "name": "Alice",
          "age": 42
        }
      }
    ]
  },
  "bookmarks": [
    "FB:kcwQ/wTfJf8rS1WY+GiIKXsCXgmQ"
  ]
}

The HTTP API

The HTTP API allows you to query a Neo4j server through HTTP/HTTPS.

For more information, see Documentation → HTTP API.

Example request

POST http://localhost:7474/db/neo4j/tx/commit
Accept: application/json;charset=UTF-8
Content-Type: application/json
Authorization: Basic bmVvNGo6dmVyeXNlY3JldA==
{
  "statements": [
    {
      "statement": "MERGE (n:Person {name: $name, age: $age}) RETURN n",
      "parameters": {
        "name": "Alice",
        "age": 42
      }
    }
  ]
}

Example response

200: OK
Content-Type: application/json;charset=utf-8
{
  "results": [ {
    "columns": ["n"],
    "data": [ {
      "row": [ {
        "name": "Alice",
        "age": 42
      } ],
      "meta": [ {
        "id": 36,
        "elementId": "4:0ea4a108-32c5-498c-99e7-95cc67ab5f7d:36",
        "type": "node",
        "deleted": false
      } ]
    } ]
  } ],
  "errors": [],
  "lastBookmarks": [
    "FB:kcwQDqShCDLFSYyZ55XMZ6tffRuQ"
  ]
}

Learn with GraphAcademy

Learn everything you need to know to build an application on top of Neo4j with free, hands-on courses from Neo4j GraphAcademy.