VSCode Python

Settings
Extension
Open port
IA Agent
Tips for vscode-python service
Author

Ludovic Deneuville

Visual Studio Code (VS Code) is a high-performance, lightweight editor that serves as the industry standard for modern development. By bridging the gap between a simple text editor and a full IDE, it offers a versatile environment capable of handling everything from Python scripting to complex web development.

The power of VS Code lies in its intelligent ecosystem. Features like IntelliSense provide context-aware code completion, while its vast extension marketplace allows you to customize your workspace with specialized tools, linters, and AI assistants. With an integrated terminal and built-in debugging, VS Code keeps your entire workflow—from writing to execution—within a single, seamless interface.

Caution

Note that on the Datalab, we utilize code-server, a web-based version of VS Code that runs in your browser and differs slightly from the standard desktop application.

1 Settings

Tip

Visual Studio Code allows you to define settings at different levels: user, workspace, and folder.

Workspace settings apply only to the current project. They are stored in the .vscode/settings.json file inside your project folder.

This is useful for ensuring consistency across a team, as everyone working on the project shares the same configuration (e.g., Python interpreter, formatting rules, or linting options).

Below an example of workspace settings:

settings.json
{
  // --- UI & Visual Appearance ---
  "workbench.colorTheme": "Dark Modern",   // Sets the overall editor theme
  "editor.fontSize": 16,                   // Increases font size for better readability

  // --- Python-Specific Configuration ---
  "[python]": {
    "editor.formatOnSave": true,             // Automatically formats the file on save
    "editor.codeActionsOnSave": {            // Automated tasks performed on every save
      "source.fixAll": "explicit",           // Automatically fixes linting errors
      "source.organizeImports": "explicit",  // Sorts and cleans up import statements
      "source.addMissingImports": "explicit" // Automatically adds missing imports
    },
    "editor.insertSpaces": true,             // Uses spaces instead of tabs for indentation
    "editor.tabSize": 4,                     // Sets indentation width to 4 spaces
    "editor.defaultFormatter": "charliermarsh.ruff", // Uses Ruff as the primary formatting engine
  },

  // Hides files and folders from the Explorer
  "files.exclude": {
    "**/__pycache__": true,
    "**/.pytest_cache": true,
    "**/.ruff_cache": true,
    "**/.mypy_cache": true
  },

  "terminal.integrated.defaultProfile.linux": "bash" // Sets Bash as the default terminal
}

You can define a rule at the global level and then specify it:

{  
  "editor.tabSize": 2,           // Global default
  "[python]": {
    "editor.tabSize": 4          // Python-specific override (files *.py)
  },
  "[yaml]": {
    "editor.wrappingIndent": "indent"
  }
}

How it works:

  • Default: Any file ➡️ 2
  • Python: .py file ➡️ 4 (specific value for python)
  • YAML: .yaml file ➡️ 2 (no specific value provided, global value used)

2 Extensions

A standard code editor only knows how to write plain text. An extension adds specific “intelligence” to the editor. For example:

  • a Language Extension teaches the editor how to “read” Python (coloring the text, suggesting commands)
  • a Formatter Extension teaches the editor how to “clean up” your code (fixing indentation)
  • a Theme Extension changes the “skin” of the editor (colors, icons)

3 Open Folder

Important

The Open Folder option allows you to define the root directory of your project.

To identify the current root folder, look at the top-left corner of the Explorer panel, where the parent folder is displayed.

This choice is important because Python imports between modules rely on relative paths, which depend on the project’s root structure.

Two ways to open folder:

  • In the top-left corner, click on the three horizontal bars ➡️
    • File
    • Open Folder
    • /home/onyxia/work/<repo_name>
    • OK
  • In a terminal: code-server /home/onyxia/work/<repo_name>
    • Close previous tab

4 Open a port

Note

Services on the Datalab are launched within an isolated environment without direct internet access. Consequently, any server deployed will not be externally accessible by default.

However, external access can be enabled by opening specific ports through configuration parameters during service startup.

Once these ports are successfully opened, you can deploy various applications—such as APIs or web sites—which will then be accessible to all authorized users.

4.1 Example

Let’s try it

Important

Once the service has started, it is no longer possible to open new ports.

If you forgot to open the port, you’ll have to start a new one.

As the service starts up, you’ll notice this sentence :

You can connect to your custom ports using the following links: Port 5000. If you access these URL without starting the corresponding services you will get a 502 bad gateway error.

You will get a Bad Gateway error. That’s normal because you haven’t deployed anything on it yet.

main.py
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "hello"}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=5000)

🎉 This API is now available worldwide via the given url.

Note

If you run your API on another port uvicorn.run(app, host="0.0.0.0", port=9876):

  • This port is not open to the outside
  • You will never be able to call your API from outside the service

From the inside call it running in a new terminal: curl -X GET http://0.0.0.0:9876 | jq ..

5 IA Agent

Note

Integrating an AI generator directly into your IDE provides a level of utility that a standard chatbot cannot match. Unlike a chatbot, which requires the manual effort of copying and pasting code, an integrated AI possesses full environmental awareness.

It can navigate your entire project structure, analyze your file tree, and read across multiple files to understand complex dependencies. Furthermore, by having access to your terminal, it can interpret error logs and execution outputs in real-time.

This deep context allows the AI to provide highly accurate, project-specific solutions that are perfectly aligned with your existing codebase and environment.

5.1 Setup

To send messages to the AI, you’ll need to call an API. The first step is to retrieve the key so you can use it.

Now you will enter the key into the SSPCloud

    • Default model: gemma4-26b-moe
    • Provider: openai
    • ModelProvider: openai-chat
    • EmbeddingsProvider: openai
    • API base URL: https://llm.lab.sspcloud.fr/api/v1
    • Paste your API key

Now it’s time to launch a service.

5.2 Use it

    • In tab User preferences, check that AI Assistant is enabled

To chat with the agent, you will use extension called Continue.

    • Hover your mouse over an icon to see its name
    • for example : https://github.com/ludo2ne/ENSAI-2A-projet-info-template.git

🎉 Now you can ask the agent questions related to your project

🚧 pre-prompt

6 Autocompletion

code-server (VSCode version used by datalabs) does not support Pylance, which normally provides autocompletion. 2 options for adding autocompletion:

6.1 Option 1

    • python -m venv venv
    • Python: Select interpreter
    • choose venv

When you install Python packages globally, everything gets mixed together.

If one project needs Django 3.2 and another needs Django 5.0, they’ll conflict.

Over time, your global Python also gets messy, with packages you don’t remember installing, and sharing your project becomes painful ➡️ the classic “it works on my machine” problem.

A venv solves this by creating a self-contained environment just for your project.

  • create: python -m venv venv
  • activate: source venv/bin/activate

Inside this bubble, you can install any packages you want in any version you want, completely isolated from other projects.

  • save dependencies for sharing: pip freeze > requirements.txt
  • exit the venv: deactivate

To recreate the environment elsewhere:

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

6.2 Option 2

To remove warnings:

pyrightconfig.json
{
  "typeCheckingMode": "off",
  "reportMissingParameterType": "none",
  "reportImplicitRelativeImport": "none"
}
.vscode/settings.json
{
  "basedpyright.analysis.inlayHints.callArgumentNames": false,
  "basedpyright.analysis.inlayHints.variableTypes": false,
  "basedpyright.analysis.inlayHints.functionReturnTypes": false
}