Skip to content

feat(runtimed-py): add dependency management and kernel restart#586

Merged
rgbkrk merged 1 commit intomainfrom
quill/runtimed-py-deps
Mar 7, 2026
Merged

feat(runtimed-py): add dependency management and kernel restart#586
rgbkrk merged 1 commit intomainfrom
quill/runtimed-py-deps

Conversation

@rgbkrk
Copy link
Member

@rgbkrk rgbkrk commented Mar 7, 2026

Summary

Add comprehensive dependency management to the runtimed-py Python bindings, enabling agents to programmatically manage notebook environments just like the frontend does.

New capabilities:

  • Get/add/remove UV and Conda dependencies from notebook metadata
  • Restart kernel with new environment configuration
  • Hot-install UV packages via sync_environment() (UV additions only, no restart needed)

Changes

New Output Type

  • SyncEnvironmentResult: Represents outcome of environment sync operation with success, synced_packages, error, and needs_restart fields

New Methods on Session and AsyncSession (8 methods each)

  1. get_uv_dependencies() - Get current UV dependency list
  2. add_uv_dependency(package) - Add UV dependency (exact match), returns updated list
  3. remove_uv_dependency(package) - Remove UV dependency (exact match), returns updated list
  4. get_conda_dependencies() - Get current Conda dependency list
  5. add_conda_dependency(package) - Add Conda dependency (exact match), returns updated list
  6. remove_conda_dependency(package) - Remove Conda dependency (exact match), returns updated list
  7. restart_kernel(wait_for_ready=true) - Shutdown kernel and start new one with "auto" environment detection (picks up inline deps)
  8. sync_environment() - Hot-install UV packages via daemon sync protocol, returns SyncEnvironmentResult

Implementation Details

Dependency management:

  • Reads/writes notebook metadata via the daemon's metadata system
  • Dependencies stored in metadata.runt.uv.dependencies and metadata.runt.conda.dependencies
  • Uses exact string matching for add/remove (accepts full PEP 508 specs from user)

Kernel restart:

  • Calls shutdown_kernel() then start_kernel() with "auto" env_source
  • "auto" mode triggers daemon environment detection to pick up inline deps
  • Optionally waits for kernel to reach "idle" status (30s timeout)

Sync environment:

  • Implements daemon protocol for hot-installing UV packages without restart
  • Returns success/failure with detailed error and needs_restart flag
  • Only works for UV inline additions (removals/conda require full restart)

Dependencies

Added notebook-doc crate for NotebookMetadataSnapshot types needed to read/write metadata.

API Example

from runtimed import Session

# Add dependencies and restart
with Session() as session:
    session.start_kernel()
    session.add_uv_dependency("pandas>=2.0")
    session.add_uv_dependency("matplotlib")
    session.restart_kernel()
    result = session.run("import pandas; import matplotlib")

# Hot-install (UV only, no restart)
with Session() as session:
    session.start_kernel()
    session.add_uv_dependency("requests")
    sync_result = session.sync_environment()
    if sync_result.success:
        session.run("import requests")
    elif sync_result.needs_restart:
        session.restart_kernel()

Test Plan

  • Code compiles with cargo check -p runtimed-py
  • Code is formatted with cargo fmt -p runtimed-py
  • Manual verification in Python: call get/add/remove methods and verify metadata changes
  • Manual verification: restart_kernel() shuts down and starts new kernel
  • Manual verification: sync_environment() works for UV additions

Add comprehensive dependency management to runtimed-py Python bindings:
- Get/add/remove UV and Conda dependencies from notebook metadata
- Restart kernel with new environment configuration
- Hot-install UV packages via sync_environment() without restart

New methods on Session and AsyncSession:
- get_uv_dependencies() / add_uv_dependency() / remove_uv_dependency()
- get_conda_dependencies() / add_conda_dependency() / remove_conda_dependency()
- restart_kernel(wait_for_ready=true)
- sync_environment() -> SyncEnvironmentResult

Dependencies stored in notebook metadata (metadata.runt.uv.dependencies etc),
read/written through daemon metadata system. Exact string matching for add/remove.

Kernel restart uses shutdown + start with "auto" env_source to pick up inline deps.
Sync environment implements daemon protocol for hot-install (UV additions only).
@rgbkrk rgbkrk merged commit ab9519e into main Mar 7, 2026
14 checks passed
@rgbkrk rgbkrk deleted the quill/runtimed-py-deps branch March 7, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant