Apache Spark Connect Client for Rust (Rust core + Python wrapper)

Clone this repo:
  1. c41ff82 [SPARK-59432][CONNECT][PYTHON] Declare gil_used = false on the _pyspark module by jameswillis · 7 hours ago master
  2. a197de0 [SPARK-59302][CONNECT] Include the LICENSE file in the maturin sdist by Hyukjin Kwon · 4 days ago
  3. 6b751f1 [MINOR][DOCS] Add crates.io + docs.rs badges and a Rust API reference link to the README by Hyukjin Kwon · 4 days ago
  4. 590012d [SPARK-59136][CONNECT] Make the active Spark Connect client identifiable (pyspark-client-rust vs the reference client) by Hyukjin Kwon · 10 days ago
  5. 254dd50 [SPARK-59143] Close remaining PySpark 4.2.0 Spark Connect public-API parity gaps by Hyukjin Kwon · 10 days ago

Spark Connect Rust Client

A fast, native Rust client for Apache Spark Connect - and a drop-in pyspark replacement with 100% public-API parity with PySpark 4.2.0. It builds spark.connect protobuf plans, manages the gRPC channel, and decodes Arrow results in Rust, speaking the same protocol and returning the same results as the reference client.

PyPI Crates.io docs.rs Spark License

Rust coverage Python coverage

📖 Documentation

Full documentation lives at apache.github.io/spark-connect-rust

The Rust API reference (generated from the crate) is on docs.rs/apache-spark-connect.

Install

Python - a faster, drop-in replacement for the pyspark-client PyPI package (uninstall any existing pyspark / pyspark-client first):

pip install pyspark-client-rust

Your Spark Connect code then runs unchanged; use it exactly like PySpark.

Rust - the native crate:

[dependencies]
apache-spark-connect = "4.2"

Quickstart (Rust)

use spark_connect::{SparkSession, functions as f, lit};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let spark = SparkSession::builder()
        .remote("sc://localhost:15002")
        .get_or_create()?;

    let df = spark
        .range(1_000_000)?
        .select([(f::col("id") * lit(2)).alias("x")])
        .filter((f::col("x") % lit(3)).eq(lit(0)));

    println!("count = {}", df.count()?);
    df.show(20)?;
    Ok(())
}

See the documentation for the full API, running a Spark Connect server, and more.

User-Defined Functions (UDFs)

Write UDFs as plain Rust functions and call them directly — #[spark_wasm_udf] compiles them to WebAssembly and ships them to the executors:

#[spark_wasm_udf]
mod udfs {
    pub fn add_one(x: i64) -> i64 { x + 1 }
}

spark.range(5)?.select([udf::add_one(col("id"))?]).show(20)?;

See the WASM UDF guide for the full setup, SQL registration, supported types, and more.

Contributing

Issues are tracked in ASF JIRA under SPARK (GitHub Issues are disabled). See the contributing guide.

License

Apache License 2.0.