## Module 1: Prepare to Run Python Code

### Step 1. Check the Lab Environment

- Click the `Resources` button on the left to view the lab environment set up for your practice. You will see:
  - A server named monitor1, running a VS Code server that acts as both a development and application server.
  - Connection details for the TiDB Cloud Serverless cluster—which, depending on your choice, may be from your own TiDB Cloud account or the lab's sandbox environment.
  - Additionally, the database name for this hands-on lab is `${LAB:SERVERLESS_CLUSTER_DATABASE_NAME}`, which will be created on your behalf in your chosen TiDB Cloud Serverless cluster.

- Close the `Resources` pop-up window.

### Step 2. Open a Terminal in the IDE

- Open [VS Code](${LAB:HTTPS_REVERSE_PROXY_URL}?next=${LAB:"/vscode/?folder=/root/tidb-lab-unify-storage-openai"|urlencode} "VS Code") in your browser.

- Click `Yes, I trust the authors` in the pop-up window.

    ![70%](https://lab-static.pingcap.com/quick-demo/vscode-trust.jpg)

- Click the `≡` icon in the upper-left corner, select `Terminal`, and then click `New Terminal` to open a new terminal window.

    ![90%](https://public-pingcap-innovation.s3.us-west-2.amazonaws.com/demo-405/405-open-terminal-0307.jpg)

### Step 3. Install Python Dependencies

Run the following command in the VS Code terminal to install the required dependencies.

```bash
poetry install
```

```output
Creating virtualenv tidb-lab-unify-storage-wZek_onr-py3.11 in /root/.cache/pypoetry/virtualenvs
Installing dependencies from lock file

Package operations: 93 installs, 0 updates, 0 removals

- Installing attrs (25.3.0)
- Installing rpds-py (0.25.1)
- Installing typing-extensions (4.13.2)
- Installing certifi (2025.4.26)
...
```

### Step 4. Configure the OPENAI API KEY

Click the `.env` file and change the value of `OPENAI_API_KEY` to your actual API Key.

![90%](https://lab-static.pingcap.com/images/2025/7/24/c90a13ee02b5926689ad2e54e50c8d1865f85fbc.png)

> [!NOTE]
> If you don't know how to get your `OPENAI_API_KEY`, please refer to the [OpenAI official documentation](https://platform.openai.com/docs/api-reference/introduction).
