A tool that programmatically executes and converts a Jupyter Notebook using nbconvert's CLI functionality, enabling automated notebook execution and format conversion.
Project description
swarmauri_tool_jupyterexecuteandconvert
This package provides functionality to programmatically execute a Jupyter Notebook and convert it to a variety of output formats using nbconvert, enabling automated workflows within the Swarmauri framework.
Installation
swarmauri_tool_jupyterexecuteandconvert supports Python 3.10 to 3.13. To install from PyPI, use:
pip install swarmauri_tool_jupyterexecuteandconvert
Once installed, the JupyterExecuteAndConvertTool becomes available, offering notebook execution and conversion features via the nbconvert CLI.
Usage
Below is a detailed example of how to utilize the JupyterExecuteAndConvertTool in your environment. The tool exposes a callable class that you can directly instantiate and use in your Python code.
-
Import the tool into your code:
from swarmauri_tool_jupyterexecuteandconvert import JupyterExecuteAndConvertTool
-
Create an instance of the tool:
notebook_tool = JupyterExecuteAndConvertTool()
-
Invoke the tool to execute and convert a notebook:
result = notebook_tool( notebook_path="path/to/your_notebook.ipynb", output_format="pdf", # can also be "html" execution_timeout=600 # optional, defaults to 600 seconds )
-
Process the returned dictionary:
if "status" in result and result["status"] == "success": print(f"Successfully converted notebook to: {result['converted_file']}") else: print(f"Error: {result.get('error')} - {result.get('message')}")
The result dictionary can contain:
• "converted_file": A string representing the output file name.
• "status": "success" if execution and conversion succeeded.
• "error" and "message": In the event of any errors during execution or conversion.
Here is a short illustration:
from swarmauri_tool_jupyterexecuteandconvert import JupyterExecuteAndConvertTool
Create the tool instance
tool = JupyterExecuteAndConvertTool()
Execute and convert a Jupyter notebook to PDF with a 5-minute timeout
response = tool( notebook_path="analysis.ipynb", output_format="pdf", execution_timeout=300 )
if response.get("status") == "success": print(f"Notebook converted: {response['converted_file']}") else: print(f"Error type: {response.get('error')}") print(f"Error message: {response.get('message')}")
Dependencies
• nbconvert: Used for executing and converting Jupyter notebooks to the desired output format.
• swarmauri_core, swarmauri_base: Required dependencies from the Swarmauri framework, providing essential base classes and utilities.
• Python 3.10 or above.
The tool automatically integrates into the Swarmauri ecosystem by inheriting from ToolBase and registering itself with ComponentBase.
About JupyterExecuteAndConvertTool
The JupyterExecuteAndConvertTool is defined in JupyterExecuteAndConvertTool.py. It inherits from ToolBase and uses the @ComponentBase.register_type decorator, making it seamlessly integrable as a Swarmauri tool. It logs notebook execution progress and handles any errors or timeouts. Once the notebook is executed, nbconvert is used again to convert the resultant executed notebook to the specified format (HTML or PDF).
Key attributes within the tool:
• version: A string indicating the current version of the tool.
• parameters: A list of Parameter objects describing inputs such as notebook_path, output_format, and execution_timeout.
• call: A method accepting notebook_path, output_format, and execution_timeout, returning a dictionary with information about the process result or any encountered errors.
Contributing
Thank you for your interest in swarmauri_tool_jupyterexecuteandconvert. Pull requests and bug reports are welcome. Please see our issue tracker for existing requests and open issues.
© 2023 Swarmauri – Licensed under the Apache License, Version 2.0.
Happy notebook converting!
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 swarmauri_tool_jupyterexecuteandconvert-0.7.0.dev10.tar.gz.
File metadata
- Download URL: swarmauri_tool_jupyterexecuteandconvert-0.7.0.dev10.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5265fe5a986510d99b5a81034e94800f7f4d7e59dc010e0f6097887f016ca14
|
|
| MD5 |
4d3c983382f457809326bbfef6ce9365
|
|
| BLAKE2b-256 |
18bd6a561a4270b1aee66912dd292c74e1d80c23ad6a51c9311aa3edd0e59022
|
File details
Details for the file swarmauri_tool_jupyterexecuteandconvert-0.7.0.dev10-py3-none-any.whl.
File metadata
- Download URL: swarmauri_tool_jupyterexecuteandconvert-0.7.0.dev10-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3059f48763d42230f71a7efc62dd7d8123084a62e3a50e30a6de73fd025140dd
|
|
| MD5 |
92d86da899f0495b6a39e1e01b16c45b
|
|
| BLAKE2b-256 |
d872b42d84af5abf3806d0c40694eaf2f3445e55ed797d54c0bf7a018d1543ea
|