Develop with a local IDE¶
You can run Spark workloads interactively from Jupyter Notebooks, VS Code, IntelliJ, or any Python/Java/Scala interface without needing to manage a Spark cluster. The workloads run on the Snowflake infrastructure.
To connect, install the snowpark-connect Python package, which is required for all languages
(Python, Java, and Scala). For Java and Scala projects, also add the snowpark-connect-java-client
Maven dependency. For establishing a connection, use a TOML connection file. This approach handles
server lifecycle, authentication, and session management automatically.
You can run your workload interactively (for example, from a notebook, an IDE, or the PySpark shell),
or you can run a packaged Java or Scala application JAR directly with the
snowpark-connect-execute-jar command-line tool. For more information, see
Running Java or Scala workloads.
Prerequisites¶
- You have a Snowflake account with access to Snowpark Connect for Spark.
- Python 3.10 or later (earlier than 3.13) is installed. Confirm your version by running
python3 --version. - Ensure that your Java and Python installations use the same CPU architecture. For example, if Python is arm64, install an arm64 build of Java (not x86_64).
Connection configuration¶
Snowpark Connect for Spark connects to Snowflake using a TOML connection file. You can create this file manually or by using Snowflake CLI.
If you have Snowflake CLI installed, you can use it to define a connection. Otherwise, you can manually write connection parameters in a config.toml file.
Add a connection by using Snowflake CLI¶
You can use Snowflake CLI to add connection properties that Snowpark Connect for Spark uses to connect to Snowflake. Your changes are saved to a
config.toml file.
-
Run the following command to add a connection:
-
Follow the prompts to define a connection.
Specify
spark-connectas the connection name.This command adds a connection to your
config.tomlfile: -
Confirm the connection works:
Add a connection manually¶
You can write or update a connections.toml file so that your code can connect to Snowpark Connect for Spark on Snowflake.
-
Ensure that the file permissions allow only the owner to read and write:
-
Edit the file to contain a
[spark-connect]connection with your specifics:
Install Snowpark Connect for Spark¶
Note
The Snowpark Connect for Spark package runs a local gRPC server process that connects to Snowflake using a single session. Each developer or isolated workload should use its own server process.
Create a Python virtual environment and install the Snowpark Connect for Spark package:
Note
The Snowpark Connect for Spark package includes a vendored copy of PySpark. However, the vendored copy doesn’t support IDE features like IntelliSense and requires that you import Snowpark Connect for Spark before any PySpark imports in your code. To avoid these limitations, install PySpark 3.5.6 as shown above.
The Java/Scala client library manages the Snowpark Connect for Spark Python gRPC server as a child process. You
need both the library and a Python virtual environment with snowpark-connect installed.
-
Create a Python virtual environment:
-
Add the following dependencies to your
pom.xml:The library is available on Maven Central: snowpark-connect-java-client_2.12, snowpark-connect-java-client_2.13.
-
On Java 9+, add the required
--add-opensJVM arguments for Apache Arrow compatibility. See JVM module system arguments for the full list and how to configure them in Maven, IntelliJ, or on the command line. -
Point the library to the venv using one of these methods (in order of precedence):
- Code API:
.pythonVenv("/path/to/scos-venv")on the session builder - Environment variable:
SNOWPARK_CONNECT_PYTHON_VENV=/path/to/scos-venv
If neither is set, the library falls back to system
python3(orpythonon Windows) and checks whethersnowpark-connectis importable. - Code API:
The Java/Scala client library manages the Snowpark Connect for Spark Python gRPC server as a child process. You
need both the library and a Python virtual environment with snowpark-connect installed.
-
Create a Python virtual environment:
-
Add the following dependencies to your
build.sbt:The library is available on Maven Central: snowpark-connect-java-client_2.12, snowpark-connect-java-client_2.13.
-
On Java 9+, add the required
--add-opensJVM arguments for Apache Arrow compatibility. See JVM module system arguments for the full list and how to configure them in sbt, IntelliJ, or on the command line. -
Point the library to the venv using one of these methods (in order of precedence):
- Code API:
.pythonVenv("/path/to/scos-venv")on the session builder - Environment variable:
SNOWPARK_CONNECT_PYTHON_VENV=/path/to/scos-venv
If neither is set, the library falls back to system
python3(orpythonon Windows) and checks whethersnowpark-connectis importable. - Code API:
Start a session and run code¶
Once you have Snowpark Connect for Spark installed and an authenticated connection in place, start a session and run Spark code.
Start the Snowpark Connect for Spark server and create a session:
Then run Spark DataFrame code:
Compile and run:
UDF support
When using user-defined functions or custom code with Java, do one of the following:
-
Register a class finder to monitor and upload class files.
-
Upload JAR dependencies. You can include the workload JAR itself if a class finder isn’t used.
-
Use a staged JAR.
Using Scala 2.13
By default, Snowpark Connect for Spark uses Scala 2.12. If your dependencies are built with Scala 2.13, you
must specify the Scala version using the snowpark.connect.scala.version configuration option.
Compile and run:
UDF support
When using user-defined functions or custom code with Scala, do one of the following:
-
Register a class finder to monitor and upload class files.
-
Upload JAR dependencies. You can include the workload JAR itself if a class finder isn’t used.
-
Use a staged JAR.
Using Scala 2.13
By default, Snowpark Connect for Spark uses Scala 2.12. Workloads built with Scala 2.13 must specify the Scala
version using the snowpark.connect.scala.version configuration option.
Running Java or Scala workloads¶
For Java and Scala workloads, Snowpark Connect for Spark provides two approaches. Choose the one that matches how you build and run your application.
snowpark-connect-java-client library: Use this approach for interactive development, when you
build and run your application from source in an IDE, Jupyter notebook, or REPL. You add the client
as a Maven or sbt dependency so that it becomes part of your build. The library starts and manages a
local Snowpark Connect for Spark server for you and ties the server’s lifecycle to your application’s JVM process,
so your session connects to Snowflake without additional setup while you develop. For the API
reference and examples, see Snowpark Connect for Spark Java/Scala client reference.
snowpark-connect-execute-jar CLI: Use this approach to run an application that’s already
packaged as a JAR, without modifying or rebuilding it. The command-line tool runs your existing JAR
against Snowflake, managing the local server and the connection for you and shutting everything down
when the application exits. Because it requires no code changes, it’s a good fit for running built
artifacts, scheduled batch jobs, or applications that you can’t or don’t want to recompile. For
prerequisites, command options, and examples, see
Snowpark Connect for Spark execute-jar CLI reference.
Common installation issues¶
Use the following checks to resolve common Snowpark Connect for Spark installation issues.
-
Ensure that Java and Python are based on the same architecture.
-
Use the most recent Snowpark Connect for Spark package, as described in Install Snowpark Connect for Spark.
-
Confirm that the
pythoncommand with PySpark code is working correctly for local execution without Snowflake connectivity.For example, execute a command such as the following: