The Interactive Shell (REPL)
Test logic, inspect variables, and execute code line-by-line using the persistent Python shell.
What is the REPL?
REPL stands for Read-Eval-Print Loop. While Script Mode (clicking the Run button) executes an entire file from top to bottom, the REPL allows you to execute Python code one line at a time. It is an indispensable tool for debugging, testing API responses, or performing rapid data transformations before committing the logic to your main codebase.
To open the shell, click the + (New Tab) button in any pane group and select REPL.
The Power of Memory Persistence
The most important characteristic of the REPL is that it maintains its memory state for as long as the session is active. This fundamentally differs from how execution in Script Mode is handled.
If you execute my_data = [1, 2, 3] in the REPL, you can hit Enter, type a new command on the next line, and my_data will still exist. You can import your custom files (e.g., from src.main import calculate_tax) and test them directly in the shell without having to run the entire application.
Parallel Execution Slots
Python Online allocates resources to allow for Parallel Execution. The REPL process operates completely independently from the Script execution process.
This means you can trigger a heavy data processing job by clicking "Run", and while that script is churning in the Output console, you can immediately switch to the REPL tab to test a regular expression or inspect a variable without waiting for the main script to finish.
The Xterm.js Architecture
Unlike the Native Output Console used for scripts, the REPL interface is powered by Xterm.js—a true terminal emulator.
When you type in the REPL, the browser sends your keystrokes (character by character) over a WebSocket to a pseudo-terminal (PTY) running on the Linux server. The server then echoes the characters back to your screen. This raw connection allows you to utilize standard terminal features:
- Up/Down Arrows: Cycle through your command history.
- Tab Completion: Hitting `Tab` will auto-complete variable names, module names, etc.
- Keyboard Interrupts: Pressing
Ctrl + Cwill instantly send aSIGINTsignal to the server, safely halting any runaway loop you accidentally started in the shell.
Session Timeouts & Persistence
Because the REPL keeps variables in memory, the server must reserve RAM for your session even when you aren't typing.
- Guest & Free Tier: To prevent memory exhaustion across the cluster, Free REPL sessions are bound by the same 60-second timeout as scripts. If the shell is idle, the backend will terminate the container, clear the memory, and print a timeout message. Simply click anywhere in the REPL pane to instantly boot a fresh session.
- Pro Tier: Your REPL runs inside your persistent Workstation. Closing the browser tab unbinds the UI, but the shell and its variables remain alive in the background. You can open the tab an hour later and your `my_data` list will still be there.
Note on Updates: While Pro Scripts run completely detached and are immortal, the REPL relies on an active SSH connection held by the Main Server. If Python Online undergoes a system-wide maintenance reboot, your background REPL and Terminal sessions will be safely reset.