$npx -y skills add neo4j-contrib/neo4j-skills --skill neo4j-spark-skillUse when reading from or writing to Neo4j with Apache Spark or Databricks using the
| 1 | # Neo4j Connector for Apache Spark |
| 2 | |
| 3 | ## When to Use |
| 4 | |
| 5 | - Reading Neo4j nodes/relationships into Spark DataFrames |
| 6 | - Writing Spark DataFrames to Neo4j as nodes or relationships |
| 7 | - Databricks notebooks connecting to Neo4j |
| 8 | - Delta Lake → Neo4j ingestion pipelines |
| 9 | - Partitioned parallel reads from large Neo4j graphs |
| 10 | |
| 11 | ## When NOT to Use |
| 12 | |
| 13 | - **Python bolt driver / execute_query** → `neo4j-driver-python-skill` |
| 14 | - **Cypher query writing** → `neo4j-cypher-skill` |
| 15 | - **GDS graph algorithms** → `neo4j-gds-skill` |
| 16 | - **Spring Boot + Neo4j** → `neo4j-spring-data-skill` |
| 17 | |
| 18 | --- |
| 19 | |
| 20 | ## Version Matrix |
| 21 | |
| 22 | | Connector | Spark | Scala | Databricks Runtime | Neo4j | |
| 23 | |-----------|-------|-------|--------------------|-------| |
| 24 | | 5.4.x | 3.3, 3.4, 3.5 | 2.12, 2.13 | 12.2, 13.3, 14.3 LTS | 4.4, 5.x, 2025.x | |
| 25 | |
| 26 | Maven artifact (Scala 2.12, Spark 3): |
| 27 | ``` |
| 28 | org.neo4j:neo4j-connector-apache-spark_2.12:5.4.2_for_spark_3 |
| 29 | ``` |
| 30 | |
| 31 | Scala 2.13 variant: |
| 32 | ``` |
| 33 | org.neo4j:neo4j-connector-apache-spark_2.13:5.4.2_for_spark_3 |
| 34 | ``` |
| 35 | |
| 36 | --- |
| 37 | |
| 38 | ## Setup |
| 39 | |
| 40 | ### Standalone Spark (PySpark) |
| 41 | |
| 42 | ```python |
| 43 | from pyspark.sql import SparkSession |
| 44 | |
| 45 | spark = (SparkSession.builder |
| 46 | .appName("neo4j-app") |
| 47 | .config("spark.jars.packages", |
| 48 | "org.neo4j:neo4j-connector-apache-spark_2.12:5.4.2_for_spark_3") |
| 49 | .config("neo4j.url", "neo4j+s://xxxx.databases.neo4j.io") |
| 50 | .config("neo4j.authentication.type", "basic") |
| 51 | .config("neo4j.authentication.basic.username", "neo4j") |
| 52 | .config("neo4j.authentication.basic.password", "password") |
| 53 | .getOrCreate()) |
| 54 | ``` |
| 55 | |
| 56 | ### Standalone Spark (Scala) |
| 57 | |
| 58 | ```scala |
| 59 | val spark = SparkSession.builder |
| 60 | .appName("neo4j-app") |
| 61 | .config("spark.jars.packages", |
| 62 | "org.neo4j:neo4j-connector-apache-spark_2.12:5.4.2_for_spark_3") |
| 63 | .config("neo4j.url", "neo4j+s://xxxx.databases.neo4j.io") |
| 64 | .config("neo4j.authentication.type", "basic") |
| 65 | .config("neo4j.authentication.basic.username", "neo4j") |
| 66 | .config("neo4j.authentication.basic.password", "password") |
| 67 | .getOrCreate() |
| 68 | ``` |
| 69 | |
| 70 | ### Databricks — Cluster Installation |
| 71 | |
| 72 | 1. Cluster → **Libraries** → **Install New** → **Maven** |
| 73 | 2. Search: `org.neo4j:neo4j-connector-apache-spark_2.12` — match Scala version to runtime |
| 74 | 3. Cluster → **Advanced Options** → **Spark** tab — add config: |
| 75 | ``` |
| 76 | neo4j.url neo4j+s://xxxx.databases.neo4j.io |
| 77 | neo4j.authentication.type basic |
| 78 | neo4j.authentication.basic.username {{secrets/neo4j/username}} |
| 79 | neo4j.authentication.basic.password {{secrets/neo4j/password}} |
| 80 | ``` |
| 81 | 4. Use **Single user** access mode (Unity Catalog shared mode not supported) |
| 82 | |
| 83 | ### Databricks — Secrets (preferred over plaintext) |
| 84 | |
| 85 | ```python |
| 86 | # Store credentials once: |
| 87 | # databricks secrets create-scope --scope neo4j |
| 88 | # databricks secrets put --scope neo4j --key url |
| 89 | # databricks secrets put --scope neo4j --key username |
| 90 | # databricks secrets put --scope neo4j --key password |
| 91 | |
| 92 | neo4j_url = dbutils.secrets.get(scope="neo4j", key="url") |
| 93 | neo4j_user = dbutils.secrets.get(scope="neo4j", key="username") |
| 94 | neo4j_pass = dbutils.secrets.get(scope="neo4j", key="password") |
| 95 | |
| 96 | spark.conf.set("neo4j.url", neo4j_url) |
| 97 | spark.conf.set("neo4j.authentication.type", "basic") |
| 98 | spark.conf.set("neo4j.authentication.basic.username", neo4j_user) |
| 99 | spark.conf.set("neo4j.authentication.basic.password", neo4j_pass) |
| 100 | ``` |
| 101 | |
| 102 | --- |
| 103 | |
| 104 | ## Key Configuration Options |
| 105 | |
| 106 | | Option | Description | Default | |
| 107 | |--------|-------------|---------| |
| 108 | | `neo4j.url` | Bolt/Neo4j URI | — (required) | |
| 109 | | `neo4j.authentication.type` | `none`, `basic`, `kerberos`, `bearer` | `basic` | |
| 110 | | `neo4j.authentication.basic.username` | Username | driver default | |
| 111 | | `neo4j.authentication.basic.password` | Password | driver default | |
| 112 | | `neo4j.authentication.bearer.token` | Bearer token | — | |
| 113 | | `neo4j.database` | Target database | driver default | |
| 114 | | `neo4j.access.mode` | `read` or `write` | `read` | |
| 115 | | `neo4j.encryption.enabled` | TLS (ignored with `+s`/`+ssc` URI) | `false` | |
| 116 | |
| 117 | --- |
| 118 | |
| 119 | ## Reading from Neo4j |
| 120 | |
| 121 | Three mutually exclusive read modes — use exactly one per `.read()` call. |
| 122 | |
| 123 | ### Label scan (nodes) |
| 124 | |
| 125 | ```python |
| 126 | # PySpark |
| 127 | df = (spark.read.format("org.neo4j.spark.DataSource") |
| 128 | .option("labels", ":Person") |
| 129 | .load()) |
| 130 | df.printSchema() |
| 131 | df.show() |
| 132 | ``` |
| 133 | |
| 134 | ```scala |
| 135 | // Scala |
| 136 | val df = spark.read |
| 137 | .format("org.neo4j.spark.DataSource") |
| 138 | .option("labels", ":Person") |
| 139 | .load() |
| 140 | ``` |
| 141 | |
| 142 | Mul |