A lightweight Python package to execute code in an isolated IPython kernel and capture results, stdout, and stderr.
Project description
IPython Kernel Executor
A lightweight Python package to execute code in an isolated IPython kernel and capture results, stdout, and stderr.
Supports Python 2+.
Installation
Make sure you have jupyter-client and ipykernel installed:
pip install jupyter-client ipykernel
Then, install this package:
pip install ipython-kernel-executor
Usage
Basic Execution
from __future__ import print_function
from ipython_kernel_executor import IPythonKernelExecutor
with IPythonKernelExecutor() as executor:
# Captures result
result, stdout, stderr = executor("1 + 1")
print(repr(result)) # '2'
print(repr(stdout)) # ''
print(repr(stderr)) # ''
# Captures stdout
result, stdout, stderr = executor("print('Hello, World!')")
print(repr(result)) # ''
print(repr(stdout)) # 'Hello, World!\n'
print(repr(stderr)) # ''
# Captures stderr
result, stdout, stderr = executor("1 / 0")
print(repr(result)) # ''
print(repr(stdout)) # ''
print(repr(stderr)) # contains 'ZeroDivisionError'
Manual Shutdown (Optional)
If not using with, manually shut down the kernel:
executor = IPythonKernelExecutor()
result, stdout, stderr = executor("2 * 3")
executor.shutdown() # Clean up
Contributing
Contributions are welcome! Please submit pull requests or open issues on GitHub.
License
This project is licensed under the MIT License. See the LICENSE file for details.
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 ipython_kernel_executor-0.1.1.tar.gz.
File metadata
- Download URL: ipython_kernel_executor-0.1.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b6ee6872b5995099c2e83888793c4f28f3aeede451a5d6cfa70d30c1eefa5a8
|
|
| MD5 |
cbe6b1bd174ae62c6197f541f90802e1
|
|
| BLAKE2b-256 |
dc019adefcd89523b2a0d264eb7830a7547d2a07868f4faf73819b408745005a
|
File details
Details for the file ipython_kernel_executor-0.1.1-py2.py3-none-any.whl.
File metadata
- Download URL: ipython_kernel_executor-0.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
251d4f8c37bc5a02f12ac426518f5d44cb3a9d89a3131d2fd6683da2698bfde2
|
|
| MD5 |
5fbd269d8779b00f7e59b0d433324ef6
|
|
| BLAKE2b-256 |
0dde4f1b9d233a88a83e9865817f308d57b6d13b39f1c2d185ce26083f6c322a
|