Skip to content

Commit 77c8990

Browse files
SNOW-1762538 add detecting running inside a Jupyter notebook for collecting usage stats
1 parent 8350f8b commit 77c8990

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
@@ -499,10 +499,9 @@ def __init__(
499499
is_kwargs_empty = not kwargs
500500

501501
if "application" not in kwargs:
502-
if ENV_VAR_PARTNER in os.environ.keys():
503-
kwargs["application"] = os.environ[ENV_VAR_PARTNER]
504-
elif "streamlit" in sys.modules:
505-
kwargs["application"] = "streamlit"
502+
app = self._detect_application()
503+
if app:
504+
kwargs["application"] = app
506505

507506
if "insecure_mode" in kwargs:
508507
warn_message = "The 'insecure_mode' connection property is deprecated. Please use 'disable_ocsp_checks' instead"
@@ -2283,3 +2282,15 @@ def _check_oauth_parameters(self) -> None:
22832282
"errno": ER_INVALID_VALUE,
22842283
},
22852284
)
2285+
2286+
@staticmethod
2287+
def _detect_application() -> None | str:
2288+
if ENV_VAR_PARTNER in os.environ.keys():
2289+
return os.environ[ENV_VAR_PARTNER]
2290+
if "streamlit" in sys.modules:
2291+
return "streamlit"
2292+
if all(
2293+
(jpmod in sys.modules)
2294+
for jpmod in ("ipykernel", "jupyter_core", "jupyter_client")
2295+
):
2296+
return "jupyter_notebook"

0 commit comments

Comments
 (0)