A package to run Jupyter notebook cells from the command line.
Project description
cell_runner
cell_runner
is a Python command-line tool that allows you to execute a specific code cell from a Jupyter notebook (.ipynb
file) directly from the command line. It is particularly useful when you want to run a single code cell from a notebook without opening the Jupyter interface.
Features
- Execute any specific code cell from a Jupyter notebook (
.ipynb
file) via CLI. - Works without requiring the entire notebook to be executed or opened.
- Simple and easy-to-use.
Installation
You can install cell_runner
locally by cloning the repository and running the following command:
pip install -e .
This installs the package in "editable" mode, allowing you to modify the code and use it without reinstalling.
Requirements
Make sure you have the following dependencies installed before using cell_runner
:
- Python 3.6 or higher
- Jupyter (for working with
.ipynb
files) - json
- subprocess
- argparse (comes with Python 3.6+)
You can install the required packages using pip
:
pip install -r requirements.txt
Usage
Once installed, you can use the cell_runner
command to run a code cell from a Jupyter notebook.
Command Syntax
cell_runner <notebook_file> <cell_index>
<notebook_file>
: The path to the.ipynb
file (Jupyter notebook).<cell_index>
: The index of the code cell to execute (starting from 0).
Examples
1. Running a specific cell from a notebook
To execute the code in the 3rd cell (index 2) of a notebook named example.ipynb
:
cell_runner example.ipynb 2
2. Handling Errors
-
If the file is not a Jupyter notebook: If you pass a file that does not end with
.ipynb
, you'll see an error:File must be a .ipynb file
-
If the cell index is out of range: If you specify an index that is out of the range of available code cells, the tool will raise an error:
Cell index is out of range. Please check the cell index. (Index starts from 0)
Example Notebook
Suppose example.ipynb
has the following cells:
-
Cell 0:
print("Cell 0")
-
Cell 1:
print("Cell 1")
-
Cell 2:
print("Cell 2")
Running the command:
cell_runner example.ipynb 1
Will execute the code in Cell 1, and you will see the following output:
Cell 1
Testing
To test the functionality of the cell_runner
package, you can use the following steps:
- Create a test Jupyter notebook (
test.ipynb
) with several code cells. - Run the
cell_runner
command on various cell indices to ensure that the correct cell is executed.
For example, to run a test on the 1st cell (index 0):
cell_runner test.ipynb 0
Additionally, you can add automated tests using pytest
:
pip install pytest
pytest tests/
Make sure you have test cases in the tests/
directory.
Development
To contribute or modify the package, follow these steps:
-
Clone the repository:
git clone <repository-url> cd my_python_package
-
Install the package in editable mode:
pip install -e .
-
Modify the code as needed in the
cell_runner
directory.
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
File details
Details for the file cell_runner-0.1.tar.gz
.
File metadata
- Download URL: cell_runner-0.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d5b142a68ad1d801801cf3c005513b118bb11706eeddfb04e2dc4ed663ee8ac |
|
MD5 | 2389fe3d8934522b502dd4050d80e201 |
|
BLAKE2b-256 | b786f9470e1141f28f6252f81854d8d70b03ac9bb0cb69d09a8aa76fa414a493 |
File details
Details for the file cell_runner-0.1-py3-none-any.whl
.
File metadata
- Download URL: cell_runner-0.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf120a3a6ef6722716c39762ec23c9e131062726d975b1e9fdf8dc6632222c61 |
|
MD5 | ae9b3bf7716d4ffd7e9b7701ab2a352c |
|
BLAKE2b-256 | cc04b0773f64b41c5b9afe1a8604487e0f3f56d08be8e59bea076e455d355e20 |