Command-line launcher for GraalPy, Oracle's high-performance Python implementation built on GraalVM.
npx @tessl/cli install tessl/maven-org-graalvm-python--python-launcher@24.2.0GraalPy Python Launcher is a command-line executable that provides a Python-compatible interface for running Python applications on GraalVM. It serves as the entry point for GraalPy, Oracle's high-performance Python implementation built on the JVM, offering seamless Java integration, JIT compilation, and native image capabilities.
<dependency><groupId>org.graalvm.python</groupId><artifactId>python-launcher</artifactId><version>24.2.1</version></dependency>implementation 'org.graalvm.python:python-launcher:24.2.1'graalpy executableNote: This artifact provides the command-line launcher. For embedding GraalPy in Java applications, use the separate org.graalvm.python:python-embedding artifact.
The launcher is designed to be invoked as an executable rather than used as a library. It provides a Python-compatible command-line interface:
# Basic script execution
graalpy script.py
# Interactive REPL
graalpy
# Execute code string
graalpy -c "print('Hello, World!')"
# Run module as script
graalpy -m module_name# Execute a Python script
graalpy my_script.py arg1 arg2
# Start interactive Python shell
graalpy -i
# Execute Python code directly
graalpy -c "import sys; print(sys.version)"
# Run a module with arguments
graalpy -m http.server 8080
# Verbose mode with environment ignore
graalpy -v -E script.pyThe launcher provides Python-compatible command-line execution with standard Python options and behavior.
public final class GraalPythonMain extends AbstractLanguageLauncher {
/**
* Creates a new GraalPythonMain launcher instance
*/
public GraalPythonMain();
/**
* Main entry point for the GraalPy launcher
* @param args Command line arguments (Python-compatible options and script/module)
*/
public static void main(String[] args);
/**
* Preprocesses command line arguments before context creation
* @param givenArgs Raw command line arguments
* @param polyglotOptions Options map to populate
* @return Processed arguments list
*/
protected List<String> preprocessArguments(List<String> givenArgs, Map<String, String> polyglotOptions);
/**
* Validates arguments and options before execution
* @param polyglotOptions Options map to validate
*/
protected void validateArguments(Map<String, String> polyglotOptions);
/**
* Launches the Python context with the given configuration
* @param contextBuilder Configured context builder
*/
protected void launch(Context.Builder contextBuilder);
/**
* Returns the language identifier for GraalPy
* @return "python"
*/
protected String getLanguageId();
/**
* Returns default languages supported by this launcher
* @return Array containing "python", "llvm", "regex"
*/
protected String[] getDefaultLanguages();
/**
* Prints help message for command line options
* @param maxCategory Maximum option category to display
*/
protected void printHelp(OptionCategory maxCategory);
/**
* Collects available command line options
* @param options Set to populate with option names
*/
protected void collectArguments(Set<String> options);
}File Execution:
graalpy script.py - Execute Python script filegraalpy script.py arg1 arg2 - Execute with command-line argumentsCode String Execution:
graalpy -c "code" - Execute Python code stringgraalpy -c "import os; print(os.getcwd())" - Execute with importsModule Execution:
graalpy -m module - Run library module as scriptgraalpy -m http.server 8080 - Run built-in HTTP servergraalpy -m pip install package - Run pip for package managementREPL (Read-Eval-Print Loop):
graalpy - Start interactive Python shellgraalpy -i - Force interactive modegraalpy -i script.py - Interactive after script executionConsole Features:
>>> and ...)Python Compatibility Options:
-c cmd - Program passed as string-m mod - Run library module as script-i - Inspect interactively after running script-v - Verbose (trace import statements)-q - Quiet (don't print version messages)-E - Ignore PYTHON* environment variables-B - Don't write .pyc files-S - Don't imply 'import site' on initialization-u - Unbuffered binary stdout and stderr-I - Isolated mode (implies -E, -P, -s)-P - Don't prepend potentially unsafe path to sys.path-s - Don't add user site directory to sys.path-V / --version - Print version and exit-h / --help - Print help message-W arg - Warning control-X opt - Implementation-specific optionsEnvironment Variable Support:
PYTHONPATH - Module search pathPYTHONHOME - Python installation directoryPYTHONIOENCODING - Encoding for stdin/stdout/stderrPYTHONHASHSEED - Hash randomization seedPYTHONPYCACHEPREFIX - Cache directory prefixPYTHONINSPECT - Force interactive mode after script executionPYTHONNOUSERSITE - Don't add user site directory to sys.pathPYTHONSAFEPATH - Don't prepend potentially unsafe path to sys.pathPYTHONVERBOSE - Verbose mode (trace import statements)PYTHONUNBUFFERED - Unbuffered binary stdout and stderrPYTHONDONTWRITEBYTECODE - Don't write .pyc filesPYTHONINTMAXSTRDIGITS - Maximum number of digits in string conversionsPYTHONWARNINGS - Warning filter configurationPYTHONSTARTUP - File executed on interactive startupPYTHONCASEOK - Ignore case in import statements (Windows)GRAAL_PYTHON_ARGS - Additional launcher argumentsGRAAL_PYTHONHOME - GraalPy-specific Python home directoryVERBOSE_GRAALVM_LAUNCHERS - Enable launcher debugging outputProvides console input/output handling for interactive and non-interactive execution modes.
/**
* Abstract base class for console input/output handling
*/
abstract class ConsoleHandler {
/**
* Reads a line of input with optional prompting
* @return Input line as string
*/
public final String readLine();
/**
* Reads a line of input with prompt control
* @param prompt Whether to display prompt
* @return Input line as string
*/
public abstract String readLine(boolean prompt);
/**
* Sets the prompt string for interactive input
* @param prompt Prompt string to display
*/
public abstract void setPrompt(String prompt);
/**
* Sets the polyglot context for the console
* @param context Polyglot context instance
*/
public void setContext(Context context);
/**
* Sets up readline functionality with history and completion
* @param shouldRecord Function determining if input should be recorded
* @param getSize Function returning history size
* @param addItem Consumer for adding history items
* @param getItem Function for retrieving history items by index
* @param setItem BiConsumer for setting history items
* @param removeItem Consumer for removing history items
* @param clear Runnable for clearing history
* @param completer Function providing tab completion
*/
public void setupReader(BooleanSupplier shouldRecord, IntSupplier getSize,
Consumer<String> addItem, IntFunction<String> getItem,
BiConsumer<Integer, String> setItem, IntConsumer removeItem,
Runnable clear, Function<String, List<String>> completer);
/**
* Creates an input stream for console reading
* @return InputStream for console input
*/
public InputStream createInputStream();
/**
* Gets terminal width in characters
* @return Terminal width (default: 80)
*/
public int getTerminalWidth();
/**
* Gets terminal height in characters
* @return Terminal height (default: 25)
*/
public int getTerminalHeight();
}
/**
* JLine-based console handler with advanced terminal features
* Provides history, tab completion, and line editing
*/
class JLineConsoleHandler extends ConsoleHandler {
/**
* Creates JLine console handler
* @param inStream Input stream
* @param outStream Output stream
* @param noPrompt Whether to suppress prompts
*/
public JLineConsoleHandler(InputStream inStream, OutputStream outStream, boolean noPrompt);
}
/**
* Basic console handler for non-interactive environments
* Simple BufferedReader-based implementation
*/
class DefaultConsoleHandler extends ConsoleHandler {
/**
* Creates default console handler
* @param in Input stream
*/
public DefaultConsoleHandler(InputStream in);
}Polyglot Context:
Performance Features:
Virtual Environment Support:
pyvenv.cfg configuration filesThe python-launcher is typically distributed as part of:
python or graalpy executableThe launcher handles various error conditions:
# Basic script execution
graalpy hello.py
# Script with arguments
graalpy process_data.py input.csv output.csv --format json
# Interactive exploration
graalpy -i -c "import numpy as np; data = np.array([1,2,3])"
# Module execution
graalpy -m json.tool input.json
# Performance benchmarking
graalpy -X warn_default_encoding benchmark.py
# Virtual environment usage
graalpy -m venv myenv
source myenv/bin/activate # or myenv\Scripts\activate on Windows
graalpy -m pip install requests
graalpy app.py/**
* Required imports for using GraalPythonMain
*/
import com.oracle.graal.python.shell.GraalPythonMain;
import com.oracle.graal.python.shell.ConsoleHandler;
import com.oracle.graal.python.shell.JLineConsoleHandler;
import com.oracle.graal.python.shell.DefaultConsoleHandler;
/**
* GraalVM/Polyglot API imports (from org.graalvm.polyglot)
*/
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Context.Builder;
import org.graalvm.options.OptionCategory;
/**
* Standard Java imports used in API
*/
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.*;