Skip to main content

Pull class methods into Jupyter cells and inject edited versions back — with optional persistence to source files

Project description

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

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

jlab_method_pull-1.0.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

jlab_method_pull-1.0.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jlab_method_pull-1.0.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for jlab_method_pull-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e5a58d9f5083e085aec42fc23f2fe6b4429636ce54ab86132cd150b6820bd93b
MD5 dc1d9485ca811d0945db351b5fab6ec2
BLAKE2b-256 d890bef77ab73ee8f7aa0f082fc80da3c33b81d083004e941f91392bfffd38eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jlab_method_pull-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ff0773bdb3efe8ac0946f31a19868056bd52bc9bb48e12d0320f16c7d4db6f0
MD5 4bb2ae9869dda54ebe89f297de6cff6d
BLAKE2b-256 0b25239e1db8d63959ca53f524a6ce78bbb66bc069745f49eebde42a122deec0

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