Skip to content

Basthon on the command line ​

The basthon command runs Basthon's kernels in a terminal, without a browser, with Node.js (version 20.15 or later). It is the same Python (or the same OCaml, C, R…) as in the console and the notebook, with the same modules. It is handy to test an activity before giving it to students, to run it in a script or to mark a set of papers.

Installation ​

bash
npm install -g @basthon/kernel-node

Usage ​

It is used like the python command:

bash
basthon program.py            # runs a file
basthon -c "print(6 * 7)"     # runs a statement
basthon                       # opens an interactive console

The arguments after the file are given to the program (sys.argv in Python). The interactive console has completion and history, and input() reads the keyboard (or the standard input). In Python, the program reads and writes the files of the computer directly, from the current directory.

The language is chosen from the extension of the file (.py, .sql, .js, .c, .ml, .r) or with the --kernel option (python3 or py, sql, javascript or js, c, ocaml, xcas, r):

bash
basthon hello.c           # calls main and returns its exit code
basthon fact.ml           # OCaml
basthon --kernel sql      # an SQL console

Graphical outputs ​

Graphical outputs (Matplotlib figures, tkinter windows, R charts, OCaml or JavaScript canvases, images, HTML…) are shown in a page of the browser, where they stay interactive. The program ends when this page is closed (or the last tkinter window, or with Ctrl+C).

With --no-browser, nothing opens: the images, SVG and HTML shown are saved in a temporary directory, or in the one given by --display-dir.

Options ​

OptionRole
-k, --kernelthe language to use
-c statementruns the statement given
-q, --quietdoes not show the version message of the interactive console
-v, --verboseshows the kernel's messages (on the error output)
--no-browserdoes not open the graphical outputs in the browser
--display-dir directorywhere to save the images, SVG and HTML shown
--no-cachedoes not use (nor create) Python's memory snapshot that speeds up its start
--jsondrives the kernel with JSON lines on the standard input and output (for another program)
-h, --helpshows the help