Run some IPython ZMQ kernel in the background, without an interactive shell. You can connect to that kernel remotely via ZMQ.
Installation (package is on PyPI):
pip install background_zmq_ipython
Usage:
import background_zmq_ipython background_zmq_ipython.init_ipython_kernel()
The kernel will then run in the background in its own thread. The init will print some message similar to this on stdout:
To connect another client to this IPython kernel, use: jupyter console --existing kernel-1111.json
Now, after you connected, how to access globals from the main module? E.g. let’s say there is a variable a.
sys.modules["__main__"].a should work. Via sys.modules, you can access all the imported modules. Or just do import mod again.
Get the stack of all/other frames via sys._current_frames(), and there you can access the globals from other threads as well.
You can provide user_ns to init_ipython_kernel, e.g:
init_ipython_kernel(user_ns=globals())
or:
init_ipython_kernel(user_ns={"main_globals": globals()})or:
init_ipython_kernel(user_ns={"a": a})
Alternatives / related links:
IPython.embed_kernel in a background thread (example code). This has some issues (e.g. here; messing around with sys.stdout etc).
This code was introduced in this StackOverflow question, and also discussed in this IPython GitHub issue #8097, but it has become outdated, so this project provides a rewrite / updated code, and the goal was also an easy to install pip package.
Metadata
Release files for background-zmq-ipython 1.20250423.155902
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 |
|---|---|---|---|---|
| background_zmq_ipython-1.20250423.155902.tar.gz | 9.1 kB | Without provenance | Details for background_zmq_ipython-1.20250423.155902.tar.gz |
Release files / background_zmq_ipython-1.20250423.155902.tar.gz
| Download URL | background_zmq_ipython-1.20250423.155902.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
593106f29ed8f92b82ee28a067708506742eb41daef7e6fdf59bc693069ea427
|
|
BLAKE2b-256 checksum How to use checksums |
934b824c2b5238a41f3419662b8a01658db3b30c7b80a036484db89d6e3c626a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.7
|
Security for background-zmq-ipython 1.20250423.155902
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.