Skip to content

Commit 42e9b80

Browse files
SNOW-1762538 add detecting running inside a Jupyter notebook for collecting usage stats
1 parent f80d83e commit 42e9b80

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/snowflake/connector/connection.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,9 @@ def __init__(
495495
is_kwargs_empty = not kwargs
496496

497497
if "application" not in kwargs:
498-
if ENV_VAR_PARTNER in os.environ.keys():
499-
kwargs["application"] = os.environ[ENV_VAR_PARTNER]
500-
elif "streamlit" in sys.modules:
501-
kwargs["application"] = "streamlit"
498+
app = self._detect_application()
499+
if app:
500+
kwargs["application"] = app
502501

503502
if "insecure_mode" in kwargs:
504503
warn_message = "The 'insecure_mode' connection property is deprecated. Please use 'disable_ocsp_checks' instead"
@@ -2272,3 +2271,15 @@ def _check_oauth_required_parameters(self) -> None:
22722271
"errno": ER_NO_CLIENT_ID,
22732272
},
22742273
)
2274+
2275+
@staticmethod
2276+
def _detect_application() -> None | str:
2277+
if ENV_VAR_PARTNER in os.environ.keys():
2278+
return os.environ[ENV_VAR_PARTNER]
2279+
if "streamlit" in sys.modules:
2280+
return "streamlit"
2281+
if all(
2282+
(jpmod in sys.modules)
2283+
for jpmod in ("ipykernel", "jupyter_core", "jupyter_client")
2284+
):
2285+
return "jupyter_notebook"

0 commit comments

Comments
 (0)