A cross-platform PTY/ConPTY terminal for Jupyter with bundled xterm.js
Project description
Notebook Terminal
Notebook Terminal embeds a real PTY/ConPTY terminal in Jupyter notebooks and provides reusable terminal sessions for Flask and Django.
Version 0.4.0 removes the anywidget dependency. The notebook frontend uses bundled xterm.js plus standard ipywidgets channels, so it requires no JupyterLab extension, administrator installation, HTTP server, iframe, WebSocket, CDN, or internet connection.
Requirements
- Python 3.9+
ipywidgets8+- Windows:
pywinpty - Linux/macOS: the standard POSIX PTY implementation
- A trusted notebook that permits JavaScript output
Installation
python -m pip install notebook-terminal
For an offline installation, download the wheel and its dependencies on another computer and install them with --no-index --find-links.
Jupyter quick start
from notebook_terminal import terminal
term = terminal(height=450, interactive=True)
The initial banner, prompt, username, host name, and working directory are generated by the real shell process. Nothing such as PS C:\\Users\\Admin> is hardcoded.
term.run("python --version")
term.run("git status")
Read-only mode:
term = terminal(interactive=False)
term.run("python script.py")
Python execution and rich output
term.run_python("""
import pandas as pd
import matplotlib.pyplot as plt
frame = pd.DataFrame({"x": [1, 2, 3], "y": [3, 1, 4]})
display(frame)
plt.plot(frame["x"], frame["y"])
plt.show()
""", rich_output=True, clear_previous=True)
Rich output tabs support DataFrames, images, HTML, Plotly, and standard Jupyter widgets created with run_kernel().
Status output
term.success("Code completed successfully")
term.info("Starting")
term.warning("Check configuration")
term.error("Operation failed")
These messages are emitted to the display output channel and are never sent to PowerShell/Bash stdin.
History and process control
term.history()
term.last_command
term.rerun()
term.clear_history()
term.interrupt()
term.restart()
term.wait_for("ready", timeout=10)
term.wait_until_idle(timeout=30)
term.clear(clear_tabs=True)
Clipboard
Ctrl+Ccopies selected terminal text.Ctrl+Cwithout a selection interrupts the process.Ctrl+Vpastes in interactive mode.
Flask and Django
The framework-independent TerminalSession and WebSocket adapters remain available:
from notebook_terminal.web import manager
session_id, session = manager.create(cwd=".", interactive=True)
session.run("python --version")
Install optional integrations:
python -m pip install "notebook-terminal[flask]"
python -m pip install "notebook-terminal[django]"
Flask uses flask-sock; Django uses Channels. Both reuse the same terminal session backend and xterm-compatible message protocol.
How the Jupyter bridge works
The notebook frontend is made from:
- a real PTY/ConPTY
TerminalSession, - bundled xterm.js and CSS,
- three hidden standard
ipywidgets.Textareachannels, - JavaScript output that connects xterm.js to those standard widgets,
- a kernel dispatcher that performs widget updates on the kernel event loop.
This avoids AnyModel, custom JupyterLab extensions, version registration errors, and the shell_parent ContextVar error caused by mutating widgets directly from PTY reader threads.
Limitations
Jupyter must allow trusted JavaScript output. Some heavily restricted notebook hosts may disable JavaScript output entirely; that cannot be bypassed by a Python package without administrator support. Standard ipywidgets must also work.
Build
python -m pip install build twine pytest
python -m pytest
python -m build
python -m twine check dist/*
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file notebook_terminal-0.3.0.tar.gz.
File metadata
- Download URL: notebook_terminal-0.3.0.tar.gz
- Upload date:
- Size: 3.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29116e1e4182407d5a86f1f420b7b81ca444488cb6e9f5d4c997825a1011708f
|
|
| MD5 |
9c93a7345bda3c19a14360380f04d528
|
|
| BLAKE2b-256 |
01c698db2c82b319d4292a40a95a3c4ffc634d9fade7d2515cc84c35aaeba8a8
|
File details
Details for the file notebook_terminal-0.3.0-py3-none-any.whl.
File metadata
- Download URL: notebook_terminal-0.3.0-py3-none-any.whl
- Upload date:
- Size: 1.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0316b06db3c729943131c364a14fd3d326f8e0047d56826a198d2de4147ca3c6
|
|
| MD5 |
ccdc834d8db915dd2eef34a225b9f3d9
|
|
| BLAKE2b-256 |
fa3966430157cbc0c842e91b4e8b5f3267ed26d6d105895398cb2227e441d437
|