marimo icon indicating copy to clipboard operation
marimo copied to clipboard

Embedding notebooks with parent->child exposure

Open MaWeffm opened this issue 1 month ago • 6 comments

📝 Summary

This PR adds read-only and reactive exposure of parent variables to embedded children notebooks via app.embed(). The goal was to improve modularity and enable bi-directional communication of variables between parent notebooks and embedded children. This topic has been discussed in #5092 and #6918. I am not a professional software developer and this PR has been implemented with the help of ChatGPT5. I could not find any community rules against this but understand potential reservations. If this PR is not acceptable, I hope that I at least triggers a discussion about parent->child exposure of variables.

This implementation could likely be improved to add some syntactic sugar to simplify usage of this feature. I'd also appreciate constructive feedback on the implementation and this PR, thanks!

🔍 Description of Changes

This PR entails larger changes and extends App.embed() to accept three additional variables expose, namespace, and readonly. In notebook mode, the exposures are registered with the child runner before the first run. In script mode, a one-shot namespace is injected into globals without reactivity. InternalApp is extended to be able to schedule child updates and minimal reruns.

/_runtime/app/kernel_runner.py was extended to keep a registry of exposures for each runner by installing a read-only namespace object in the child kernel's globals.

/_runtime/runner/hooks_post_execution.py was extended by adding a post-execution hook that pushes updated parent defs into children and schedules minimal re-runs of those child cells that reference the namespace.

Examples were added to /examples/reactive_embedding/. See screenshots of code of a parent app and the two child apps it embeds below, and a video of the parent notebook in action further down:

child_1.py: Screenshot from 2025-10-29 21-54-30

child_2.py Screenshot from 2025-10-29 21-53-42

parent.py Screenshot from 2025-10-29 21-55-07

See the parent notebook in action below, the children notebooks run stand-alone, too:

Screencast from 2025-10-29 21-41-31.webm

📋 Checklist

  • [x ] I have read the contributor guidelines.
  • [ x] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • [ x] I have added tests for the changes made.
  • [ x] I have run the code and verified that it works as expected.

I have read the CLA Document and I hereby sign the CLA.

MaWeffm avatar Oct 29 '25 21:10 MaWeffm

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Nov 26, 2025 2:06pm

vercel[bot] avatar Oct 29 '25 21:10 vercel[bot]

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

github-actions[bot] avatar Oct 29 '25 21:10 github-actions[bot]

I have read the CLA Document and I hereby sign the CLA

MaWeffm avatar Oct 29 '25 21:10 MaWeffm

recheck

MaWeffm avatar Oct 29 '25 21:10 MaWeffm

Hey @MaWeffm - this is something we are interested in exploring for sure, but we haven't landed on the API / feature-set for this.

Our team can slot in some time this week to discuss how we want to prioritize this and what the solution should look like.

mscolnick avatar Nov 02 '25 20:11 mscolnick

Sounds fantastic, @mscolnick! Thank you for considering this!

MaWeffm avatar Nov 03 '25 12:11 MaWeffm