Running sample code in a notebook
The notebook provides small code examples for loading data from different sources.
Before you start
If a project is already open, open the tab with a notebook.
If not, open the project:
-
In the management console, open the DataSphere section in the folder where you work with DataSphere projects.
- Go to the Projects tab.
- Select the project you want to open and click .
- Choose Open and wait for the project to open.
Run the sample code
To run the sample code:
- In the top panel in the project window, click Kernel.
- In the menu that opens, click Yandex Disk.
- In the menu that opens, click the example you want to run.
- The example code will be inserted into the notebook cell.
- Follow the steps in the example.
- Run the cell. To do this, click .
Code examples for loading data from different sources
To run the code examples, you will need the app ID and secret.
To get them:
- Follow the link:
https://oauth.yandex.ru/client/new
. - Fill in the field Application name.
- In Platforms, choose Web service.
- In the Callback URI #1 field, enter
https://oauth.yandex.ru/verification_code
. - In Accesses, mark access for Yandex.Disk.
Uploading the contents of a remote file to a local file
from cloud_ml.storage.api import Storage
disk = Storage.ya_disk(application_id='ID', application_secret='secret')
disk.get('path/to/file/within/ya/disk/file.txt', 'path/to/file.txt')
Uploading the contents of a remote directory to a local file
from cloud_ml.storage.api import Storage
disk = Storage.ya_disk(application_id='ID', application_secret='secret')
disk.get_dir('path/to/dir/within/ya/disk', 'path/to/dir')
Uploading the contents of a local file to a remote file
from cloud_ml.storage.api import Storage
disk = Storage.ya_disk(application_id='ID', application_secret='secret')
disk.put('path/to/file.txt', 'path/to/file/within/ya/disk/file.txt')
Uploading the contents of a local directory to a remote directory
from cloud_ml.storage.api import Storage
disk = Storage.ya_disk(application_id='ID', application_secret='secret')
disk.put_dir('path/to/dir', 'path/to/dir/within/ya/disk')