Skip to main content

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.

Release files for ipython-kernel-executor 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ipython-kernel-executor 0.1.1
File Size Uploaded
ipython_kernel_executor-0.1.1.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ipython-kernel-executor 0.1.1
File Interpreter ABI Platform
ipython_kernel_executor-0.1.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 7.0 kB

Release files / ipython_kernel_executor-0.1.1.tar.gz

Download URL ipython_kernel_executor-0.1.1.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3b6ee6872b5995099c2e83888793c4f28f3aeede451a5d6cfa70d30c1eefa5a8
BLAKE2b-256 checksum
How to use checksums
dc019adefcd89523b2a0d264eb7830a7547d2a07868f4faf73819b408745005a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release files / ipython_kernel_executor-0.1.1-py2.py3-none-any.whl

Download URL ipython_kernel_executor-0.1.1-py2.py3-none-any.whl
Size 3.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
251d4f8c37bc5a02f12ac426518f5d44cb3a9d89a3131d2fd6683da2698bfde2
BLAKE2b-256 checksum
How to use checksums
0dde4f1b9d233a88a83e9865817f308d57b6d13b39f1c2d185ce26083f6c322a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page