Dataproc client library for Spark Connect
Actively maintained. Last release 8 months ago, commits in 8 of the last 26 weeks. A safe choice.
pip install dataproc-spark-connectDataproc Spark Connect Client
A wrapper of the Apache Spark Connect client with additional functionalities that allow applications to communicate with a remote Dataproc Spark Session using the Spark Connect protocol without requiring additional steps.
Install
pip install dataproc_spark_connect
Uninstall
pip uninstall dataproc_spark_connect
Setup
This client requires permissions to manage Dataproc Sessions and Session Templates.
If you are running the client outside of Google Cloud, you need to provide
authentication credentials. Set the GOOGLE_APPLICATION_CREDENTIALS environment
variable to point to
your Application Credentials
file.
You can specify the project and region either via environment variables or directly in your code using the builder API:
- Environment variables:
GOOGLE_CLOUD_PROJECTandGOOGLE_CLOUD_REGION - Builder API:
.projectId()and.location()methods (recommended)
Usage
-
Install the latest version of Dataproc Spark Connect:
pip install -U dataproc-spark-connect -
Add the required imports into your PySpark application or notebook and start a Spark session using the fluent API:
from google.cloud.dataproc_spark_connect import DataprocSparkSession spark = DataprocSparkSession.builder.getOrCreate() -
You can configure Spark properties using the
.config()method:from google.cloud.dataproc_spark_connect import DataprocSparkSession spark = DataprocSparkSession.builder.config('spark.executor.memory', '4g').config('spark.executor.cores', '2').getOrCreate() -
For advanced configuration, you can use the
Sessionclass to customize settings like subnetwork or other environment configurations:from google.cloud.dataproc_spark_connect import DataprocSparkSession from google.cloud.dataproc_v1 import Session session_config = Session() session_config.environment_config.execution_config.subnetwork_uri = '<subnet>' session_config.runtime_config.version = '3.0' spark = DataprocSparkSession.builder.projectId('my-project').location('us-central1').dataprocSessionConfig(session_config).getOrCreate()