Skip to main content

sras-client

Python client for Snowflake Runtime for Apache Spark.

pip install snowflake-spark-connect

Usage

from datetime import timedelta

from snowflake.sparkconnect import SparkSession

spark = (
    SparkSession.builder.idlettl(timedelta(minutes=30))
    .sessionttl(timedelta(hours=4))
    .getOrCreate()
)

spark.sql("SELECT 1").show()
spark.stop()

getOrCreate() reuses the process session when the builder has no credentials. A later call with different credentials, TTLs, or database/schema settings raises instead of sharing another identity, including TTL-only builders such as .idlettl(...). create() starts a new Spark Connect server with a new session in the current process.

In a Snowflake Notebook, get_active_session() binds to the active Snowpark session. Pass optional named database and schema arguments to set that context before the Spark Connect server starts.

Authentication options

Use one of the following authentication options when creating a session. Pick one. .connection("prod") uses that toml profile as-is (not mixed with SNOWFLAKE_*).

Method What it does
(nothing) getOrCreate() — env, default connections.toml, or the Notebook session
.snowpark_session(session) Existing Snowpark session (Snowflake Notebook)
.connection("prod") Named profile from ~/.snowflake/connections.toml
.remote(account=..., ...) Snowflake connection parameters (see below)

Do not mix .connection("prod"), .remote(...), and .snowpark_session(...).

Session lifetime

Option Meaning
.idlettl(timedelta(...)) Stop the Spark server after this much idle time
.sessionttl(timedelta(...)) Hard cap on total session lifetime
.tokenttl(timedelta(...)) Lifetime of each Spark Connect JWT
spark_idlettl / spark_sessionttl / spark_tokenttl inside .remote(...) Same TTLs, passed as Snowflake kwargs

These apply only when the builder STARTs a server. They cannot be combined with a sc:// URL.

Database and schema

Option Meaning
.database(name) Use this Snowflake database on the control session before START
.schema(name) Use this Snowflake schema on the control session before START

Explicit .database(...) / .schema(...) values always override database/schema from a connection, configuration, or supplied/active Snowpark session. They apply only when the builder STARTs a server and cannot be combined with a sc:// URL.

The snowflake.sparkconnect.SparkSession refreshes its token in the background to automatically stay authenticated.

.remote(**kwargs) Snowflake parameters

These are the same parameters as snowpark-python.

Spark-specific kwargs:

Parameter Notes
spark_idlettl / spark_sessionttl / spark_tokenttl Same as .idlettl() / .sessionttl() / .tokenttl()

Environment variables

When the builder has no .connection() / .remote(), Snowflake SNOWFLAKE_* login vars are used (including SNOWFLAKE_HOST), then SNOWFLAKE_CONNECTION_NAME, then the default toml profile, then an active Notebook session. Blank env values are ignored.

Metadata

Release files for snowflake-spark-connect 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for snowflake-spark-connect 0.1.0
File Size Uploaded
snowflake_spark_connect-0.1.0.tar.gz 1.9 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for snowflake-spark-connect 0.1.0
File Interpreter ABI Platform
snowflake_spark_connect-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 4.4 MB

Release files / snowflake_spark_connect-0.1.0.tar.gz

Download URL snowflake_spark_connect-0.1.0.tar.gz
Size 1.9 MB
Tags Source
SHA-256 checksum
How to use checksums
a45a499b43eca5ea320e93fdc3ac1fea93740a0d44ddd21b2126257ac009f834
BLAKE2b-256 checksum
How to use checksums
072d043eb23c599754ca479d21c4fcb0edf9842cdf940b7c42ed6acc5bd0920f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / snowflake_spark_connect-0.1.0-py3-none-any.whl

Download URL snowflake_spark_connect-0.1.0-py3-none-any.whl
Size 2.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b623471ba9cede22260f12dbe02deb605889b5f1bed0a3ddc6ed5a28c9136342
BLAKE2b-256 checksum
How to use checksums
8dbfd37ab63d29ac10156ce559046ce786f69f7a456ca9e307ff88226cc299a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page