IPython Integration
The IPython integration layer under jumper_extension.ipython connects the core service to notebooks and IPython shells. For user‑facing usage of magic commands, see the Jupyter API; the sections below provide code‑level reference generated via mkdocstrings.
Extension entry points
DropCellTransformer
Drop the entire cell if it is being recorded.
Source code in jumper_extension/ipython/extension.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
__call__(lines)
IPython cleanup_transforms expects a callable: (lines) -> lines.
Source code in jumper_extension/ipython/extension.py
28 29 30 31 32 33 34 35 36 37 38 | |
transform_cell(cell)
Return an empty string to drop the whole cell.
Source code in jumper_extension/ipython/extension.py
40 41 42 43 44 45 46 47 48 49 50 51 | |
Magic commands
Bases: Magics
IPython line magics for the JUmPER extension.
This class defines the %perfmonitor_* family of magics and a
few helpers. Each magic forwards its work to a
:class:PerfmonitorMagicAdapter instance, which in turn delegates
to :class:PerfmonitorService.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shell
|
Any
|
The current IPython shell instance. |
required |
magic_adapter
|
PerfmonitorMagicAdapter
|
Adapter that implements the string-based public API used by these magics. |
required |
Examples:
Load the extension in a notebook::
%load_ext jumper_extension
Source code in jumper_extension/ipython/magics.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
__init__(shell, magic_adapter)
Initialize the magics wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shell
|
Any
|
IPython shell the magics are registered on. |
required |
magic_adapter
|
PerfmonitorMagicAdapter
|
Adapter used to execute the underlying commands. |
required |
Source code in jumper_extension/ipython/magics.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
end_write_script(line)
Stop recording and save accumulated code to a script file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Unused argument string. |
required |
Examples:
%end_write_script
Source code in jumper_extension/ipython/magics.py
418 419 420 421 422 423 424 425 426 427 428 | |
export_session(line)
Export the full monitoring session to a directory or zip.
When the target ends with .zip, a temporary directory is
created and compressed into that archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Raw argument string containing an optional target path. |
required |
Returns: None
Examples:
Export into a directory::
%export_session my_dir
Export into a zip archive::
%export_session my_session.zip
Source code in jumper_extension/ipython/magics.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
import_session(line)
Import a monitoring session from a directory or zip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Raw argument string with the source path. |
required |
Returns: None
Examples:
%import_session my_session.zip
Source code in jumper_extension/ipython/magics.py
329 330 331 332 333 334 335 336 337 338 339 340 341 | |
perfmonitor_disable_perfreports(line)
Disable automatic performance reports.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Unused argument string. |
required |
Returns: None
Examples:
%perfmonitor_disable_perfreports
Source code in jumper_extension/ipython/magics.py
187 188 189 190 191 192 193 194 195 196 197 198 199 | |
perfmonitor_enable_perfreports(line)
Enable automatic performance reports after each cell.
The line string is parsed for options such as monitoring level, interval, and whether to use text or HTML output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Raw argument string, for example
|
required |
Returns: None
Examples:
Enable HTML reports at process level::
%perfmonitor_enable_perfreports --level process
Enable text reports for user level with custom interval::
%perfmonitor_enable_perfreports --level user --interval 0.5 --text
Source code in jumper_extension/ipython/magics.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
perfmonitor_export_cell_history(line)
Export cell history or push it into the notebook.
If --file is provided, the cell history is written to disk.
Otherwise, a data frame is pushed into the user namespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Raw argument string, for example
|
required |
Returns: None
Examples:
Export cell history to CSV::
%perfmonitor_export_cell_history --file cells.csv
Push the cell history DataFrame::
%perfmonitor_export_cell_history
Source code in jumper_extension/ipython/magics.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
perfmonitor_export_perfdata(line)
Export performance data or push it into the notebook.
If --file is provided, data is written to disk. Otherwise,
the resulting data frames are pushed into the user namespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Raw argument string, such as
|
required |
Returns: None
Examples:
Export process-level data to CSV::
%perfmonitor_export_perfdata --file perf.csv --level process
Push a DataFrame into the notebook::
%perfmonitor_export_perfdata --level user
Source code in jumper_extension/ipython/magics.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
perfmonitor_fast_setup(line)
Run a quick setup for interactive monitoring.
This helper enables ipympl interactive plots (if available),
starts monitoring, and turns on automatic performance reports.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Unused argument string. |
required |
Returns: None
Examples:
Quickly prepare interactive monitoring in a notebook::
%perfmonitor_fast_setup
Source code in jumper_extension/ipython/magics.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
perfmonitor_help(line)
Show comprehensive help for all available magics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Unused argument string. |
required |
Returns: None
Examples:
%perfmonitor_help
Source code in jumper_extension/ipython/magics.py
382 383 384 385 386 387 388 389 390 391 392 393 394 | |
perfmonitor_load_cell_history(line)
Load cell history from disk and push it to the notebook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Raw argument string containing |
required |
Returns: None
Examples:
%perfmonitor_load_cell_history --file cells.csv
Source code in jumper_extension/ipython/magics.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
perfmonitor_load_perfdata(line)
Load performance data from disk and push it to the notebook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Raw argument string containing |
required |
Returns: None
Examples:
%perfmonitor_load_perfdata --file perf.csv
Source code in jumper_extension/ipython/magics.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
perfmonitor_perfreport(line)
Show a performance report for the current session.
The line string may include cell range and monitoring level options to restrict the report.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Raw argument string, for example
|
required |
Returns: None
Examples:
Show a report for all cells::
%perfmonitor_perfreport
Show a report for cells 2–5 at system level::
%perfmonitor_perfreport --cell 2:5 --level system
Source code in jumper_extension/ipython/magics.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
perfmonitor_plot(line)
Open an interactive performance plot.
This magic opens interactive widgets for exploring collected performance data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Raw argument string forwarded to the adapter. |
required |
Returns: None
Examples:
Open an interactive plot for the current session::
%perfmonitor_plot
Source code in jumper_extension/ipython/magics.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
perfmonitor_resources(line)
Show hardware resources available to the current session.
This magic prints CPUs, memory, and GPU information for either a live or imported monitoring session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Unused argument string. |
required |
Returns: None
Examples:
Show resources for the current session::
%perfmonitor_resources
Source code in jumper_extension/ipython/magics.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
perfmonitor_start(line)
Start performance monitoring.
If an interval is provided as a single numeric argument, it is interpreted as the sampling interval in seconds; otherwise the default interval is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Optional interval argument, for example |
required |
Returns: None
Examples:
Start monitoring with the default interval::
%perfmonitor_start
Start monitoring with a 0.5 second interval::
%perfmonitor_start 0.5
Source code in jumper_extension/ipython/magics.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
perfmonitor_stop(line)
Stop the active performance monitoring session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Unused argument string. |
required |
Returns: None
Examples:
%perfmonitor_stop
Source code in jumper_extension/ipython/magics.py
129 130 131 132 133 134 135 136 137 138 139 140 141 | |
post_run_cell(result)
Hook executed after each cell has run.
Delegates to the magic adapter so that post-cell reporting and bookkeeping can be performed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Any
|
IPython execution result object. |
required |
Returns: None
Source code in jumper_extension/ipython/magics.py
73 74 75 76 77 78 79 80 81 82 83 84 | |
pre_run_cell(info)
Hook executed before each cell.
This inspects the raw cell source, extracts any magic commands, and informs the underlying adapter so that monitoring and reporting state can be updated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
Any
|
IPython pre-run information object that contains
|
required |
Returns: None
Source code in jumper_extension/ipython/magics.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
show_cell_history(line)
Show an interactive table of executed cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Unused argument string. |
required |
Returns: None
Examples:
%show_cell_history
Source code in jumper_extension/ipython/magics.py
368 369 370 371 372 373 374 375 376 377 378 379 380 | |
start_write_script(line)
Start recording code from subsequent cells to a Python script.
If no path is provided, the script writer chooses a default filename based on the current time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Optional output path, for example
|
required |
Examples:
Start recording to a generated filename::
%start_write_script
Record to a specific file::
%start_write_script my_script.py
Source code in jumper_extension/ipython/magics.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
IPython utilities
get_called_line_magics(raw_cell)
Get the list of line magics called in a cell
Source code in jumper_extension/ipython/utilities.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
is_pure_line_magic_cell(raw_cell)
A pure line-magic cell = each non-empty line is either:
- starts with %
Source code in jumper_extension/ipython/utilities.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |