Skip to main content

A tool designed to start a new Jupyter kernel programmatically using jupyter_client, enabling execution of notebook cells.

Project description

Swamauri Logo

PyPI - Downloads GitHub Hits PyPI - Python Version PyPI - License
PyPI - swarmauri_tool_jupyterstartkernel


swarmauri_tool_jupyterstartkernel

Overview

The swarmauri_tool_jupyterstartkernel package provides a tool that programmatically starts a Jupyter kernel using jupyter_client. It integrates seamlessly with the Swarmauri framework to offer flexible kernel initialization, monitoring, and error handling.

This tool can be particularly useful for dynamic, programmatic execution of notebook cells, automated testing of notebook-based workflows, or other situations where a Python (or alternative language) kernel instance is needed on-demand.


Installation

You can install this package from the Python Package Index (PyPI). Make sure your Python version is between 3.10 and 3.12 (inclusive of 3.10 and exclusive of 3.13):

pip install swarmauri_tool_jupyterstartkernel

If your environment uses Poetry, you can add this line to your pyproject.toml under [tool.poetry.dependencies]:

swarmauri_tool_jupyterstartkernel = "*"

Note that the tool depends on: • swarmauri_core
• swarmauri_base
• jupyter_client

These will be installed automatically when using pip or Poetry.


Usage

Once installed, you can import and create an instance of the JupyterStartKernelTool in your Python code. Below is a simple example showing how to start a kernel and capture the resulting kernel name and ID.

from swarmauri_tool_jupyterstartkernel import JupyterStartKernelTool

# Create an instance of the JupyterStartKernelTool
tool = JupyterStartKernelTool()

# Start a default python3 kernel
results = tool()
print("Default Kernel Results:", results)

# Start a different kernel by specifying 'kernel_name'
custom_results = tool(kernel_name="python3")
print("Custom Kernel Results:", custom_results)

Advanced Usage

You can optionally provide a kernel specification dictionary to configure more complex settings (e.g., environment variables, resource limits, custom arguments). This example shows how you might pass a simple configuration dictionary:

config_spec = {
    "env": {
        "MY_CUSTOM_ENV_VAR": "test_value"
    }
}

# Start a kernel with custom specification
results_with_spec = tool(kernel_name="python3", kernel_spec=config_spec)
print("Advanced Kernel Results with Spec:", results_with_spec)

If a kernel fails to start, the tool returns an error message in the dictionary:

error_results = tool(kernel_name="non_existent_kernel")
if "error" in error_results:
    print("Error starting kernel:", error_results["error"])

Retrieving the Kernel Manager

The JupyterStartKernelTool class stores the KernelManager instance internally for access after a successful start. You can retrieve it at any time using:

km = tool.get_kernel_manager()
if km:
    print("Kernel Manager is available for further operations.")

Dependencies

• swarmauri_core: Provides the base classes and architecture for Swarmauri-type components.
• swarmauri_base: Contains the general ToolBase class and other internal utilities.
• jupyter_client: Manages Jupyter kernel operations, allowing this tool to start and monitor kernels.


License

swarmauri_tool_jupyterstartkernel is distributed under the Apache-2.0 License.
© 2023 Swarmauri. All Rights Reserved.

For additional support, feel free to open an issue or contact our team for guidance on leveraging this tool within your Swarmauri-based deployments.

Project details


Release history Release notifications | RSS feed

This version

0.7.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_tool_jupyterstartkernel-0.7.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file swarmauri_tool_jupyterstartkernel-0.7.0.tar.gz.

File metadata

File hashes

Hashes for swarmauri_tool_jupyterstartkernel-0.7.0.tar.gz
Algorithm Hash digest
SHA256 38c4d117c19ff5f2b1d3a8829dc204b1346dc557f71d4f5e3824d443c10690dc
MD5 a56745c7a16bf87712e83222fc4b5a8d
BLAKE2b-256 a5516cd3dc299ad51ce952ef9e22d93d7cea006ce0a628d416542d78acdaee9b

See more details on using hashes here.

File details

Details for the file swarmauri_tool_jupyterstartkernel-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for swarmauri_tool_jupyterstartkernel-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a43684e53bf3bcb80f14b03c035da8d023bbd770995ac0e966ce98339a8b2e45
MD5 b6a804a267b5b71825dfbbb9e580e1d4
BLAKE2b-256 5fc7650e0246ff226b76cb6d6ecbb1ffb5bb6c19d6388144f16521190f46a775

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page