Skip to content

REPL

This page provides an overview of the REPL and describes how to use it for interactive q development within the kdb Visual Studio Code Extension.

REPL stands for Read-Eval-Print Loop, and is an interactive programming environment used in many languages. REPL is particularly useful for interactive development, debugging, and testing because it allows you to write and run code snippets in real-time, seeing immediate feedback.

The REPL is the primary mechanism for running and testing q code in the kdb Visual Studio Code Extension. It provides an interactive interface to execute commands directly against the KDB-X runtime.

By default, files that are not explicitly associated with a connection are executed in the REPL.

The REPL is the implicit execution environment and does not appear as a selectable connection.

To run code against a remote or active connection, you must explicitly select a connection.

Execution model

The kdb Visual Studio Code Extension uses a clear and explicit execution model:

  • No connection selected → code runs in the REPL (default)
  • Connection selected → code runs on that connection

The REPL is not listed as a connection option. Leaving a file unassociated with a connection is the intended way to run code locally and safely in the REPL.

Start the REPL

There are two ways to start a REPL, each rooted at a different base folder:

  • KX: Start REPL — run this from the Command Palette (search for >repl) to start a REPL for the whole workspace, rooted at the workspace folder.
  • KX: Start REPL Here — right-click a folder or file in the VS Code Explorer to start a REPL rooted at that folder. If you invoke it on a file, the REPL is rooted at the file's parent directory.

Rooting a REPL at a folder gives you two things: the REPL runs from that folder, so relative paths resolve there, and for KDB-X that folder's mod directory is searched first, so your project's modules load before the global ones.

REPL

Once started:

  • A terminal window opens containing the active q session, labeled with its base folder (for example, q REPL (myproj/sub)).
  • The session persists until explicitly closed.
  • Any variables, functions, or tables created remain available for future commands.

You can have multiple REPLs running at once, each rooted at a different folder. Whatever you execute runs on the active REPL — see How the extension chooses a REPL.

Project-local module resolution

Each REPL adds its base folder's mod folder to the module search path (QPATH), so the KX modules system resolves project-local modules with use`…. Starting a REPL closer to your project (with KX: Start REPL Here) is therefore useful when your modules and scripts are organized under a specific directory.

How the extension chooses a REPL

When you run a file or selection, it goes to the active REPL — the REPL you most recently started or focused (clicked into). Everything you run continues to go there until you start a new REPL or focus a different one, which then becomes the active REPL.

If there is no active REPL — for example, because you closed it — the extension falls back to the folder rule, choosing from any REPLs that are still running:

  • It uses the REPL whose base folder contains the file.
  • If no running REPL's folder contains the file, it uses the workspace REPL, starting one if none exists.

Note

Because the active REPL takes priority, a file does not necessarily run in the REPL rooted at its own folder. If you want a file to run in a folder-specific REPL, focus that REPL's terminal to make it active before running.

Execute q files

To execute a q file in the REPL:

  1. Ensure no connection is selected for the file
  2. Execute the file

The code runs in the REPL using the active local session.

The results are shown in the terminal and you can continue to work either in your q file or directly in the terminal.

Refer to the REPL shortcuts table for information on what keyboard shortcuts you can use.

To execute a q file on a connection:

  1. Click Choose Connection
  2. Select the desired connection
  3. Execute the file

Note

The connection selector only applies to explicit connections. If no connection is selected, execution defaults to the REPL. An active connection is not used unless explicitly chosen.

Benefits of using REPL

A REPL gives you a tight feedback loop, stateful context, and guardrails. You learn faster, debug quicker, and ship with fewer mistakes.

Key benefits include:

  • Rapid iteration with stateful sessions. Execute commands and receive immediate feedback while maintaining session state across operations. This enables faster development cycles with reduced boilerplate.

  • Safe and efficient troubleshooting. Experiment within transactions and roll back changes as needed. Quickly isolate and resolve issues by modifying and re-running queries in real time.

  • In-context exploration and optimization. Access schema details, autocomplete, and performance insights directly within the REPL, supporting informed tuning and discovery.

  • Streamlined workflow and reusability. Minimize context switching by staying within a single interface. Use command history as a living notebook to document, replay, or convert workflows into scripts.

  • Smooth transition to production and built-in safeguards. Validate logic in the REPL before promoting queries to production. Features like autocommit off, role switching, and environment prompts help prevent unintended changes.

Use PyKX within REPL

The kdb Visual Studio Code Extension allows you to integrate PyKX directly within the REPL environment. When KDB-X is installed through VS Code, PyKX support is automatically available within the REPL environment, enabling you to switch between q, Python and SQL contexts for data analysis, visualization, or model development.

Refer to the PyKX within REPL instructions for details on how to get started and use PyKX within REPL.

Note

The REPL automatically inherits the active Python virtual environment (venv) from the Python extension in VS Code. If you switch Python interpreters and restart the REPL, it will use the latest interpreter selected in VS Code.

Supported file types

In addition to q and Python files, SQL files are also supported for execution within REPL. Refer to the supported execution types table for more details.

Next steps