Develop a query in VS Code (Python)

The Deephaven VS Code extension is a powerful tool for developing server-side Deephaven queries in Python or Groovy directly from Microsoft Visual Studio Code (VS Code). It provides an alternative to the Deephaven IDE for users who prefer to do their development in VS Code, or who want to do development in a local IDE rather than a browser. The Deephaven VS Code extension allows the usage of VS Code's many features and other extensions for query development such as GitHub Copilot.

Install the Deephaven VS Code Extension

The Deephaven VS Code extension can be installed from the VS Code Marketplace or from the extension browser inside of VS Code. The extension is currently pre-release, so you'll need to install it as such.

Install Deephaven VS Code Extension

Once installed, there will be a new Deephaven icon in the Activity bar (the sidebar containing navigation icons).

VS Code - Activity Bar Icon

Clicking the Deephaven icon opens a new panel containing details of configured Deephaven servers. By default, the extension is configured to connect to a single Community server hosted at http:localhost:10000. Enterprise servers can be configured via the deephaven.enterpriseServers setting in VS Code user or workspace settings. To open one of the VS Code settings.json files:

  1. Open the Command Palette by clicking cmd/ctrl + shift + p.

  2. Type settings and select Preferences: Open User Settings (JSON) or Preferences: Open Workspace Settings (JSON). Change user settings to apply to all workspaces, and workspace settings to apply to the current workspace only.

    VS Code - Command Palette Settings

  3. Add the following entry to the settings.json file (change the URL and port to that of your Deephaven installation; the default port is 8123 for a server without Envoy and 8000 for a server with Envoy):

    "deephaven.enterpriseServers": [
      "https://demo.deephaven.io:8123/",
    ]
    

Note

Some VS Code bugs cause flakiness with the run button. VS Code v90 introduced an optional workbench.editor.alwaysShowEditorActions setting. Setting this to true improves the experience. Namely, the run button will not disappear when running commands or selecting its dropdown. See https://github.com/deephaven/vscode-deephaven/issues/1 for more details.

Workspace setup

Before using the Deephaven VS Code extension, you must configure VS Code for Python usage. See Getting Started with Python in VS Code. It is recommended to configure a virtual Python environment within your VS Code workspace (see Create a virtual environment). If you have already configured a virtual environment, you can then install Deephaven pip packages in the venv.

To ensure your local environment matches your server, query the versions of packages you want to install. You can do this in a Code Studio in the Deephaven IDE using a script like the following:

import pkg_resources

# package names to check
package_names = [
    "deephaven-core",
    "deephaven-plugin-plotly-express",
    "deephaven-plugin-ui",
]

for name in package_names:
    version = pkg_resources.get_distribution(name).version
    print(f"{name}={version}")

Using this information, you can create a requirements.txt to install the same packages locally. For example, here's a minimal requirements.txt file that enables IntelliSense for common Deephaven packages:

deephaven-core=0.38.0
deephaven-plugin-plotly-express=0.12.0
deephaven-plugin-ui=0.23.1

See Workspace setup for more details, including auto-generating a requirements.txt file from the server.

Develop a Query

  1. Open a workspace in VS Code that has been configured as described in the Workspace setup section.

  2. Activate the Deephaven view by clicking the Deephaven icon in the activity bar.

    Activate Deephaven View

  3. Create a new script in the workspace named simple_ticking.py, and paste the following code into it:

    from deephaven import time_table
    
    simple_ticking = time_table("PT2S")
    
  4. Run the script by clicking the Run Deephaven File action at the top of the file:

    VS Code - Run Deephaven File

  5. Provide credentials when prompted for login.

  6. You should see a ticking table in a new panel!

    VS Code Ticking Table

  7. If you open a Query Monitor tab in the Deephaven IDE, you should see an Interactive Console query for the VS Code connection. VS Code Interactive Console Query

    The id in the Name column will match the id in the connection in VS Code. VS Code Connection ID

Make a PQ

Once you have a working query in VS Code, you can make it a Persistent Query (PQ) in the Deephaven IDE. Queries run from VS Code will only persist within the active session. Making a PQ will allow it to persist in between sessions.

To create a new PQ, in the Query Monitor tab:

  1. Click the New button.

  2. Click the Script tab in the query details panel.

  3. Change the runtime dropdown to Python.

  4. Copy / paste your query from VS Code into the code area of the Script tab:

    VS Code - Create a PQ

  5. Click the Save button.

View the PQ

After saving the new query, it appears in the Query Monitor, and its status changes to Running once the query successfully starts.

VS Code - PQ List

Once your PQ is running, you can access the simple_ticking table from the Panels menu.

VS Code - Open PQ in Code Studio