Skip to main content

Lightweight JSONL execution logging for IPython.

Project description

ipy-runlog

A lightweight IPython extension that records code cell execution history as JSON Lines (JSONL).

Motivation

Experiments are shaped by failed attempts as well as successful ones. Recording both preserves the trial-and-error process, giving an experiment notebook a coherent story instead of showing only its final results.

Installation

With pip:

pip install ipy-runlog

In a uv project:

uv add ipy-runlog

Usage

Load the extension — recording starts automatically:

%load_ext ipy_runlog

The log is written to .ipy_runlog/ in the current working directory. The file name is generated from the current date and time, for example:

.ipy_runlog/20260611-123456.jsonl

Recording stops automatically when the IPython session ends.

Commands

Check the current status:

%runlog status

Switch to a new log file mid-session (closes the current log):

%runlog new experiment-01
%runlog new experiment-01 --output   # also record cell output
%runlog new experiment-01 -d ./logs  # custom output directory

Rename the current log file without interrupting recording:

%runlog rename feature-extraction

Stop recording manually:

%runlog stop

Show help:

%runlog help
%runlog new --help

Configuration

You can set defaults in pyproject.toml:

[tool.ipy-runlog]
directory = "./logs"
output = true

Or in .ipy_runlog.toml at the project root (used as a fallback when pyproject.toml is absent or has no [tool.ipy-runlog] section):

directory = "./logs"
output = true

Available config keys:

Key Type Default Description
directory string .ipy_runlog/ Output directory
output bool false Record cell output
name string current timestamp Default log file name

Note: Python 3.11+ uses the built-in tomllib. For Python 3.9–3.10, install tomli to enable config file support: pip install tomli.

How It Works

The extension uses IPython event handlers to monitor cell execution:

  • pre_run_cell: Triggered before a cell is executed. The extension captures the source code of the cell at this point.
  • post_run_cell: Triggered after a cell finishes executing. The extension calculates the elapsed time, determines if it was successful or failed (including error details), and optionally captures the output.

Each event is appended as a single JSON line to the log file. On normal session exit, a final recording_stopped event is written automatically via atexit.

Log Format

Logs use UTF-8 encoded JSON Lines, with one event per line. New events are appended when the target file already exists.

Event types:

  • recording_started: recording started
  • cell_executed: a cell finished executing
  • recording_renamed: log file was renamed with %runlog rename
  • recording_stopped: recording stopped (includes "reason": "session_ended" on automatic stop)

A cell_executed event contains:

  • started_at and ended_at: local timestamps in ISO 8601 format
  • elapsed_sec: execution time in seconds
  • status: success or failed
  • execution_count: the IPython execution count
  • code: the cell source code
  • output: the cell result when --output is enabled; non-JSON values are stored using repr()
  • error: error type, message, and traceback (always recorded on failure)

Development

Install this repository in editable mode:

python -m pip install -e .

With uv:

uv pip install -e .

Run the test suite:

uv run pytest

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

ipy_runlog-0.1.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

ipy_runlog-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file ipy_runlog-0.1.0.tar.gz.

File metadata

  • Download URL: ipy_runlog-0.1.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ipy_runlog-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2b561498d1598c64596dc40649f8e7c5c55c3b8cd0bf8da3a24c7d8459a14054
MD5 4606e147e4b99e07bc923838080c513d
BLAKE2b-256 ee9f4984bbabf2036b0ac94ee832324b22f2f5bed302535fb20a4e6d04672d0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ipy_runlog-0.1.0.tar.gz:

Publisher: publish.yml on kromiii/ipy-runlog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ipy_runlog-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ipy_runlog-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ipy_runlog-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62abee770babe502cf692f3420a8447729e3b12aceb318dc247c203741b1b4e7
MD5 ca9d78e88cbed9b10c8faf2223ae388c
BLAKE2b-256 48d2f091166ed0037821f36ff6e82b40df181f43c665fadacc0cb3db1505464a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ipy_runlog-0.1.0-py3-none-any.whl:

Publisher: publish.yml on kromiii/ipy-runlog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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