47fac22230
- .claude/CLAUDE.md - .claude/commands/subagentes.md - .claude/rules/INDEX.md - .mcp.json - bash/functions/cybersecurity/analyze_dns.md - bash/functions/cybersecurity/audit_http_headers.md - bash/functions/cybersecurity/audit_ssh_config.md - bash/functions/cybersecurity/check_firewall.md - bash/functions/cybersecurity/detect_suspicious_users.md - bash/functions/cybersecurity/encrypt_file.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3.8 KiB
3.8 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| jupyter_exec | function | py | notebook | 2.0.0 | impure | jupyter_append_execute(notebook_path: str, code: str, server_url: str, token: str) -> dict | Ejecuta codigo en kernels de Jupyter via REST + WebSocket clasico al kernel. Tres modos: append (añade celda y ejecuta), cell (ejecuta celda existente), kernel (ejecuta sin tocar notebook). NO usa el canal colaborativo Y.js. |
|
false | error_go_core |
|
|
Dict con cell_index y outputs del código ejecutado, o resultados del kernel | true |
|
python/functions/notebook/tests/test_jupyter_exec.py | python/functions/notebook/jupyter_exec.py |
Funciones
jupyter_append_execute(notebook_path, code, server_url, token)
Añade una celda de codigo al final del notebook, la ejecuta en el kernel y persiste
celda + outputs a disco via REST /api/contents. Jupyter Lab detecta el cambio y lo
refleja en el browser.
from notebook.jupyter_exec import jupyter_append_execute
result = jupyter_append_execute(
"notebooks/analisis.ipynb",
"import pandas as pd\nprint(pd.__version__)",
server_url="http://localhost:8888",
token="",
)
# {"cell_index": 5, "outputs": ["2.2.1"]}
jupyter_execute_cell(notebook_path, cell_index, server_url, token)
Ejecuta una celda existente por indice (0-based) y persiste sus outputs.
result = jupyter_execute_cell("notebooks/analisis.ipynb", 3)
# {"cell_index": 3, "outputs": ["42"]}
jupyter_kernel_execute(code, server_url, token)
Ejecuta codigo directo en el kernel sin tocar ningun notebook.
result = jupyter_kernel_execute("len(df)")
# {"outputs": ["1500"], "status": "ok"}
CLI
python -m notebook.jupyter_exec append notebooks/mi.ipynb "print('hola')"
python -m notebook.jupyter_exec cell notebooks/mi.ipynb 2
python -m notebook.jupyter_exec kernel "x = 42; print(x)"
Output siempre JSON. En error retorna {"error": "..."} por stderr con exit code 1.
Extraccion de outputs
| output_type | campo leido |
|---|---|
| stream | text |
| display_data / execute_result | data.text/plain |
| error | traceback (joined con \n) |
Notas (v2.0.0 — fix Issue 0050)
- Bypassa el canal colaborativo Y.js. Usa REST
/api/contentspara leer/escribir celdas yKernelClient(websocket clasico al kernel) para ejecutar. Robusto frente a versiones nuevas dejupyter-collaborationque rompianNbModelClient. - Trade-off: las celdas/outputs se persisten a disco, no se sincronizan en tiempo real via Y.js. Jupyter Lab detecta el cambio en el filesystem y lo refleja (puede pedir 'Revert to disk' segun version).
_notebook_existsusaGET /api/contents?content=0(HEAD devuelve 405 en Jupyter Server).- Auto-init:
jupyter_append_executecrea el notebook si no existe y arranca una sesion con kernel si no hay ninguna activa para ese notebook. - El token puede ser cadena vacia si el servidor tiene autenticacion deshabilitada.