Skip to main content

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}'

The command takes the following arguments:

  • schedule: Cron schedule expression (e.g., "0 * * * *" for hourly)
  • notebook: Path to the input notebook file
  • log_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

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
)

# 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
)

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 hour
    • 0 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


Download files

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

Source Distribution

jplan-1.0.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

jplan-1.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file jplan-1.0.0.tar.gz.

File metadata

  • Download URL: jplan-1.0.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for jplan-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d8c866b6852ba2f05ae06ba29577efd2f9bf521c00d9f9beac990c17a6c85fe3
MD5 9bc7f6f9b36539a668f2e15b7ae28476
BLAKE2b-256 e04efe427ca0f9c26d06b4162bb20ed224614f7f3f70faac705fe4e905ac44e6

See more details on using hashes here.

File details

Details for the file jplan-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: jplan-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for jplan-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 858c8a3c119c3af7201689c88d8e7e5fc62ae9da3799951aa83b6ee11633b403
MD5 405d36c461c229a5361d51544c034cd3
BLAKE2b-256 849d36e74d6acbc79f0e2bc8ed86e909d93e097ea775026382dfe28c0b8c5721

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