Skip to content

Commit 276618a

Browse files
committed
Add new client to retrieve exportable .ipynb of current session.
http://b/171318603
1 parent cdea271 commit 276618a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.c
488488
ENV PYTHONUSERBASE "/root/.local"
489489
ADD patches/kaggle_gcp.py /root/.local/lib/python3.7/site-packages/kaggle_gcp.py
490490
ADD patches/kaggle_secrets.py /root/.local/lib/python3.7/site-packages/kaggle_secrets.py
491+
ADD patches/kaggle_session.py /root/.local/lib/python3.7/site-packages/kaggle_session.py
491492
ADD patches/kaggle_web_client.py /root/.local/lib/python3.7/site-packages/kaggle_web_client.py
492493
ADD patches/kaggle_datasets.py /root/.local/lib/python3.7/site-packages/kaggle_datasets.py
493494
ADD patches/log.py /root/.local/lib/python3.7/site-packages/log.py

patches/kaggle_session.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
This library adds support for retrieving data related to the current user session.
3+
"""
4+
5+
import os
6+
7+
from kaggle_web_client import KaggleWebClient
8+
9+
10+
class UserSessionClient():
11+
GET_SOURCE_ENDPOINT = '/requests/GetKernelRunSourceForCaipRequest'
12+
13+
def __init__(self):
14+
self.web_client = KaggleWebClient()
15+
16+
def get_exportable_ipynb(self):
17+
"""Fetch the .ipynb source of the current notebook session.
18+
19+
If Kaggle datasets are attached to the notebook, the source will
20+
include an additonnal cell with logic to download the datasets
21+
outside the Kaggle platform.
22+
"""
23+
request_body = {
24+
'UseDraft': True,
25+
}
26+
return self.web_client.make_post_request(request_body, self.GET_SOURCE_ENDPOINT)

0 commit comments

Comments
 (0)