Skip to main content

jlab_method_pull

Pull class methods into editable JupyterLab cells and inject modified versions back — optionally rewriting the source file for persistence.

Install

pip install jlab_method_pull

To make pullMethodCode and injectMethod available automatically in every JupyterLab kernel, run once:

from jlab_method_pull import install
install()

Usage

Pull a method into a new cell

from jlab_method_pull import pullMethodCode, injectMethod
from mymodule import MyClass

pullMethodCode(MyClass.some_method)

A new cell appears below, pre-filled with the method's source, all imports from the source file, and a ready-to-run injectMethod call:

import numpy as np
from mymodule import MyClass, OtherClass

def some_method(self, x):
    ...

injectMethod(some_method, MyClass, persistent=False)

Inject a method back

# In-memory only (survives the session, not reimports):
injectMethod(some_method, MyClass, persistent=False)

# Persistent (also rewrites mymodule.py on disk):
injectMethod(some_method, MyClass, persistent=True)

persistent=True uses AST to locate the exact lines of the old method in the source file and replaces them. It works correctly even if the method was previously monkey-patched in memory.

How it compares

Tool Cell injection Runtime patch Rewrites source file
IPython %load file-level only — —
gorilla — yes —
jlab_method_pull method-level yes yes

Requirements

  • Python ≥ 3.9
  • IPython (only required for the Jupyter cell injection and install())

Release files for jlab-method-pull 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jlab-method-pull 1.1.0
File Size Uploaded
jlab_method_pull-1.1.0.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jlab-method-pull 1.1.0
File Interpreter ABI Platform
jlab_method_pull-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.1 kB

Release files / jlab_method_pull-1.1.0.tar.gz

Download URL jlab_method_pull-1.1.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
76a36391217c9ec189033ca980f390266b960c52ba9510656d1646b22166fac3
BLAKE2b-256 checksum
How to use checksums
fb2cfe2bba991601d35492c296efac251040f568b9e3ecfc576d516dd004580d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / jlab_method_pull-1.1.0-py3-none-any.whl

Download URL jlab_method_pull-1.1.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae00a438d9632cacb9abb24bf6a71985824f3680d4c51aecb4f8631653b95dc5
BLAKE2b-256 checksum
How to use checksums
fe4c9f0e1ad7780baa893d9f55599e2a16895256b1fa72cbbe9d6ec66ad98bb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page