About
Qonsole is a lightweight Python console for Qt applications. It's made to be easy to embed in other PySide/PyQt applications and comes with some examples that show how this can be done. The interpreter can run in a separate thread, in the UI main thread or in a gevent task. Qonsole is a fork of pyqtconsole. The two diverged at pyqtconsole v1.3.0, and it is not quite a drop-in replacement, but does implement new features and has various improvements.
Simple usage
The following snippet shows how to create a console that will execute user
input in a separate thread. Be aware that long running tasks will still block
the main thread due to the GIL. See the examples directory for more
examples.
import sys
from threading import Thread
from PyQt5.QtWidgets import QApplication
from qonsole import PythonConsole
app = QApplication([])
console = PythonConsole()
console.show()
console.eval_in_thread()
sys.exit(app.exec_())
Embedding
-
Separate thread - Runs the interpreter in a separate thread, see the example
threaded.py. Running the interpreter in a separate thread obviously limits the interaction with the Qt application. The parts of Qt that needs to be called from the main thread will not work properly, but is excellent way for having a 'plain' python console in your Qt app. -
main thread - Runs the interpreter in the main thread, see the example
inuithread.py. Makes full interaction with Qt possible, lenghty operations will of course freeze the UI (as any lenghty operation that is called from the main thread). This is a great alternative for people who does not want to use the gevent based approach but still wants full interactivity with Qt. -
gevent - Runs the interpreter in a gevent task, see the example
_gevent.py. Allows for full interactivity with Qt without special consideration (at least to some extent) for longer running processes. The best method if you want to use pyQtgraph, Matplotlib, PyMca or similar.
Features
Syntax highlighting
Syntax highlighting is provided by the https://pygments.org library.
Simply pass the Pygments style string to the PythonConsole constructer like so:
console = PythonConsole(pygments_style='github-dark')
Magic commands
Commands that start with % are magic commands.
This features provides IPython-like magic commands such as:
%pwd-- Print current working directory%cd-- Change directory%ls-- List directory contents%who-- List variable names in the current namespace%whos-- Display detailed variable information%timeit-- Time the execution of a Python statement%run-- Execute a Python script file%clear-- Clear the console display%export-- Export console session as Python script (.py) or Jupyter notebook (.ipynb)%help-- Display help message for magic commands
In addition, custom magic commands can be defined by using the add_magic_command() method. Example:
def version(args=None):
return '3.3.0'
console = PythonConsole()
console.add_magic_command("version", version)
Which can be used like so:
IN [0]: %version
3.3.0
Shell commands
Commands entered in the console that start with ! will be executed as shell commands.
The output of the command will be printed in the console.
For example, on a Linux or macOS system, entering !ls -l will list the files in the current directory. Example:
IN [0]: !ls -l
OUT[0]: total 16546
-rw-r--r-- 1 user user 18741 Fen 6 2026 file1.txt
-rw-r--r-- 1 user user 18741 Feb 6 2026 file2.txt
Prompt String
By default IN [n]: and OUT [n]: are displayed before each input and output line.
You can customize this through constructor arguments:
# Including the line numbers:
console = PythonConsole(inprompt="%d >", outprompt="%d <")
# Or just static:
console = PythonConsole(inprompt=">>>", outprompt="<<<")
Right-click menu
The console's right-click menu includes several useful items:
- "Copy"
- "Paste"
- "Select All"
- "Clear Console" (same as the
%clearmagic command) - "Export Session" (same as the
%exportmagic command) - "Toggle Word Wrap"
Credits
This module depends on QtPy which provides a compatibility layer for Qt. The console is tested under both Qt5 and Qt6.
Development
- Repository at GitHub
- To generate coverage information for the unit tests, run
pixi run "coverage run -m pytest tests/ && coverage report -m && coverage html"
Metadata
Release files for qonsole 3.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qonsole-3.3.0.tar.gz | 169.1 kB | With provenance | Details for qonsole-3.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qonsole-3.3.0-py3-none-any.whl | Python 3 | none | any | Details for qonsole-3.3.0-py3-none-any.whl |
Total release size: 208.0 kB
Release files / qonsole-3.3.0.tar.gz
| Download URL | qonsole-3.3.0.tar.gz |
|---|---|
| Size | 169.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63a7e046ac5e519cc519cbe6f4a8add65fdf6e972999b423682e1abfba4a310e
|
|
BLAKE2b-256 checksum How to use checksums |
2fdd13bd21891c4f81e941bfbb7fe27c0f0c64e20f6a99b62ffe756707d53065
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 16, 2026.
Transparency logRelease files / qonsole-3.3.0-py3-none-any.whl
| Download URL | qonsole-3.3.0-py3-none-any.whl |
|---|---|
| Size | 38.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1471817e28bf50952ece532cb2d12ef9d0de6335b16330065a286a0e7476cd74
|
|
BLAKE2b-256 checksum How to use checksums |
64bfec09170e7237fa2ad6e3630b3cb76baa94332cdf3cd450d03bea93e61546
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 16, 2026.
Transparency logSecurity for qonsole 3.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for qonsole-3.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.