A command-line tool to schedule and execute Jupyter notebooks using cron
Project description
jplan
A command-line tool to schedule and execute Jupyter notebooks using cron.
Installation
This package uses uv for package management. To install:
# Install uv if you haven't already
pip install uv
# Create a virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .
Usage
Command Line Interface
The simplest way to use jplan is through the command line:
# Run notebook every hour with default log file in notebook's directory
jplan "0 * * * *" input.ipynb
# Run notebook every hour with specific log file (positional argument)
jplan "0 * * * *" input.ipynb output.log
# Run notebook every hour with specific log file (keyword argument)
jplan "0 * * * *" input.ipynb --log-file output.log
# Run notebook every hour with specific kernel
jplan "0 * * * *" input.ipynb --kernel python3
# Run notebook every 15 minutes
jplan "*/15 * * * *" input.ipynb
# Run notebook with custom output directory
jplan "0 * * * *" input.ipynb --output-dir /path/to/output
# Run notebook with parameters
jplan "0 * * * *" input.ipynb --parameters '{"param1": "value1", "param2": 42}'
# Run notebook with custom working directory for relative paths
jplan "0 * * * *" input.ipynb --working-dir /path/to/data
The command takes the following arguments:
schedule: Cron schedule expression (e.g., "0 * * * *" for hourly)notebook: Path to the input notebook filelog_file: (Optional) Path to the log file (can be specified as positional or --log-file argument)--output-dir: (Optional) Directory to save executed notebooks--parameters: (Optional) JSON string of parameters to pass to the notebook--kernel: (Optional) Name of the kernel to use for execution--working-dir: (Optional) Working directory for resolving relative paths (defaults to notebook directory)
Relative Path Handling
jplan automatically handles relative paths in your notebooks. When a notebook is executed:
- The working directory is set to the notebook's location by default
- You can specify a custom working directory using
--working-dir - All relative paths in the notebook are resolved relative to the working directory
- The original notebook is never modified (changes are made in a temporary copy)
Example notebook code:
import pandas as pd
# These will all work correctly
df1 = pd.read_csv('data.csv') # Resolves to working_dir/data.csv
df2 = pd.read_csv('./data.csv') # Resolves to working_dir/data.csv
df3 = pd.read_csv('../data.csv') # Resolves to working_dir/../data.csv
# You can also use the resolve_path helper
from pathlib import Path
file_path = resolve_path('data.csv') # Gets absolute path
Python API
You can also use the package programmatically:
from jplan.executor import execute_notebook
# Execute a notebook with default settings
execute_notebook(
input_path="path/to/input.ipynb"
)
# Execute a notebook with custom settings
execute_notebook(
input_path="path/to/input.ipynb",
output_path="path/to/output.ipynb", # optional
parameters={"param1": "value1", "param2": 42}, # optional
kernel_name="python3", # optional
log_file="path/to/output.log", # optional
working_dir="path/to/data" # optional
)
# Create a cron job
from jplan.cron import create_cron_job
create_cron_job(
notebook_path="path/to/input.ipynb",
schedule="0 * * * *", # Run at the start of every hour
output_dir="path/to/output", # optional
parameters={"param1": "value1"}, # optional
kernel_name="python3", # optional
log_file="path/to/output.log", # optional
working_dir="path/to/data" # optional
)
The schedule parameter uses standard cron syntax:
* * * * *represents: minute hour day-of-month month day-of-week- Examples:
0 * * * *- Run at the start of every hour0 0 * * *- Run at midnight every day*/15 * * * *- Run every 15 minutes
The executed notebooks will be saved with "_executed" appended to the filename, and a log file will be created in the output directory.
Development
To install development dependencies:
uv pip install -e ".[dev]"
License
MIT
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 jplan-1.1.0.tar.gz.
File metadata
- Download URL: jplan-1.1.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b67219833409fe806a6f1b1fd97477b29a963a32db2447ef5465390c896baa99
|
|
| MD5 |
ff25cc750927a68baa8eed205c17b8c4
|
|
| BLAKE2b-256 |
4f7e18ce9ba1c28fc3b872ac82dcdad6a3dfd914f998fc94a1a7327adb5c1ca2
|
File details
Details for the file jplan-1.1.0-py3-none-any.whl.
File metadata
- Download URL: jplan-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
247b548dc028f14cc7ed7b22ca9fdfe19c70457826998efeda6cdc1270b07a52
|
|
| MD5 |
d1d1681ec9b298cb7d4e638767105e5d
|
|
| BLAKE2b-256 |
f210150fbbd7b984e687475064e2824259891601f338df3907c54be25ef7a608
|