[Yandex Cloud documentation](../../../index.md) > [Yandex DataSphere](../../index.md) > [Step-by-step guides](../index.md) > DataSphere Jobs > Working with jobs from Visual Studio Code

# Working with jobs from Visual Studio Code

DataSphere Jobs Toolkit enables you to work with DataSphere [jobs](../../concepts/jobs/index.md) from within [Visual Studio Code](https://code.visualstudio.com/). You will need a Yandex Cloud account and a DataSphere [project](../../concepts/project.md).

DataSphere Jobs Toolkit uses [DataSphere CLI](../../concepts/jobs/cli.md) to analyze the environment and identify dependencies. The CLI is automatically installed in the current virtual environment when you run your first job.

{% note info %}

To use DataSphere Jobs Toolkit, make sure you have installed [Visual Studio Code](https://code.visualstudio.com/), [Python 3.10](https://www.python.org/downloads/release/python-3100/), and the [Python extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python).

{% endnote %}

When you run a job, the `datasphere` library analyzes the environment, collects code dependencies, and can provide them to DataSphere for deploying the environment on a cloud VM. To avoid unnecessary system dependencies that can affect job performance, we recommend using a virtual environment, such as [venv](https://docs.python.org/3/library/venv.html) or [conda](https://docs.conda.io/en/latest/#).

{% note info %}

To run DataSphere jobs, use Python [venv](https://docs.python.org/3/tutorial/venv.html). The supported Python versions are 3.8 to 3.12.

{% endnote %}

## Install DataSphere Jobs Toolkit {#setup}

1. Open the [extension page on Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=yandex-cloud.ds-toolkit-vscode).
1. Click **Install**.
1. The browser will prompt you to open Visual Studio Code. Click **Open app**.
1. On the DataSphere Jobs Toolkit page that opens in Visual Studio Code, click **Install**.

Once you go through the installation successfully, the extension page will show **This extension is enabled globally**.

## Get authenticated in DataSphere Jobs {#authentication}

To start working with DataSphere Jobs, get authenticated using a Yandex or federated account.

{% list tabs group=authentication %}

- Yandex account {#yandex-account}

  1. Get an [OAuth token](../../../iam/concepts/authorization/oauth-token.md).

     An OAuth token lives 12 months. After that, you need to [get a new one](https://oauth.yandex.com/authorize?response_type=token&client_id=1a6990aa636648e9b2ef855fa7bec2fb) and get authenticated again.

  1. In Visual Studio Code, click **Search** at the top of the window and enter this command: `> DataSphere Jobs: Set OAuth token`. In the window that opens, click **Open** to get an OAuth token.

      If you already have an OAuth token, click **Cancel**.
  1. In the **Input OAuth token** field that opens, enter your OAuth token.

  To delete the OAuth token, use this command:`> DataSphere Jobs: Remove OAuth token`.

- Federated or local account {#federated-account}

  To authenticate a federated or local account, you need to install and configure the [CLI](../../../cli/quickstart.md). If the CLI is installed in the default folder or the path to it is specified in the `Path` environment variable, the toolkit will detect it automatically. If not, specify the CLI executable path in the extension settings:

  1. In the left-hand panel, select **DataSphere Jobs** and click **Settings**.
  1. In the **Datasphere: Yandex Cloud Console Path** field, enter the path to the CLI executable, such as the following:

      ```text
      C:\Users\<username>\yandex-cloud\bin\yc.exe
      ```

{% endlist %}

## Run a job {#run-job}

1. In the left-hand panel, select ![logo](../../../_assets/datasphere/ds-logo.svg) **DataSphere Jobs** and click **Settings**.
1. In the **Datasphere: Project** field, enter the project ID. To get the project ID, click the **ID** icon on your project page in the [DataSphere interface](https://datasphere.yandex.cloud/projects).
1. Open a Python file using DataSphere Jobs Toolkit. To do this, in the Visual Studio Code Explorer, right-click the file you need and select **Run File in DataSphere Jobs**.

    You can also pre-open the file with the job code in Visual Studio Code, click **Run and Debug** in the top-right corner of the edit window, and select **Run File in DataSphere Jobs**.

    You can use [this sample code](work-with-jobs.md#example) when testing the extension. For more job run examples, see [this GitHub repository](https://github.com/yandex-cloud-examples/yc-datasphere-jobs-examples).

1. In the **DataSphere Job Configuration** window that opens, set the following configuration:

    {% list tabs %}

    - BASIC

      Configure the main run parameters that match the values in the `config.yaml` [file](work-with-jobs.md#create-job):

      * **Working directory**: Working directory containing the files required to run your job.
      * **Inputs**: Files with input data in `<path>=<variable_name>` format. Specify each value pair on a separate line.
      * **Outputs**: Files with output data in `<path>=<variable_name>` format. Specify each value pair on a separate line.

    - ADVANCED

      Configure additional settings:

      * **Project Identifier**: DataSphere project ID.
      * **Configuration file path**: Path to the completed `config.yaml` configuration file.
      * **Instance Type**: [Configuration](../../concepts/configurations.md) settings of the VM you will use to run your job.
      * **S3 mounts**: IDs of [S3 connectors](../../concepts/s3-connector.md). In case of multiple S3 connectors, specify each ID on a separate line.
      * **Datasets**: [Datasets](../../concepts/dataset.md) in `<dataset>=<variable_name>` format. Specify each value pair on a separate line.

    - ENVIRONMENT

      Configure the [Docker image](../../concepts/docker.md):

      * **Variables**: Variables required to run the code, in `<name>:<value>` format. Specify each value pair on a separate line.
      * **Docker**: Docker image settings:
          * **Image**: Docker image URL.
          * **User**: System account with either a password or name of the secret containing the [authorized key](../../../iam/concepts/authorization/key.md).

    - PYTHON

      Set up your Python working environment:

      * **Environment dependency build method**: Select whether to define environment dependencies manually or automatically.
      * **Extra root paths**: Additional root folders. Specify each value on a separate line.
      * **Extra index urls**: Additional index URLs.
      * If you choose not to define environment dependencies, enable **No Dependencies**.

    {% endlist %}

    To save your current settings to `launch.json` for use in future jobs, click **Save**. To export job configuration to `config.yaml`, click **Export**.

    You can also upload a previously saved and ready-to-use job configuration by clicking **Load**.

1. To run the configuration, click **Invoke**.

    After you successfully run the job from within DataSphere Jobs Toolkit, the **DEBUG CONSOLE** window will open. It will contain a link to the job in DataSphere:

    ```txt
    creating job ...
    uploading 37 files (129.7MB) ...
    files are uploaded
    created job `bt19qb2pb0ji********`
    executing job ...
    job link: https://datasphere.yandex.ru/communities/bt11e3m29qti********/projects/bt1eq06id8kv********/job/bt19qb2pb0ji********
    ```

    The **OUTPUT** window also features tabs with the following information:

    * **DataSphere Jobs Invocation**: User code execution results.
    * **DataSphere Jobs Toolkit**: Job start, end, or error messages.
    * **DataSphere Jobs Toolkit Logs**: Information about the extension performance.

## View the job history {#job-history}

DataSphere Jobs Toolkit allows you to view the job history and manage your jobs.

To see the job history in DataSphere Jobs, select ![logo](../../../_assets/datasphere/ds-logo.svg) **DataSphere Jobs** in the left-hand panel. In the **DATASPHERE JOBS: LAUNCH HISTORY** panel that opens, you will see the history of jobs sorted by start time.

You can perform the following actions from the DataSphere Jobs history panel:

* **Cancel**: Stop the job.
* **Attach**: Connect to the job.
* **Copy job ID**: Copy the job ID.
* **Open job**: Open the job in a browser.

#### Useful links {#see-also}

* [DataSphere Jobs](../../concepts/jobs/index.md)
* [Running jobs in DataSphere Jobs](work-with-jobs.md)