Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/docs/source/reference/pyspark.sql/spark_session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ See also :class:`SparkSession`.
SparkSession.udf
SparkSession.udtf
SparkSession.version

is_remote

Spark Connect Only
------------------
Expand Down
2 changes: 2 additions & 0 deletions python/pyspark/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from pyspark.sql.readwriter import DataFrameReader, DataFrameWriter, DataFrameWriterV2
from pyspark.sql.window import Window, WindowSpec
from pyspark.sql.pandas.group_ops import PandasCogroupedOps
from pyspark.sql.utils import is_remote


__all__ = [
Expand All @@ -72,4 +73,5 @@
"DataFrameWriter",
"DataFrameWriterV2",
"PandasCogroupedOps",
"is_remote",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expose this as pyspark.sql.utils.is_remote?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just expose it under pyspark.sql because APIs are usually exposed under that namespace. I think you can use it as:

is_remote = getattr(pyspark.sql, "is_remote", getattr(pyspark.sql.utils, "is_remote", None))()

]
19 changes: 19 additions & 0 deletions python/pyspark/sql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ def is_timestamp_ntz_preferred() -> bool:
def is_remote() -> bool:
"""
Returns if the current running environment is for Spark Connect.

.. versionadded:: 4.0.0

Notes
-----
This will only return ``True`` if there is a remote session running.
Otherwise, it returns ``False``.

This API is unstable, and for developers.

Returns
-------
bool

Examples
--------
>>> from pyspark.sql import is_remote
>>> is_remote()
False
"""
return "SPARK_CONNECT_MODE_ENABLED" in os.environ

Expand Down