Connecting to Yandex Disk
Written by
Updated at August 29, 2023
You can connect to the Yandex Disk
Getting started
Open the DataSphere project:
-
Select the relevant project in your community or on the DataSphere homepage
in the Recent projects tab. - Click Open project in JupyterLab and wait for the loading to complete.
- Open the notebook tab.
Uploading the contents from a file on Yandex Disk to a DataSphere project file
-
Go to a new cell and copy the command to import the contents from a file on Yandex Disk to it:
# %pip install requests urllib if needed import requests from urllib.parse import urlencode base_url = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?' public_key = '<Yandex_Disk_file_link>' final_url = base_url + urlencode(dict(public_key=public_key)) response = requests.get(final_url) download_url = response.json()['href'] response = requests.get(download_url) dist_path = '<DataSphere_project_file_path>' with open(dist_path, 'wb') as f: f.write(response.content)
Where:
<Yandex_Disk_file_link>
: Link to the file on Yandex Disk whose contents need to be imported to DataSphere. To get the link, right-click the file and select Share ⟶ Copy link.<DataSphere_project_file_path>
: Path to the DataSphere project file to import data to. To get the path, right-click the file and select Copy path.
-
Run the cell. To do this, choose Run → Run Selected Cells or press Shift + Enter.
Uploading the contents from a folder on Yandex Disk to a DataSphere project folder
-
Go to a new cell and copy the command to import the contents from a folder on Yandex Disk to it:
# %pip install requests urllib if needed import requests from urllib.parse import urlencode from io import BytesIO from zipfile import ZipFile base_url = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?' public_key = '<Yandex_Disk_folder_link>' final_url = base_url + urlencode(dict(public_key=public_key)) response = requests.get(final_url) download_url = response.json()['href'] response = requests.get(download_url) dist_path = '<DataSphere_project_folder_path>' zipfile = ZipFile(BytesIO(response.content)) zipfile.extractall(path=dist_path)
Where:
<Yandex_Disk_folder_link>
: Link to the folder on Yandex Disk whose contents need to be imported to DataSphere. To get the link, right-click the folder and select Share ⟶ Copy link.<DataSphere_project_folder_path>
: Path to the DataSphere project folder to import data to. To get the path, right-click the folder and select Copy path.
-
Run the cell.