<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Jupyter Blog - xeus</title><link href="https://blog.jupyter.org/" rel="alternate"/><link href="https://blog.jupyter.org/feeds/tag-xeus.atom.xml" rel="self"/><id>https://blog.jupyter.org/</id><updated>2026-10-01T04:00:00+00:00</updated><subtitle>Xeus, the C++ library for writing Jupyter kernels.</subtitle><entry><title>From Punch Cards to the Browser: Fortran Comes to JupyterLite</title><link href="https://blog.jupyter.org/posts/2026/from-punch-cards-to-the-browser-fortran-comes-to-jupyterlite/" rel="alternate"/><published>2026-10-01T04:00:00+00:00</published><updated>2026-10-01T04:00:00+00:00</updated><author><name>Anutosh Bhat</name></author><id>tag:blog.jupyter.org,2026-10-01:/posts/2026/from-punch-cards-to-the-browser-fortran-comes-to-jupyterlite/</id><summary type="html">&lt;p&gt;The LFortran kernel now runs entirely in your browser, with no installation and no server.&lt;/p&gt;
</summary><content type="html">&lt;figure&gt;
&lt;img alt="Fortran card" src="https://blog.jupyter.org/posts/2026/from-punch-cards-to-the-browser-fortran-comes-to-jupyterlite/images/r1z7339YGg.jpg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Punched card from a Fortran program Z(1) = Y + W(1), plus sorting information in the last 8 columns - Arnold Reinhold, &lt;a href="https://en.wikipedia.org/wiki/Punched_card#/media/File:FortranCardPROJ039.agr.jpg"&gt;Wikimedia Commons&lt;/a&gt;, CC BY-SA 2.5&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="a-language-for-people-who-think-in-formulas"&gt;A language for people who think in formulas&lt;/h2&gt;
&lt;p&gt;In the early 1950s, programming meant writing numerical machine instructions by hand, one row at a time. John Backus, who led the effort that changed this at IBM, described the experience as “hand-to-hand combat with the machine.”&lt;/p&gt;
&lt;p&gt;In 1953 he proposed a different bargain: let scientists write programs the way they already wrote their mathematics — &lt;em&gt;as formulas&lt;/em&gt; — and let a machine do the translating. The skeptics said it could not work. Memory was scarce, computer time was precious, and code produced from anything readable by humans could surely never rival code crafted by hand. Three years later, in April 1957, IBM delivered the first &lt;strong&gt;FORTRAN&lt;/strong&gt; compiler for the IBM 704, and the skeptics were answered by the world’s first optimizing compiler, whose output ran nearly as fast as anything a hand-coder could produce.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2026/from-punch-cards-to-the-browser-fortran-comes-to-jupyterlite/images/BJpwuIKFGg.webp" alt="Fortran_logo.svg" width="200" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;The name was the whole idea: &lt;strong&gt;FORmula TRANslation&lt;/strong&gt;. Fortran let scientists and engineers work in the vocabulary of their own fields — arrays, floating-point numbers, complex arithmetic — rather than in registers and opcodes. It became the first programming language to be standardized, in 1966, and it has been actively maintained to this day (latest standard is 2023, next one in progress, targeted for 2028). Much of the software that runs on the world’s fastest computers is written in Fortran, and the dense numerical libraries that other languages call for their heavy lifting, LAPACK most prominently, are written in it too. If you have solved a linear system today, in Python or R or Julia, there is a decent chance Fortran did the work.&lt;/p&gt;
&lt;h2 id="the-other-half-of-scientific-computing"&gt;The other half of scientific computing&lt;/h2&gt;
&lt;p&gt;But Fortran was born in the batch era. Running a program meant keypunching a deck of cards, handing it to an operator, and coming back hours later, or the next day, to find out whether it had run at all. Computing meant deciding everything in advance.&lt;/p&gt;
&lt;p&gt;A second tradition grew out of the opposite frustration: computing as a conversation. Type an expression, look at the result, adjust, repeat. That impulse ran through time-sharing terminals, through Mathematica and MATLAB, and into IPython, first released in 2001, which grew into &lt;strong&gt;Project Jupyter&lt;/strong&gt;. The notebook, with code, results, and prose in a single living document, is now the default home of exploratory data analysis and computational science, and Jupyter’s architecture is deliberately language-agnostic: any language can implement a kernel and join the conversation. Python, Julia, and R most visibly; C++, Lua, and others besides.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2026/from-punch-cards-to-the-browser-fortran-comes-to-jupyterlite/images/Hkqa_LFYzx.webp" alt="labpreview" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;In notebooks, though, Fortran has been present but invisible: the compiled layer underneath NumPy and its cousins, reached through wrappers, glimpsed only when a profiler points at it. The language in which so much of numerical computing is actually written has rarely been the language you can sketch an idea in.&lt;/p&gt;
&lt;h2 id="interactive-fortran"&gt;Interactive Fortran&lt;/h2&gt;
&lt;p&gt;That is the gap &lt;strong&gt;LFortran&lt;/strong&gt; was built to close. LFortran is a modern, open-source (BSD-licensed) Fortran compiler built on LLVM, an optimizing compiler infrastructure several generations on from the one Backus’s team delivered for the IBM 704.  The question that compiler settled, whether code written for humans could run as fast as code written for the machine, is one its descendants answer routinely; what they rarely offer is a conversation.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2026/from-punch-cards-to-the-browser-fortran-comes-to-jupyterlite/images/S1XHFUKFfg.webp" alt="lfortran" width="200" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;What LFortran adds is exactly that second mode: alongside compiling Fortran to fast binaries for production work, it can evaluate code interactively, statement by statement, much like Python, Julia, or MATLAB.&lt;/p&gt;
&lt;p&gt;Once a language has an interpreter, a Jupyter kernel is a small step away: from the language’s point of view, the kernel’s job is only to receive a cell of code and return its results. LFortran has shipped with such a kernel for some time. It is built on &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;&lt;strong&gt;xeus&lt;/strong&gt;&lt;/a&gt;, a C++ implementation of the Jupyter kernel protocol that already powers a long list of kernels, including xeus-python, xeus-cling, and xeus-r. The protocol plumbing is taken care of, so the kernel can concentrate on Fortran itself, and a single &lt;code&gt;conda install -c conda-forge lfortran&lt;/code&gt; gives you both the compiler and the kernel.&lt;/p&gt;
&lt;h2 id="taking-the-kernel-to-the-browser"&gt;Taking the kernel to the browser&lt;/h2&gt;
&lt;p&gt;Today we are announcing &lt;a href="https://jupyterlite.readthedocs.io"&gt;JupyterLite&lt;/a&gt; support: the LFortran kernel now runs in &lt;strong&gt;JupyterLite&lt;/strong&gt;, a JupyterLab distribution that runs entirely in the browser. JupyterLite is served as a static website, with no Jupyter server, no container, and nothing provisioned on any machine.&lt;/p&gt;
&lt;p&gt;This matters because it changes not just what a notebook is, but how it can be shared. A notebook becomes something you can publish like any web page: static, lightweight, and infinitely scalable. Whether you’re hosting it on GitHub Pages, a university server, or a personal blog, you can serve thousands of users with minimal resources. There is no backend to manage, no accounts to create, no queues to wait in. The gap between “here is a notebook” and “here, try it” disappears, and with it, many of the barriers that have traditionally limited access to computational tools.&lt;/p&gt;
&lt;p&gt;This makes JupyterLite ideal for education, where students can experiment with code without installing anything; for live documentation, where readers can tweak and run examples from a project’s docs; and for citizen science, where communities can collaborate on data analysis without specialized infrastructure. Fortran, a language built for heavy computation, is now as accessible as a webpage.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2026/from-punch-cards-to-the-browser-fortran-comes-to-jupyterlite/images/Hkuk5Ittfg.webp" alt="1_1mHVBUr6tB3TP0Z1ujvdjw" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;Building the kernel on xeus carried it most of the way to the browser. The same xeus kernel code that ships on conda-forge for the desktop is built for WebAssembly by emscripten-forge and loaded into JupyterLite by jupyterlite-xeus, and many of the JupyterLite kernels available today are xeus kernels: Python, R, C++, Lua. The desktop and browser kernels are the same code.&lt;/p&gt;
&lt;p&gt;The last obstacle was the interesting one. In interactive mode, LFortran leans on LLVM’s just-in-time compilation: each cell is compiled as it arrives and executed on the spot. A browser will not do that. WebAssembly keeps code and data in separate address spaces, so a program cannot write machine code into its own memory and then jump to it, and the classic JIT move is unavailable. What the browser does allow is loading a module: new code enters a running WebAssembly program by being handed to the host and instantiated, never by being written into memory. The problem becomes one of routing the compiler’s output through that door.&lt;/p&gt;
&lt;p&gt;This is the wall xeus-cpp hit when it brought the clang-repl C++ interpreter to WebAssembly, and the solution here is the one devised there. Instead of executing generated code in place, the kernel passes it to the WebAssembly toolchain, itself compiled to WebAssembly and running in the same tab, which links it into a side module (the browser’s equivalent of a shared library) and loads it into the running kernel. Parsing, compilation, and linking all happen in the browser; the notebook’s program grows one module at a time.&lt;/p&gt;
&lt;h2 id="try-it"&gt;Try it&lt;/h2&gt;
&lt;p&gt;You can try it right now on &lt;a href="https://notebook.link"&gt;notebook.link&lt;/a&gt;, with nothing but a browser. Just click &lt;a href="https://notebook.link/@anutosh491/fortran"&gt;HERE&lt;/a&gt;! The demo ships with a handful of notebooks to start from, including a Mandelbrot example and one showing rich display output — plots and images rendered straight from Fortran cells.&lt;/p&gt;
&lt;p&gt;The kernel itself is available as a package on &lt;a href="https://emscripten-forge.org/"&gt;&lt;strong&gt;emscripten-forge&lt;/strong&gt;&lt;/a&gt;, a software distribution for WebAssembly. That means Fortran is now just another entry in an &lt;code&gt;environment.yml&lt;/code&gt;: any JupyterLite deployment built with jupyterlite-xeus can include it. The deployment is a static site you can host anywhere (GitHub Pages, a blog) with no server costs and no limits on the number of users. For a Fortran project, this could mean embedding live, executable examples directly in your documentation, letting users experiment with your code without ever leaving the browser.&lt;/p&gt;
&lt;p&gt;For a regular Jupyter installation, the kernel is still available the classic way:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;conda&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;-c&lt;span class="w"&gt; &lt;/span&gt;conda-forge&lt;span class="w"&gt; &lt;/span&gt;lfortran&lt;span class="w"&gt; &lt;/span&gt;jupyterlab
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="inside-the-lfortran-compiler"&gt;Inside the LFortran compiler&lt;/h2&gt;
&lt;p&gt;Another reason why LFortran is a particularly good fit for the notebook workflow lies in its compiler pipeline: its Abstract Semantic Representation, or ASR. While the AST records the syntax the user wrote, ASR records what the program means, with types, symbols, procedure interfaces, and other semantic information made explicit. LFortran can therefore perform high-level, Fortran-aware transformations on a valid program before lowering it to LLVM IR, leaving LLVM to handle lower-level optimization and code generation.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;Fortran source → AST → ASR → LLVM IR → native code / WebAssembly
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For interactive use, each notebook cell has its own ASR translation unit. Its symbol table points to the translation unit from the preceding cell, forming a chain through the session. A cell can therefore use variables, modules, and procedures defined earlier, while redefining a name shadows the old definition instead of modifying code that has already been compiled. Cell-level symbols are given distinct generated names, allowing old and new definitions to remain alive at the same time. Once the current cell has been lowered to an LLVM module, it is handed to the native On Request Compilation (ORC) JIT or to the browser executor described above.&lt;/p&gt;
&lt;h2 id="epilogue"&gt;Epilogue&lt;/h2&gt;
&lt;p&gt;When Fortran arrived in 1957, using it meant punching cards, standing in line at the keypunch and the card reader, and waiting for the batch to come back around. Today it means opening a URL, typing a few lines, and pressing Shift+Enter. The formulas look much the same as they did sixty-nine years ago.&lt;/p&gt;
&lt;p&gt;What changed is everything around them.&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="about-the-authors"&gt;About the authors&lt;/h2&gt;
&lt;p&gt;&lt;img src="https://blog.jupyter.org/posts/2026/from-punch-cards-to-the-browser-fortran-comes-to-jupyterlite/images/BJVhjIFtze.jpg" alt="ondrej" width="150" loading="lazy" data-body-image=""&gt;&lt;br&gt;
&lt;a href="https://ondrejcertik.com"&gt;Ondřej Čertík&lt;/a&gt; is the creator of LFortran, which he started in 2017 and has led ever since; he is also the original author of SymPy and SymEngine, a co-founder of the fortran-lang community, and a Principal Software Engineer at Microsoft.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.jupyter.org/posts/2026/from-punch-cards-to-the-browser-fortran-comes-to-jupyterlite/images/SJ5tjLFtfl.jpg" alt="1_NpDAN0ssTEugOAgQJ279xA" width="150" loading="lazy" data-body-image=""&gt;&lt;br&gt;
&lt;a href="https://github.com/anutosh491"&gt;Anutosh Bhat&lt;/a&gt; did the work of bringing this kernel to the browser: he ported both xeus-cpp and the Fortran kernel to WebAssembly, and iterated extensively on the kernel itself. Anutosh is a scientific software engineer at QuantStack, an LLVM maintainer, and a co-author of xeus-cpp; his contributions span clang-repl, LLVM’s WebAssembly backend, and their packaging for emscripten-forge.&lt;/p&gt;
&lt;h2 id="acknowledgements"&gt;Acknowledgements&lt;/h2&gt;
&lt;p&gt;The work by Anutosh on the porting the LFortran kernel to WebAssembly was funded by &lt;a href="https://quantstack.net"&gt;QuantStack&lt;/a&gt;, the team behind JupyterLite, xeus, and the emscripten-forge distribution.&lt;/p&gt;
&lt;p&gt;LFortran itself is the product of many years of sustained work by more than 130 contributors, made possible by the support of the &lt;a href="https://www.sovereign.tech/"&gt;Sovereign Tech Agency&lt;/a&gt;; Los Alamos National Laboratory, which supported its early development; GSI Technology; FLOSS/fund; QuantStack; John D. Cook; NumFOCUS; and Google Summer of Code, through which many contributors first joined the project. We also thank the individuals and organizations who have sponsored LFortran through GitHub and OpenCollective.&lt;/p&gt;
</content><category term="JupyterLite"/><category term="kernels"/><category term="WebAssembly"/><category term="xeus"/></entry><entry><title>GNU Octave Meets JupyterLite: Compute Anywhere, Anytime!</title><link href="https://blog.jupyter.org/posts/2025/gnu-octave-meets-jupyterlite-compute-anywhere-anytime/" rel="alternate"/><published>2025-10-16T15:04:00+00:00</published><updated>2025-10-16T15:04:00+00:00</updated><author><name>Isabel Paredes</name></author><id>tag:blog.jupyter.org,2025-10-16:/posts/2025/gnu-octave-meets-jupyterlite-compute-anywhere-anytime/</id><summary type="html">&lt;p&gt;We are thrilled to announce the newest member of our JupyterLite kernel ecosystem: Xeus-Octave. Xeus-Octave allows you to run GNU Octave code directly on your browser. GNU Octave is a free and open-source Scientific Programming Language that can be used to run Matlab scripts.&lt;/p&gt;</summary><content type="html">&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2025/gnu-octave-meets-jupyterlite-compute-anywhere-anytime/images/001-1__Ha5vHmLH66mSH3WFg1fxg.jpg" alt="Octave-lite logo" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;We are thrilled to announce the newest member of our JupyterLite kernel ecosystem: &lt;strong&gt;Xeus-Octave&lt;/strong&gt;. Xeus-Octave allows you to run GNU Octave code directly on your browser. GNU Octave is a free and open-source Scientific Programming Language that can be used to run Matlab scripts. In this article, we present the challenges encountered when targeting WebAssembly, the current state of the Xeus-Octave kernel, and the future plans for expanding the GNU Octave ecosystem.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Earlier this year, we introduced the JupyterLite kernel for R, &lt;a href="https://blog.jupyter.org/posts/2025/r-in-the-browser-announcing-our-webassembly/"&gt;&lt;strong&gt;Xeus-R-Lite&lt;/strong&gt;&lt;/a&gt;. Much like R, cross-compiling GNU Octave to WebAssembly required the same custom toolchain to enable the compilation of Fortran code, combining LLVM Flang and Emscripten.&lt;/p&gt;
&lt;p&gt;Similar to many other mathematically oriented language packages, GNU Octave requires a BLAS/LAPACK implementation. Fortunately, OpenBLAS and the Netlib implementations of BLAS/LAPACK had already been added to the emscripten-forge WebAssembly distribution. Initially, OpenBLAS was the preferred implementation, but for the successful compilation of Octave, Netlib LAPACK was selected as it presented fewer hurdles during the build process.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="cross-compilation-of-gnu-octave"&gt;Cross-Compilation of GNU Octave&lt;/h2&gt;
&lt;p&gt;One of the complications of cross-compiling Octave to WebAssembly, which had not been encountered with the R source code, was the extensive use of Fortran common symbols blocks in the internal libraries of Octave such as odepack.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;liboctave&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;external&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;odepack&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;slsode&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;
&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="o"&gt;-----------------------------------------------------------------------&lt;/span&gt;
&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;The&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;following&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;internal&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Common&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;contains&lt;/span&gt;
&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;variables&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;which&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;are&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;any&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;subroutine&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;but&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;whose&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;must&lt;/span&gt;
&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="n"&gt;be&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;preserved&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;between&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;calls&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;routine&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;own&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ow"&gt;and&lt;/span&gt;
&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;variables&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;which&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;are&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;communicated&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;between&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;subroutines&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;The&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;SLS001&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;is&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;declared&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ow"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;subroutines&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;SLSODE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;SINTDY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;SSTODE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;SPREPJ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ow"&gt;and&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;SSOLSY&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Groups&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;of&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;variables&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;are&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;replaced&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;by&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;dummy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;arrays&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ow"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Common&lt;/span&gt;
&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;declarations&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ow"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;routines&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;those&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;variables&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;are&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ow"&gt;not&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;used&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="o"&gt;-----------------------------------------------------------------------&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="n"&gt;COMMON&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;SLS001&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;CONIT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;CRATE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;EL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ELCO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;HOLD&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;RMAX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;TESCO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;CCMAX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;EL0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;H&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;HMIN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;HMXI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;HU&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;RC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;TN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;UROUND&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;INIT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MXSTEP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MXHNIL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;NHNIL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;NSLAST&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;NYH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;IALTH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IPUP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;LMAX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MEO&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;NQNYH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;NSLP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;ICF&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IERPJ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;IERSL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;JCUR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;JSTART&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;KFLAG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;L&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;LYH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;LEWT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;LACOR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;LSAVF&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;LWM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;LIWM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;METH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MITER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;MAXORD&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MAXCOR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MSBP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;MXNCF&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;NQ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;NST&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;NFE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;NJE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;NQU&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Initially, it was not possible to cross-compile these common blocks to WebAssembly because the latest version of LLVM (v20 at the time of testing) did not support common symbol linkage.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="c1"&gt;// Source: llvm/lib/MC/MCWasmStreamer.cpp&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;MCWasmStreamer::emitCommonSymbol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MCSymbol&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;uint64_t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                      &lt;/span&gt;&lt;span class="n"&gt;Align&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ByteAlignment&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;llvm_unreachable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Common symbols are not yet implemented for Wasm&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As a temporary solution, LLVM was patched with the help of &lt;a href="https://github.com/serge-sans-paille"&gt;Serge Guelton&lt;/a&gt; to simulate common symbols as weak symbols.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;void MCWasmStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
&lt;span class="w"&gt; &lt;/span&gt;                                     Align ByteAlignment) {
&lt;span class="gd"&gt;-  llvm_unreachable(&amp;quot;Common symbols are not yet implemented for Wasm&amp;quot;);&lt;/span&gt;
&lt;span class="gi"&gt;+  auto *Symbol = cast&amp;lt;MCSymbolWasm&amp;gt;(S);&lt;/span&gt;
&lt;span class="gi"&gt;+  getAssembler().registerSymbol(*Symbol);&lt;/span&gt;
&lt;span class="gi"&gt;+  Symbol-&amp;gt;setWeak(true);&lt;/span&gt;
&lt;span class="gi"&gt;+  Symbol-&amp;gt;setExternal(true);&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A proper solution to enable support of common symbols is currently in progress and will likely be included in the next release of LLVM v22 (see &lt;a href="https://github.com/llvm/llvm-project/pull/151478"&gt;llvm-project/pull/151478&lt;/a&gt;). For curious readers, the patched version of LLVM can be found &lt;a href="https://github.com/IsabelParedes/llvm-project/releases/download/v20.1.7_emscripten-wasm32/llvm_emscripten-wasm32-20.1.7-h2e33cc4_5.tar.bz2"&gt;here&lt;/a&gt; (linux only).&lt;/p&gt;
&lt;p&gt;In addition to the patches for LLVM, GNU Octave required a few minor modifications to target WebAssembly; mainly this entailed disabling the GUI functionalities and consolidating the Fortran function signatures and calling conventions. A full list of patches can be found in the &lt;a href="https://github.com/emscripten-forge/recipes/tree/main/recipes/recipes_emscripten/octave/patches"&gt;recipe directory&lt;/a&gt; on emscripten-forge.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="xeus-octave"&gt;Xeus-Octave&lt;/h2&gt;
&lt;p&gt;Once GNU Octave had been successfully packaged for WebAssembly, bringing &lt;a href="https://github.com/jupyter-xeus/xeus-octave"&gt;Xeus-Octave&lt;/a&gt; to JupyterLite was a simple matter of adding a recipe to &lt;a href="https://github.com/emscripten-forge/recipes/"&gt;emscripten-forge&lt;/a&gt;!&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="A JupyterLite notebook demonstrating plots with Xeus-Octave" src="https://blog.jupyter.org/posts/2025/gnu-octave-meets-jupyterlite-compute-anywhere-anytime/images/002-1_lKsfXJGc7_tM1ONU5Ej0Ng.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;&lt;a href="https://jupyter-xeus.github.io/xeus-octave/lab/?path=xeus-octave-wasm.ipynb"&gt;&lt;strong&gt;Try Xeus-Octave in JupyterLite!&lt;/strong&gt;&lt;/a&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;hr&gt;
&lt;h2 id="future-work"&gt;Future Work&lt;/h2&gt;
&lt;p&gt;For our next steps, the team is planning on expanding the Octave ecosystem by adding Octave packages to both conda-forge and emscripten-forge. The packaging work will require defining a process where Octave packages can be installed in predetermined conda environments, perhaps with some minor modifications to the existing pkg utility.&lt;/p&gt;
&lt;hr&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="about-the-author"&gt;About the Author&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Isabel Paredes&lt;/strong&gt;, who led the charge on bringing GNU Octave to emscripten-forge, is a senior scientific software developer at QuantStack. Prior to working on this project, she focused on porting the R programming language and the Robot Operating System (ROS) framework to WebAssembly.&lt;/p&gt;
&lt;h2 id="acknowledgments"&gt;Acknowledgments&lt;/h2&gt;
&lt;p&gt;This project synthesizes work from many open-source contributors.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/emscripten-forge/recipes/"&gt;&lt;strong&gt;Emscripten-forge&lt;/strong&gt;&lt;/a&gt;, the distribution of conda packages for WebAssembly, was created by Thorsten Beier, who continues to lead the project. Many recipes were contributed by Isabel Paredes, Anutosh Bhat, Martin Renou, Ian Thomas, Wolf Vollprecht, and Johan Mabille.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jupyterlite.readthedocs.io/en/stable/?badge=latest"&gt;&lt;strong&gt;JupyterLite&lt;/strong&gt;&lt;/a&gt;, the Jupyter distribution that runs entirely in the web browser, was created by Jeremy Tuloup.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyter-xeus/xeus"&gt;&lt;strong&gt;Xeus&lt;/strong&gt;&lt;/a&gt;, the C++ library implementing the Jupyter kernel protocol, enabling a custom communication layer, and is foundational to kernels like xeus-r, xeus-python, running in JupyterLite, was created by Johan Mabille and is maintained by a broader team including Martin Renou, Sylvain Corlay, and Thorsten Beier, who worked on the first integration with JupyterLite.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-octave"&gt;&lt;strong&gt;Xeus-Octave&lt;/strong&gt;&lt;/a&gt;, the Xeus-based Jupyter kernel for GNU Octave, was created by Giulio Girardi and Antoine Prouvost.&lt;/li&gt;
&lt;/ul&gt;
</content><category term="JupyterLite"/><category term="kernels"/><category term="WebAssembly"/><category term="xeus"/></entry><entry><title>C++ in Jupyter — Interpreting C++ in the Web</title><link href="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/" rel="alternate"/><published>2025-06-19T15:29:00+00:00</published><updated>2025-06-19T15:29:00+00:00</updated><author><name>Anutosh Bhat</name></author><id>tag:blog.jupyter.org,2025-06-19:/posts/2025/c-in-jupyter-interpreting-c-in-the-web/</id><summary type="html">&lt;p&gt;A Jupyter kernel for C++ running in the Web browser&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Scientists and engineers utilize programming languages not only to build software systems but also to drive interactive exploratory workflows. They leverage developer tools to explore and reason through problems effectively. This process involves executing code, examining visualizations, loading data, and running additional code. Rapid iteration is particularly crucial during the exploratory phase of any technical project.&lt;/p&gt;
&lt;p&gt;For this reason, the most popular tools for exploratory work tend to be interpreted languages, such as Python or R. The “Read-Eval-Print-Loop” (REPL) places the user at the center of these iterative workflows. While compiled languages such as C++ are essential for performance-sensitive applications, engineers accustomed to interactive tools often struggle in such environments.&lt;/p&gt;
&lt;p&gt;At CERN, the C++ programming language has been pivotal to their data analysis platform for particle physics, notably in the ROOT framework. ROOT is underpinned by the Cling C++ interpreter, which is built on the Clang and LLVM stack. The Cling interpreter, co-created by Vassil Vassilev and Axel Naumann in the 2010s, effectively turned C++ into an agile scientific scripting language!&lt;/p&gt;
&lt;p&gt;These interactive workflows are where the Jupyter stack shines compared to traditional IDEs. Indeed, the Jupyter project was designed with exploratory computing in mind. Crucially, it was built from the ground up to be language-agnostic, accommodating multiple programming languages seamlessly. In 2017, the Xeus-Cling Jupyter kernel &lt;a href="https://blog.jupyter.org/posts/2017/interactive-workflows-for-c-with-jupyter/"&gt;was announced&lt;/a&gt;. Developed by Sylvain Corlay, Johan Mabille and Loic Gouarin, it integrated Cling in the Jupyter ecosystem, taking advantage of the rich features of Jupyter, such as rich mime type display and interactive widgets.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="An example C++ Jupyter notebook powered by the original Xeus-Cling kernel" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/001-0_WCAlh5DEa7IT27u3.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;An example C++ Jupyter notebook powered by the original Xeus-Cling kernel&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Packaging the Cling project proved challenging as it required patching the code base of Clang, and was not released as frequently as the LLVM stack, causing difficulties with rolling software distributions like conda-forge.&lt;/p&gt;
&lt;p&gt;In an effort led by Cling co-creator Vassil Vassilev, the &lt;a href="https://clang.llvm.org/docs/ClangRepl.html"&gt;Clang-Repl&lt;/a&gt; project was born, which consists in building the foundations for interactive C++ in the core of Clang. Clang-Repl has been undergoing active development for a few years now and a Jupyter kernel for Clang-Repl, &lt;a href="https://github.com/compiler-research/xeus-cpp"&gt;Xeus-Cpp&lt;/a&gt;, has also been developed, providing a similar set of features to Xeus-Cling.&lt;/p&gt;
&lt;p&gt;Building the new C++ kernel upon Xeus was crucial as it enabled the porting of the C++ kernel to the Web browser with JupyterLite.&lt;/p&gt;
&lt;h2 id="scaling-jupyter-with-jupyterlite"&gt;Scaling Jupyter with JupyterLite&lt;/h2&gt;
&lt;p&gt;The standard approach for Jupyter-based computing relies on providing each user with computing resources in the backend. Serving a few thousand end users necessitates substantial resources and complex deployment strategies.&lt;/p&gt;
&lt;p&gt;The JupyterLite project shifts this paradigm by running code directly in the user’s Web browser, by relying on a WebAssembly build of the kernel and required libraries. This eliminates the linear relationship between the number of users and the required resources.&lt;/p&gt;
&lt;p&gt;For instance, the NumPy.org website features a JupyterLite code console on its main page, offering a computational environment to thousands of monthly visitors without incurring any cloud costs. Similarly, the Capytale deployment of Jupyter, used in French high schools, operates on the same model. It accounts for over half a million registered users and hosts more than 200,000 user sessions weekly.&lt;/p&gt;
&lt;p&gt;In order to provide a broad range of packages and libraries for this new platform, the &lt;a href="https://jupyterlite.readthedocs.io/en/stable/"&gt;JupyterLite&lt;/a&gt; team at &lt;a href="https://quantstack.net/"&gt;QuantStack&lt;/a&gt; developed the &lt;a href="https://emscripten-forge.org/"&gt;Emscripten-forge&lt;/a&gt; distribution, utilizing the conda package manager for creating WebAssembly environments. Emscripten-forge comprises the main packages of the Python scientific computing ecosystem, as well as the R programming language, and several command-line applications powering the JupyterLite terminal.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Today, we are proud to announce that Xeus-Cpp and LLVM are available in emscripten-forge, effectively enabling interpreted C++ in the browser.&lt;/em&gt;&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="The new C++ Jupyter kernel in action in JupyterLite." src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/002-0_XLTuIN3E7_64kPcO.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The new C++ Jupyter kernel in action in JupyterLite.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Feel free to try it out in your browser by clicking the link below!&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://compiler-research.org/xeus-cpp-wasm/lab/index.html"&gt;&lt;img src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/003-1_gNg6NzVjE9nwIF9PSdt-jA.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We now dive into the details on the internals of the WebAssembly build of Xeus-Cpp, and the key features of the project.&lt;/p&gt;
&lt;h2 id="walking-up-the-stack"&gt;Walking up the stack&lt;/h2&gt;
&lt;h3 id="emulated-just-in-time-compilation-and-webassembly"&gt;Emulated Just-in-Time Compilation and WebAssembly&lt;/h3&gt;
&lt;p&gt;A fundamental challenge inherent to the WebAssembly is that it operates in a &lt;strong&gt;sandboxed Harvard architecture&lt;/strong&gt;: code and data reside in completely distinct memory spaces. This makes conventional &lt;strong&gt;JIT compilation&lt;/strong&gt; unfeasible in the browser, as it prohibits dynamic modification of executable memory.&lt;/p&gt;
&lt;p&gt;The WebAssembly backend for Clang-Repl was introduced during the LLVM 17 development cycle, with the introduction of a WASM-specific &lt;strong&gt;IncrementalExecutor&lt;/strong&gt;, sidestepping the standard LLVM JIT approach used on native platforms. This new &lt;strong&gt;WasmIncrementalExecutor&lt;/strong&gt; class handled the WebAssembly-specific execution model as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The LLVM IR from the REPL’s Partial Translation Unit (PTU) is compiled into an object file.&lt;/li&gt;
&lt;li&gt;This object file is passed to wasm-ld with flags to generate a standalone WebAssembly module.&lt;/li&gt;
&lt;li&gt;The resulting .wasm module acts as a dynamically linked side module, designed to be loaded on top of a persistent main module at runtime.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These side modules, while similar to shared libraries, are treated as auxiliary WASM modules that are dynamically attached to the main application using Emscripten’s dlopen mechanism. They share memory with the main module and can resolve symbols defined in previous executions. As a result, each REPL input produces a corresponding .wasm module that is compiled, linked, and loaded at runtime, incrementally extending the current execution environment.&lt;/p&gt;
&lt;p&gt;Following the initial version in LLVM 17, the support for WebAssembly was incrementally consolidated by a series of pull requests addressing various issues and corner cases with respect to symbol duplication, memory corruption, and dynamic linking failures. We believe the version available today in LLVM 20 is a solid foundation to build upon.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/llvm/llvm-project/pull/86402"&gt;PR #86402 — Initial WebAssembly support for clang-repl&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/llvm/llvm-project/pull/113446"&gt;PR #113446 — Fix undefined lld::wasm::link symbol&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/llvm/llvm-project/pull/116735"&gt;PR #116735 — Improve flags responsible for generating shared wasm binaries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/llvm/llvm-project/pull/117978"&gt;PR #117978 — Fix generation of wasm binaries&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/llvm/llvm-project/pull/118107"&gt;PR #118107 — Remove redundant shared flag while running clang-repl in browser&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For a deeper understanding of the constraints of the WebAssembly platform for JIT compilation, refer to the GSOC report: &lt;a href="https://compiler-research.org/assets/presentations/Anubhab_Ghosh_wasm_clangrepl.pdf"&gt;Anubhab Ghosh — WASM Clang-Repl&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id="porting-xeus-cpp-to-emscripten-forge"&gt;Porting Xeus-Cpp to Emscripten-forge&lt;/h3&gt;
&lt;p&gt;In addition to challenges with emulating JIT compilation in WebAssembly, packaging Xeus-Cpp for emscripten-forge presented another challenge: managing shared objects within the initial WebAssembly executable, which are typically built statically for other xeus kernels. This issue was addressed in the following PRS:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyterlite/xeus/pull/145"&gt;PR #145 — Handle .data file for kernels that require preloading&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyterlite/xeus/pull/146"&gt;PR #146 - Kernel shared libs handling&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As a result of this work, required side modules are now specified as metadata in the Jupyter kernelspec &lt;a href="https://github.com/compiler-research/xeus-cpp/blob/main/share/jupyter/kernels/xcpp23/wasm_kernel.json.in#L12"&gt;kernel.json&lt;/a&gt; file, enabling JupyterLite to automatically detect and utilize them.&lt;/p&gt;
&lt;h2 id="features"&gt;Features&lt;/h2&gt;
&lt;h3 id="inline-documentation"&gt;Inline documentation&lt;/h3&gt;
&lt;p&gt;To fully integrate C++ as a first-class citizen within the Jupyter ecosystem, supporting inline documentation is crucial. Similar to the Python kernel, utilizing the ? magic command should allow users to inspect the following type, perform a lookup in the available documentation, and display the relevant information.&lt;/p&gt;
&lt;p&gt;The C++ kernel comes equipped with a lookup file for the standard library, making it possible to execute queries like &lt;strong&gt;?std::vector&lt;/strong&gt; seamlessly.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Inline help feature in the C++ JupyterLite kernel" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/004-0_j7LvIkaUDbSD0urz.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Inline help feature in the C++ JupyterLite kernel&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;This can be enabled for third-party libraries. Check out the &lt;a href="https://xeus-cpp.readthedocs.io/en/latest/inline_help.html"&gt;documentation&lt;/a&gt; to enable inline help for your package.&lt;/p&gt;
&lt;p&gt;This feature, inherited from the Xeus-Cling project, was initially created by &lt;strong&gt;Loic Gouarin&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id="rich-display"&gt;Rich display&lt;/h3&gt;
&lt;p&gt;One of the core benefits of integrating C++ into the Jupyter ecosystem is the ability to leverage Jupyter’s rich MIME display system. Rather than limiting output to plain text, Xeus-Cpp allows you to render rich content like &lt;strong&gt;images, HTML tables, LaTeX&lt;/strong&gt;, or even &lt;strong&gt;custom visualizations&lt;/strong&gt;, all directly from C++.&lt;/p&gt;
&lt;p&gt;This is made possible by the function xcpp::display, which sends a &lt;em&gt;MIME bundle&lt;/em&gt; to the frontend. Each bundle can include multiple representations of the same object, such as &lt;strong&gt;text/plain&lt;/strong&gt;, &lt;strong&gt;image/png&lt;/strong&gt;, or even custom mime types.&lt;/p&gt;
&lt;p&gt;This is illustrated in the following example:&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Rich mime type rendering feature of the Xeus-Cpp kernel" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/005-0_icsXc3d2vC5OTF1K.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Rich mime type rendering feature of the Xeus-Cpp kernel&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;A custom renderer for any given type can be defined by defining the &lt;strong&gt;mime_bundle_repr&lt;/strong&gt; function in the corresponding namespace, which is then picked up by Xeus-Cpp’s display system through Argument-Dependent Lookup (ADL). A large collection of mime types are supported by the JupyterLab frontend, which can also be extended with plugins to support custom mime types.&lt;/p&gt;
&lt;h3 id="advanced-graphics"&gt;Advanced Graphics&lt;/h3&gt;
&lt;p&gt;Another compelling example leveraging the rich rendering capabilities, is to combine it with frameworks such as SDL for rich graphic content. Emscripten has built-in support for SDL (enabled with the &lt;strong&gt;-s USE_SDL=2&lt;/strong&gt; compilation flag), which allows us to leverage its power in C++ notebooks.&lt;/p&gt;
&lt;p&gt;To illustrate this, we ported &lt;strong&gt;Kevin Beason’s legendary &lt;a href="https://www.kevinbeason.com/smallpt/"&gt;smallpt&lt;/a&gt; global illumination renderer&lt;/strong&gt; (a path tracer in 99 lines of C++) into a C++ notebook. The scene is rendered using SDL onto an in-memory canvas, and the resulting image is captured and displayed with &lt;strong&gt;xcpp::display&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This setup showcases the seamless integration of SDL and the Jupyter display system:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use SDL for &lt;strong&gt;real-time or offscreen rendering&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Then pipe the result through xcpp::display(…) as a PNG or pixel buffer.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://github.com/compiler-research/xeus-cpp/pull/299"&gt;PR #299&lt;/a&gt; added an example notebook supporting smallpt with SDL-based rendering. Feel free to access the notebook through our &lt;a href="https://compiler-research.org/xeus-cpp/lab/index.html"&gt;lite link&lt;/a&gt;. Since the number of samples per pixel (spp) directly correlates with how long the process runs (approximately 2 minutes in our case), we’ve included debug logs to keep users informed during rendering, so they aren’t left wondering about the progress.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Smallpt tiny raytracer in action in JupyterLite" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/006-0_OrN0HWXlcMjemfj6.jpg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Smallpt tiny raytracer in action in JupyterLite&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;This approach paves the way for interactive C++ graphics demos, ray tracing notebooks, and even the prototyping of browser-based video games from within WebAssembly C++ notebooks.&lt;/p&gt;
&lt;h3 id="loading-third-party-libraries"&gt;Loading Third-Party Libraries&lt;/h3&gt;
&lt;p&gt;For a user’s perspective, a key difference between a Jupyter kernel for a compiled language like C++ and e.g. Python concerns how third-party libraries can be utilized. In Python, one merely needs to import the relevant installed packages, while in the case of C++, the relevant compiled libraries must be loaded in addition to including the corresponding headers.&lt;/p&gt;
&lt;p&gt;Thankfully, Clang-Repl provides the &lt;strong&gt;LoadDynamicLibrary&lt;/strong&gt; to dynamically load shared objects, which was adapted to the WebAssembly based in &lt;a href="https://github.com/llvm/llvm-project/pull/133037"&gt;LLVM PR #133037&lt;/a&gt;. Instead of relying directly on raw dlopen calls, this function ensures that memory layout, symbol resolution, and constructor invocation are handled correctly — even in a WebAssembly environment.&lt;/p&gt;
&lt;p&gt;Building on top of this, the CppInterOp project made these features available via a high-level C++ API.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Showcasing the dynamic loading of shared objects with CppInterOp" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/007-0_O4xsKujuUwCvMVSq.jpg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Showcasing the dynamic loading of shared objects with CppInterOp&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Library authors interested in facilitating the use of their package with the Jupyter kernel can include the calls to CppInterop’s &lt;strong&gt;LoadLibrary&lt;/strong&gt; can simply be included in user-facing headers.&lt;/p&gt;
&lt;p&gt;This has been done for example, in the Symengine library.&lt;/p&gt;
&lt;h3 id="symbolic-computing-with-symengine"&gt;Symbolic Computing with Symengine&lt;/h3&gt;
&lt;p&gt;A compelling example of the Jupyter rich display system’s advanced capabilities with Xeus-Cpp is the &lt;a href="https://github.com/symengine/symengine"&gt;&lt;strong&gt;SymEngine&lt;/strong&gt;&lt;/a&gt; package, a powerful C++ library for symbolic computing.&lt;/p&gt;
&lt;p&gt;Originally designed as a backend for symbolic Python libraries like SymPy, SymEngine offers native support for expression trees, calculus and Latex/MathJax rendering of mathematical expressions. We have integrated SymEngine into the emscripten-forge distribution, making it readily available for use. Once installed, it works seamlessly with Xeus-Cpp, requiring no additional setup.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;SymEngine expressions can be rendered via xcpp::display()&lt;/strong&gt;, which produces LaTeX-formatted expressions and delegates their rendering to &lt;strong&gt;MathJax&lt;/strong&gt; in the frontend.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Rich mime type rendering used with Symengine" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/008-0_7E9I9OxKKGqDK_Og.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Rich mime type rendering used with Symengine&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id="array-based-computing"&gt;Array-based Computing&lt;/h3&gt;
&lt;p&gt;Jupyter notebooks are particularly popular among data scientists, students, and practitioners of scientific computing. &lt;strong&gt;Array-based computing&lt;/strong&gt; is at the center of the practice, be it in Python with NumPy, in R, GNU Octave, or Julia.&lt;/p&gt;
&lt;p&gt;A framework for array-based computing is C++ is &lt;strong&gt;Xtensor&lt;/strong&gt;. Xtensor’s syntax closely mirrors that of NumPy, supporting features like array broadcasting, lazy evaluation, and element-wise operations with an idiomatic C++ API. Using Xtensor in combination with the C++ Jupyter kernel provides a similar user experience to that of NumPy with the Python Jupyter kernel.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="JupyterLite used in combination with Xtensor, utilizing rich display for tables." src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/009-0_jbBM7zjHznUTxDmp.jpg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;JupyterLite used in combination with Xtensor, utilizing rich display for tables.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Built on top of Xtensor, &lt;strong&gt;Xtensor-BLAS&lt;/strong&gt; brings the &lt;strong&gt;high-level syntax of Xtensor&lt;/strong&gt; with the &lt;strong&gt;performance of OpenBLAS&lt;/strong&gt;. It provides convenient, NumPy-style access to BLAS and LAPACK routines making operations like matrix inversion or system solving easy to express and execute.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="JupyterLite used in combination with Xtensor-BLAS" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/010-0_Y0RXrB1PrRoP7fQ3.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;JupyterLite used in combination with Xtensor-BLAS&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;To use these libraries inside a JupyterLite notebook, all you need is to include Xtensor-BLAS in your environment (available via emscripten-forge). Under the hood, Xtensor-BLAS dynamically loads &lt;strong&gt;libopenblas&lt;/strong&gt;, which is bundled automatically as a dependency.&lt;/p&gt;
&lt;h3 id="simd-acceleration"&gt;SIMD Acceleration&lt;/h3&gt;
&lt;p&gt;We can take a step further with &lt;strong&gt;SIMD (Single Instruction, Multiple Data)&lt;/strong&gt; acceleration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Using raw WebAssembly intrinsics :&lt;/strong&gt; WebAssembly includes 128-bit SIMD instructions, which are provided in Clang’s &lt;strong&gt;&amp;lt;wasm_simd128.h&amp;gt;&lt;/strong&gt; header. They can be used to perform vectorized operations directly.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Xeus-Cpp kernel showcasing the use of SIMD instructions" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/011-0_PyE8StfrE9f5s7g8.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Xeus-Cpp kernel showcasing the use of SIMD instructions&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Using Xsimd:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Rewriting specialized vectorized routines for WebAssembly can be cumbersome. This is where frameworks like &lt;a href="https://github.com/xtensor-stack/xsimd"&gt;&lt;strong&gt;Xsimd&lt;/strong&gt;&lt;/a&gt; come in. It provides a high-level SIMD API in C++ that abstracts platform-specific SIMD instructions. With Xsimd, you can efficiently operate on batches of numbers using familiar arithmetic operators or mathematical functions, while benefiting from optimized performance under the hood.&lt;/p&gt;
&lt;p&gt;Xsimd powers SIMD acceleration in Xtensor and is also used in many other projects, including Apache Arrow, Firefox, Velox, Pythran, and Krita. Here’s how the same example would look when when using Xsimd instead of raw intrinsics:&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Xeus-Cpp kernel showcasing the Xsimd library" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/012-0_cmTseJsCeHr02SRp.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Xeus-Cpp kernel showcasing the Xsimd library&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id="magic-commands"&gt;Magic Commands&lt;/h3&gt;
&lt;p&gt;In addition to interpreting standard C++ code, Xeus-Cpp also supports &lt;strong&gt;magic commands&lt;/strong&gt;, special notebook commands prefixed with % or %% that allow for extended functionality not defined by the C++ language itself.&lt;/p&gt;
&lt;p&gt;These magics let you interact with the runtime environment, manage files, or perform meta-operations, all from within a code cell. The following magics are available:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;%file :&lt;/strong&gt; The %file magic enables file creation and editing directly from a code cell. You can append to an existing file using the &lt;strong&gt;-a&lt;/strong&gt; flag&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Using the %file magics in Xeus-Cpp-lite" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/013-0_-sOa-yVDMKuTdJ6R.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Using the %file magics in Xeus-Cpp-lite&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;%timeit :&lt;/strong&gt; A %timeit magic has also been prototyped via &lt;a href="https://github.com/compiler-research/xeus-cpp/pull/289"&gt;PR #289&lt;/a&gt; by &lt;a href="https://github.com/kr-2003"&gt;@kr-2003&lt;/a&gt;, enabling performance measurement for expressions in the notebook.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;However, due to the lack of &lt;strong&gt;last value printing support&lt;/strong&gt; in Clang-Repl, this feature currently relies on a workaround and hasn’t yet been merged. Once upstream support is in place, %timeit will be integrated cleanly and available out of the box.&lt;/p&gt;
&lt;p&gt;Here’s a preview of the %timeit magic in action:&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Using the %timeit magics in Xeus-Cpp-lite" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/014-1_TxNBjy8ovN1LbrQ1UYejAQ.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Using the %timeit magics in Xeus-Cpp-lite&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Magic commands open the door to a more expressive and interactive notebook experience for C++. While support is currently limited to a few core magics, this is just the beginning — with more capabilities and enhancements expected in the near future.&lt;/p&gt;
&lt;h3 id="interactive-widgets"&gt;Interactive Widgets&lt;/h3&gt;
&lt;p&gt;Beyond rich mime type rendering and inline documentation, the Jupyter widgets system allows users to create interactive components in the Jupyter notebook, leveraging by-directional communication with the kernel for more interactivity.&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://github.com/jupyter-xeus/xwidgets"&gt;&lt;strong&gt;xwidgets&lt;/strong&gt;&lt;/a&gt; package is a C++ implementation of the Jupyter widget protocol, comprising an implementation of all the core Jupyter widgets, and which underlies other interactive visualization libraries like &lt;a href="https://github.com/jupyter-xeus/xleaflet"&gt;&lt;strong&gt;xleaflet&lt;/strong&gt;&lt;/a&gt; or &lt;a href="https://github.com/jupyter-xeus/xcanvas"&gt;&lt;strong&gt;xcanvas&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here are a couple examples demonstrating interactive widgets through xwidgets &amp;amp; xcanvas with Xeus-Cpp-lite.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Displaying a slider using xwidgets" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/015-1_uJRTSmvJ8OgZbDLliI5BkQ.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Displaying a slider using xwidgets&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img alt="Displaying a canvas through xcanvas" src="https://blog.jupyter.org/posts/2025/c-in-jupyter-interpreting-c-in-the-web/images/016-1_w-SeiUeAmHPcMeIY84tb0w.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Displaying a canvas through xcanvas&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;If you inspect the codebase of xwidgets or xcanvas, you will notice that it contains very little code. All that is required on the C++ end is a declaration of the attributes that should be synchronized with the frontend, and serialization methods for complex data types.&lt;/p&gt;
&lt;p&gt;Most of the programmatic logic for Jupyter interactive widgets lies in the frontend implementation. The consequence for the C++ Jupyter kernel is that with seemingly little implementation effort, we could enable an entire ecosystem of widget libraries, covering a large range of use cases. Interactive widgets for 2-D plotting (&lt;strong&gt;bqplot&lt;/strong&gt;, &lt;strong&gt;plotly&lt;/strong&gt;) and 3-D plotting (&lt;strong&gt;ipyvolume&lt;/strong&gt;), GIS (&lt;strong&gt;ipyleaflet&lt;/strong&gt;), efficient rendering of meshes (&lt;strong&gt;ipygany&lt;/strong&gt;), graph visualization (&lt;strong&gt;ipycytoscape&lt;/strong&gt;), and many more could be almost automatically connected to the C++ world.&lt;/p&gt;
&lt;h2 id="how-to-deploy-jupyterlite-with-xeus-cpp"&gt;How to deploy JupyterLite with Xeus-Cpp&lt;/h2&gt;
&lt;p&gt;The GitHub repository &lt;a href="https://github.com/jupyterlite/xeus-lite-demo"&gt;https://github.com/jupyterlite/xeus-lite-demo&lt;/a&gt; is a template for creating a JupyterLite deployment on GitHub pages that includes the packages specified in a conda environment.&lt;/p&gt;
&lt;p&gt;The process is as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a new repository from the GitHub template.&lt;/li&gt;
&lt;li&gt;Enable the deployment on GitHub pages from a GitHub action, as shown in the README.&lt;/li&gt;
&lt;li&gt;Edit the environment file to include the desired packages.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For example, to deploy an C++ kernel with Symengine &amp;amp; Xtensor-blas installed, the environment.yml file would contain the following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;xeus-cpp&lt;/span&gt;
&lt;span class="nt"&gt;channels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;https://repo.prefix.dev/emscripten-forge-dev&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;conda-forge&lt;/span&gt;
&lt;span class="nt"&gt;dependencies&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;xeus-cpp&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;symengine&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;xtensor-blas&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The deployment linked at the beginning of this article was created with this template.&lt;/p&gt;
&lt;h2 id="future-work"&gt;Future work&lt;/h2&gt;
&lt;p&gt;The journey of interactive C++ in Jupyter, both natively and in the browser, is still evolving. While Xeus-Cpp already offer powerful foundations, several exciting developments are underway that will further expand their capabilities across platforms&lt;/p&gt;
&lt;h3 id="debugger-support"&gt;Debugger Support&lt;/h3&gt;
&lt;p&gt;Currently, only a few Jupyter kernels like Xeus-Python offer full integration with the Jupyter Debug Protocol to enable the Jupyterlab debugger. We’re working to bring that experience to C++ as well.&lt;/p&gt;
&lt;p&gt;This summer, thanks to &lt;a href="https://summerofcode.withgoogle.com/programs/2025/projects/uEB2as1n"&gt;Google Summer of Code 2025&lt;/a&gt;, &lt;strong&gt;Abhinav Kumar&lt;/strong&gt; will be implementing native debugging support in Xeus-Cpp.The approach is based on using &lt;strong&gt;LLDB&lt;/strong&gt; and its &lt;strong&gt;Debug Adapter Protocol (lldb-dap)&lt;/strong&gt;. Modeled after Xeus-Python, it leverages LLDB’s Clang and JIT debugging capabilities to enable &lt;strong&gt;breakpoints&lt;/strong&gt;, &lt;strong&gt;variable inspection&lt;/strong&gt;, and &lt;strong&gt;step-through execution&lt;/strong&gt; directly within the JupyterLab debugger interface.&lt;/p&gt;
&lt;p&gt;We already have a proof-of-concept demonstrating that debugging C++ in Jupyter is possible. You can track this effort here: &lt;a href="https://github.com/compiler-research/xeus-cpp/issues/282"&gt;xeus-cpp issue #282&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In the longer term, we aim to explore extending debugging to the browser through Xeus-Cpp.&lt;/p&gt;
&lt;h3 id="cuda-support-in-xeus-cpp"&gt;Cuda Support in Xeus-Cpp&lt;/h3&gt;
&lt;p&gt;CUDA support in Clang-Repl was broken by the time LLVM 20 was released, but that changed with this upstream patch:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;LLVM PR: &lt;a href="https://github.com/llvm/llvm-project/pull/136404"&gt;#136404 — Enable CUDA support in clang-repl&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We’re now preparing to bring CUDA support directly to Xeus-Cpp, enabling GPU programming from a Jupyter notebook. Early planning is underway:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GitHub issue: &lt;a href="https://github.com/compiler-research/xeus-cpp/issues/300"&gt;#300 — CUDA REPL support in xeus-cpp&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="last-value-printing"&gt;Last Value Printing&lt;/h3&gt;
&lt;p&gt;In &lt;strong&gt;cling&lt;/strong&gt;, a widely appreciated feature is &lt;em&gt;last value printing&lt;/em&gt;, simply writing a variable at the end of a cell automatically displays its value, without needing any manual printing. This behavior naturally carried over to &lt;strong&gt;xeus-cling&lt;/strong&gt;, making interactive exploration even smoother.&lt;/p&gt;
&lt;p&gt;This feature stands almost done in Clang-Repl:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;LLVM PR: &lt;a href="https://github.com/llvm/llvm-project/pull/84769"&gt;#84769 — Last Value Printing in clang-repl&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once merged, this will be integrated into Xeus-Cpp, enabling seamless REPL experience for C++ users.&lt;/p&gt;
&lt;h2 id="how-to-contribute"&gt;How to contribute?&lt;/h2&gt;
&lt;p&gt;Whether you’re a developer, package maintainer, educator, or simply curious about C++ in the browser, &lt;strong&gt;contributions are always welcome&lt;/strong&gt;!&lt;/p&gt;
&lt;h3 id="packaging-for-the-browser"&gt;Packaging for the Browser&lt;/h3&gt;
&lt;p&gt;Many of the capabilities in xeus-cpp-lite rely on packages built for the WebAssembly platform via &lt;strong&gt;emscripten-forge&lt;/strong&gt;. If you’re interested in porting a library or creating a new recipe, please visit &lt;a href="https://emscripten-forge.org/"&gt;emscripten-forge.org&lt;/a&gt; for detailed guidelines and examples.&lt;/p&gt;
&lt;p&gt;PRs and discussions are welcome at &lt;a href="https://github.com/emscripten-forge"&gt;github.com/emscripten-forge&lt;/a&gt;, especially if you’re looking to bring more numerical, graphical, or scientific libraries into the browser.&lt;/p&gt;
&lt;h3 id="improving-xeus-cpp-cppinterop-and-clang-repl"&gt;Improving Xeus-Cpp, CppInterOp and Clang-Repl&lt;/h3&gt;
&lt;p&gt;We welcome contributions to the broader &lt;strong&gt;xeus&lt;/strong&gt; project, which is part of the &lt;a href="https://jupyter.org/"&gt;Project Jupyter&lt;/a&gt; ecosystem. Xeus-Cpp in particular is actively seeking contributors, whether to improve kernel behavior, expand feature support, or explore new magic commands and UI integrations.&lt;/p&gt;
&lt;p&gt;On the LLVM side, the &lt;strong&gt;Clang-Repl&lt;/strong&gt; component is still under active development and can greatly benefit from community contributions, particularly around WebAssembly backend improvements and incremental execution features.&lt;/p&gt;
&lt;h3 id="areas-of-need-opportunities-for-collaboration"&gt;Areas of Need &amp;amp; Opportunities for Collaboration&lt;/h3&gt;
&lt;p&gt;In addition to code contributions, we are seeking funding opportunities to advance the project. We’ve identified several areas where focused effort could significantly enhance the ecosystem, and we warmly welcome collaborators or potential funding partners interested in helping us move these efforts forward, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Integration testing&lt;/strong&gt;: LLVM currently lacks tests for Clang-Repl + WebAssembly. Establishing a reliable test harness in this area is both challenging and critical.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interactive plotting&lt;/strong&gt;: A robust plotting library or plugin for Xeus-Cpp would make the kernel far more expressive for teaching, data exploration, and scientific computing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Plugin system for magics&lt;/strong&gt;: Further decoupling kernel extensions would simplify development and allow community-driven growth. A concrete description of this project is framed on &lt;a href="https://hepsoftwarefoundation.org/gsoc/2025/proposal_XeusCpp-Plugins.html"&gt;CERN’s website&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you or your organization shares the vision of making modern C++ more accessible, especially in-browser, we’d love to hear from you.&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="about-the-authors"&gt;About the Authors&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://github.com/anutosh491"&gt;&lt;strong&gt;Anutosh Bhat&lt;/strong&gt;&lt;/a&gt; is a scientific software engineer at &lt;a href="https://quantstack.net/"&gt;QuantStack&lt;/a&gt;. His contributions range from the core of LLVM and Xeus, to their packaging for the Emscripten-forge software distribution. In the course of this endeavor, Anutosh was granted commit rights to the LLVM project.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/vgvassilev"&gt;&lt;strong&gt;Vassil Vassilev&lt;/strong&gt;&lt;/a&gt; is a Research Software Consultant with Princeton at &lt;a href="https://home.cern/"&gt;CERN&lt;/a&gt;. As the co-creator of Cling and the lead developer of the Clang-Repl and CppInterOp projects, he has spearheaded the development of interpreted C++ for over a decade.&lt;/p&gt;
&lt;h2 id="acknowledgements"&gt;Acknowledgements&lt;/h2&gt;
&lt;p&gt;The work by &lt;strong&gt;Vassil Vassilev&lt;/strong&gt; on this project is done in the context of the &lt;a href="https://compiler-research.org/"&gt;Compiler Research&lt;/a&gt; group, funded by the National Science Foundation grant OAC-2311471.&lt;/p&gt;
&lt;p&gt;The work by &lt;strong&gt;Anutosh Bhat&lt;/strong&gt; on this project is funded by &lt;a href="https://quantstack.net/"&gt;QuantStack&lt;/a&gt;, as part of a broader initiative to enable the data science ecosystem within the Web browser.&lt;/p&gt;
&lt;p&gt;Work on prototyping the WebAssembly infrastructure for Clang-Repl was done by &lt;strong&gt;Anubhab Ghosh&lt;/strong&gt;, supported through &lt;a href="https://summerofcode.withgoogle.com/archive/2023/projects/X0cFgJkY"&gt;Google Summer of Code 2023&lt;/a&gt; via the LLVM mentoring organization.&lt;/p&gt;
&lt;p&gt;A significant portion of the Xeus-Cpp codebase was inherited from the Xeus-Cling project and adapted for the Clang-Repl interpreter. This includes work by &lt;strong&gt;Sylvain Corlay&lt;/strong&gt;, &lt;strong&gt;Johan Mabille&lt;/strong&gt;, &lt;strong&gt;Loic Gouarin&lt;/strong&gt;, and &lt;strong&gt;Martin Renou&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;We are grateful to &lt;strong&gt;Thorsten Beier&lt;/strong&gt;, the creator and lead developer of the emscripten-forge software distribution, for his support in packaging LLVM and Xeus-Cpp.&lt;/p&gt;
&lt;p&gt;We extend our gratitude to &lt;strong&gt;Martin Renou&lt;/strong&gt; and &lt;strong&gt;Anastasiia Sliusar&lt;/strong&gt; for devising the processing of conda packages in the frontend, which underlies the support of third-party libraries in WebAssembly environments used by Xeus-Cpp and xeus-r. We are grateful to &lt;strong&gt;Johan Mabille&lt;/strong&gt; for creating xeus and for his code reviews within the xeus stack. We also thank &lt;strong&gt;Jeremy Tuloup&lt;/strong&gt; for creating JupyterLite.&lt;/p&gt;
&lt;p&gt;We are grateful to &lt;strong&gt;Matthew Barton, Tharun Anandh &amp;amp; Abhinav Kumar&lt;/strong&gt; for their numerous and significant contributions to the Xeus-Cpp project.&lt;/p&gt;
&lt;p&gt;Finally, we are immensely grateful to the authors and maintainers of Emscripten and LLVM for building such remarkable technologies and for their engagement and support during our numerous interactions on GitHub.&lt;/p&gt;
</content><category term="C++"/><category term="JupyterLite"/><category term="kernels"/><category term="WebAssembly"/><category term="xeus"/></entry><entry><title>R in the Browser: Announcing Our WebAssembly Distribution</title><link href="https://blog.jupyter.org/posts/2025/r-in-the-browser-announcing-our-webassembly/" rel="alternate"/><published>2025-02-28T08:31:00+00:00</published><updated>2025-04-25T07:39:00+00:00</updated><author><name>Isabel Paredes</name></author><id>tag:blog.jupyter.org,2025-02-28:/posts/2025/r-in-the-browser-announcing-our-webassembly/</id><summary type="html">&lt;p&gt;R is now available in emscripten-forge, enabling the Xeus-R kernel in JupyterLite.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;em&gt;R is now available in emscripten-forge, enabling the Xeus-R kernel in JupyterLite.&lt;/em&gt;&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2025/r-in-the-browser-announcing-our-webassembly/images/001-1_y4YmV8C0L1CkE1Q5JRJLkg.webp" alt="Banner with gradient background and R-lite logo" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;In the past few months, &lt;a href="https://quantstack.net/"&gt;QuantStack&lt;/a&gt; has received funding from the &lt;a href="https://www.gatesfoundation.org/"&gt;&lt;strong&gt;Bill &amp;amp; Melinda Gates Foundation&lt;/strong&gt;&lt;/a&gt; through a grant to &lt;a href="https://coursekata.org/"&gt;CourseKata&lt;/a&gt; to develop support for the R programming language in &lt;a href="https://jupyterlite.readthedocs.io/en/stable/"&gt;JupyterLite&lt;/a&gt; and the &lt;a href="https://emscripten-forge.org/"&gt;Emscripten-forge&lt;/a&gt; distribution for WebAssembly.&lt;/p&gt;
&lt;p&gt;Today, we are thrilled to announce the availability of the R programming language in the Emscripten-Forge distribution for WebAssembly, which enables R workflows in JupyterLite through the Xeus-R Jupyter kernel.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Screenshot of JupyterLite with an R Jupyter notebook in use" src="https://blog.jupyter.org/posts/2025/r-in-the-browser-announcing-our-webassembly/images/002-0_9D50aOr7jhxFnjzo.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;JupyterLite with an R Jupyter notebook in use&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;To experience R in JupyterLite, simply click on the link below:&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://isabelparedes.github.io/xeus-r-demo/lab/?path=demo.ipynb"&gt;&lt;img src="https://blog.jupyter.org/posts/2025/r-in-the-browser-announcing-our-webassembly/images/003-0_qOr5KTmon-fiZ37l.webp" alt="Button to access JupyterLite" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this article, we present the details of our efforts to enable R workflows in JupyterLite. We cover the challenges encountered in packaging R and its dependencies for this platform, the solutions we implemented, and the process of handling R mamba packages on the frontend.&lt;/p&gt;
&lt;h2 id="why-webassembly-scaling-scientific-computing-workflows-in-jupyter-to-millions-of-users"&gt;Why WebAssembly? Scaling scientific computing workflows in Jupyter to millions of users&lt;/h2&gt;
&lt;p&gt;The main challenge in scaling Jupyter deployments lies in providing a live computing environment on the server side for each user session.&lt;/p&gt;
&lt;p&gt;While Kubernetes-based JupyterHub deployments have been successfully implemented at a university scale (such as the UC Berkeley Data 8 class, or the JupyterHub deployment of Université Paris Saclay), they demand substantial computing resources and a skilled DevOps team to achieve and maintain this level of scalability.&lt;/p&gt;
&lt;p&gt;In contrast, &lt;a href="https://jupyterlite.readthedocs.io/"&gt;&lt;strong&gt;JupyterLite&lt;/strong&gt;&lt;/a&gt; represents a fundamentally different paradigm. As a browser-based distribution of Jupyter, it runs language kernels directly in the browser, enabling significantly greater scalability and ease of deployment. Notable JupyterLite-based applications include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A JupyterLite console integrated into &lt;a href="http://numpy.org"&gt;&lt;strong&gt;NumPy&lt;/strong&gt;&lt;/a&gt;’s front page, providing immediate access to NumPy functionality without requiring installation.&lt;/li&gt;
&lt;li&gt;A similar console application on &lt;a href="https://live.sympy.org/"&gt;&lt;strong&gt;SymPy&lt;/strong&gt;&lt;/a&gt;’s project page, fully hosted statically.&lt;/li&gt;
&lt;li&gt;The official &lt;a href="https://jupyter.org/try"&gt;&lt;strong&gt;Jupyter&lt;/strong&gt;&lt;/a&gt; website&lt;sup class="footnote-ref"&gt;&lt;a href="#fn1" id="fnref1"&gt;[1]&lt;/a&gt;&lt;/sup&gt;.&lt;/li&gt;
&lt;li&gt;The examples in &lt;a href="https://scikit-learn.org/stable/lite/lab/index.html"&gt;&lt;strong&gt;Scikit-Learn&lt;/strong&gt;&lt;/a&gt;’s documentation.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These examples illustrate how WebAssembly can be transformative by providing ready-to-use computing environments for scientific workflows, in documentation, blog posts, and scientific communications. The WebAssembly environments are made available to the hundreds of thousands of monthly visitors of these websites without requiring any computing resources on the backend.&lt;/p&gt;
&lt;figure&gt;
&lt;a href="http://NumPy.org"&gt;&lt;img alt="JupyterLite deployment displayed on the NumPy website" src="https://blog.jupyter.org/posts/2025/r-in-the-browser-announcing-our-webassembly/images/004-0_-531naCHla3pK14Q.jpg" loading="lazy" data-body-image=""&gt;&lt;/a&gt;
&lt;figcaption&gt;JupyterLite deployment displayed on the NumPy website&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;a href="https://live.sympy.org/"&gt;&lt;img alt="JupyterLite deployment displayed on the SymPy website" src="https://blog.jupyter.org/posts/2025/r-in-the-browser-announcing-our-webassembly/images/005-0_vk6bu54D0C7y4k9b.jpg" loading="lazy" data-body-image=""&gt;&lt;/a&gt;
&lt;figcaption&gt;JupyterLite deployment displayed on the SymPy website&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;a href="https://jupyter.org/try"&gt;&lt;img alt="JupyterLite deployment displayed on the Jupyter website" src="https://blog.jupyter.org/posts/2025/r-in-the-browser-announcing-our-webassembly/images/006-0_SKvqpunHcz3i2mBG.webp" loading="lazy" data-body-image=""&gt;&lt;/a&gt;
&lt;figcaption&gt;JupyterLite deployment displayed on the Jupyter website&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="beyond-python-enabling-r-in-the-browser-and-more"&gt;Beyond Python, enabling R in the browser, and more&lt;/h2&gt;
&lt;p&gt;While the initial focus of the JupyterLite team has been on the Python programming language, the JupyterLite infrastructure was designed to be language-agnostic from the outset. The same principle applies to the package management stack we have been contributing to over the past few years, namely, &lt;a href="https://github.com/mamba-org/mamba"&gt;mamba&lt;/a&gt; and &lt;a href="https://conda-forge.org/"&gt;conda-forge&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;When we began targeting the WebAssembly platform, we chose to build our efforts on the mamba and conda-forge ecosystem. This decision allowed us to provide customizable environments for WebAssembly and expand beyond Python. This enabled applications such as the &lt;a href="https://github.com/jupyterlite/terminal"&gt;&lt;strong&gt;JupyterLite terminal&lt;/strong&gt;&lt;/a&gt;, created by Ian Thomas, which comprises a bash-like shell written in TypeScript called &lt;a href="https://github.com/jupyterlite/cockle"&gt;Cockle&lt;/a&gt;, and WebAssembly builds of native shell commands such as cat, grep, ls, and vim. You can read the &lt;a href="https://blog.jupyter.org/posts/2024/jupyterlite-terminal/"&gt;&lt;strong&gt;earlier&lt;/strong&gt; &lt;strong&gt;announcement&lt;/strong&gt;&lt;/a&gt; introducing the JupyterLite terminal.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Today, we are excited to reveal the availability of R in emscripten-forge, enabling Jupyter kernels such as Xeus-R to be used in JupyterLite.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;With the addition of R, emscripten-forge now provides a unified packaging solution for Python, R, and terminal applications for WebAssembly. This covers the scopes of &lt;a href="https://pyodide.org/"&gt;&lt;strong&gt;Pyodide&lt;/strong&gt;&lt;/a&gt; (a Python distribution for WebAssembly), &lt;a href="https://docs.r-wasm.org/"&gt;&lt;strong&gt;WebR&lt;/strong&gt;&lt;/a&gt; (an R distribution for WebAssembly), and &lt;a href="https://sandbox.bio/"&gt;&lt;strong&gt;Sandbox.bio&lt;/strong&gt;&lt;/a&gt; (a shell emulator with WebAssembly commands).&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="building-r-for-emscripten-forge"&gt;Building R for Emscripten-forge&lt;/h2&gt;
&lt;p&gt;Emscripten-forge is a GitHub organization containing recipes to build &lt;strong&gt;conda packages&lt;/strong&gt; for the emscripten-wasm32 platform; it is also the first distribution of conda packages targeting this platform. It is built upon a modernized stack, leveraging &lt;strong&gt;rattler-build&lt;/strong&gt; (the successor to the conda-build package builder) and &lt;strong&gt;mamba&lt;/strong&gt;. The emscripten-forge project, which was created and is still led by Thorsten Beier, is now a team effort covering a broad range of packages.&lt;/p&gt;
&lt;p&gt;In order to build R with emscripten-forge, we first required a toolchain capable of converting Fortran and C/C++ code into WebAssembly. Since R relies on BLAS and LAPACK (which are written in Fortran) and many essential R packages wrap native libraries that use Fortran, this conversion capability was crucial.&lt;/p&gt;
&lt;h2 id="fortran"&gt;Fortran&lt;/h2&gt;
&lt;p&gt;By default, the emscripten-forge toolchain can cross-compile any C/C++ packages into WebAssembly; however, the first challenge in building the R stack was expanding the toolchain to also compile Fortran code. The two compilers that we considered for this task are LFortran and Flang.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://lfortran.org/"&gt;&lt;strong&gt;LFortran&lt;/strong&gt;&lt;/a&gt; is a compiler built on top of LLVM and designed from the ground up as a cross-compiler. Despite its potential, LFortran is still in its early stages compared to Flang and does not yet fully support all Fortran features.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://flang.llvm.org/"&gt;&lt;strong&gt;LLVM Flang&lt;/strong&gt;&lt;/a&gt; is the Fortran compiler of the LLVM project. Unfortunately, it does not support cross-compilation.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Working with Serge Guelton and Kerim Birgi, we initially experimented with the LFortran compiler and contributed to addressing issues encountered when building Netlib &lt;a href="https://github.com/Reference-LAPACK/lapack"&gt;LAPACK&lt;/a&gt;. The BLAS implementation from this package served as a valuable testing ground since BLAS is one of the core dependencies for R.&lt;/p&gt;
&lt;p&gt;After careful consideration, we found that Flang, with its ability to compile a wider variety of Fortran projects, brought us closer to building the Fortran components of R to WebAssembly. George Stagg, the main developer of the WebR project, has written a detailed &lt;a href="https://gws.phd/posts/fortran_wasm/"&gt;article&lt;/a&gt; on using Flang to produce WebAssembly, which was adapted to the (then) latest version of LLVM (&lt;a href="https://github.com/r-wasm/llvm-project/blob/wasm/llvm/CMakeLists.txt"&gt;v18&lt;/a&gt;). Inspired by George Stagg’s endeavors, Serge posted upstream contributions to the Flang project (&lt;a href="https://github.com/llvm/llvm-project/pull/99465"&gt;#99465&lt;/a&gt;, &lt;a href="https://github.com/llvm/llvm-project/pull/99822"&gt;#99822&lt;/a&gt;, &lt;a href="https://github.com/llvm/llvm-project/pull/101242"&gt;#101242&lt;/a&gt;, &lt;a href="https://github.com/llvm/llvm-project/pull/105589"&gt;#105589&lt;/a&gt;), resolving issues with 32-bit platforms that were impacting our effort to support WebAssembly. All of these changes will be included in LLVM/Flang 20.0.&lt;/p&gt;
&lt;p&gt;The remaining patches which cannot be merged upstream at this point involve:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;(1) enabling code generation that targets WebAssembly (&lt;a href="https://github.com/llvm/llvm-project/commit/198c0e1e23a52abb3e274ee44223551247f2c38f"&gt;198c0e1&lt;/a&gt;),&lt;/li&gt;
&lt;li&gt;(2) encoding target-specific size definitions for various data types given that the host and target platforms have different architectures (&lt;a href="https://github.com/llvm/llvm-project/commit/1da66cda3652da369f5d1be871c27368a12b55e9"&gt;1da66cd&lt;/a&gt;), and&lt;/li&gt;
&lt;li&gt;(3) disabling support for 128-bit floating-point types (&lt;a href="https://github.com/llvm/llvm-project/commit/f20c7c05db0ed9afb50c0092dad7bc991d933481"&gt;f20c7c0&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A version of (2) that could be contributed upstream is in the works, which would be one step closer to making WebAssembly an official target for Flang. Additionally, (3) will no longer be needed starting with Flang v20.&lt;/p&gt;
&lt;p&gt;These patches were integrated by Axel Obermeier into the Flang build recipe for the conda-forge distribution, making the modified build accessible to everyone. It can be installed on Linux with mamba or micromamba by executing:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;micromamba&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;conda-forge/label/emscripten::flang&lt;span class="w"&gt; &lt;/span&gt;libllvm19&lt;span class="w"&gt; &lt;/span&gt;--no-channel-priority
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The final ingredient for our toolchain involved creating a compatible Fortran runtime library. Since Flang implements its runtime library in C/C++, compiling this library with Emscripten proved to be straightforward. We added a &lt;a href="https://github.com/emscripten-forge/recipes/blob/9b08a19a531bb5e03c7d5147367f6de2acb57e40/recipes/recipes_emscripten/libflang/recipe.yaml"&gt;recipe for libflang&lt;/a&gt; to emscripten-forge, which packages the runtime library and includes all the aforementioned patches.&lt;/p&gt;
&lt;p&gt;In the following example, we invoke Flang on a simple Fortran script, and execute the resulting JavaScript and WebAssembly with NodeJS.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;ls
hello.f90&lt;span class="w"&gt;  &lt;/span&gt;libFortranRuntime.a
&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;cat&lt;span class="w"&gt; &lt;/span&gt;hello.f90
File:&lt;span class="w"&gt; &lt;/span&gt;hello.f90
program&lt;span class="w"&gt; &lt;/span&gt;hello
&lt;span class="w"&gt; &lt;/span&gt;print&lt;span class="w"&gt; &lt;/span&gt;*,&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Hello, Fortran!&amp;quot;&lt;/span&gt;
end&lt;span class="w"&gt; &lt;/span&gt;program&lt;span class="w"&gt; &lt;/span&gt;hello
&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;source&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;~/emsdk/emsdk_env.sh
&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;flang-new&lt;span class="w"&gt; &lt;/span&gt;--target&lt;span class="o"&gt;=&lt;/span&gt;wasm32-unknown-emscripten&lt;span class="w"&gt; &lt;/span&gt;-c&lt;span class="w"&gt; &lt;/span&gt;hello.f90&lt;span class="w"&gt; &lt;/span&gt;-o&lt;span class="w"&gt; &lt;/span&gt;hello.o
&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;emcc&lt;span class="w"&gt; &lt;/span&gt;hello.o&lt;span class="w"&gt; &lt;/span&gt;libFortranRuntime.a&lt;span class="w"&gt; &lt;/span&gt;-o&lt;span class="w"&gt; &lt;/span&gt;hello.js
&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;ls
hello.f90&lt;span class="w"&gt;  &lt;/span&gt;hello.js&lt;span class="w"&gt;  &lt;/span&gt;hello.o&lt;span class="w"&gt;  &lt;/span&gt;hello.wasm&lt;span class="w"&gt;  &lt;/span&gt;libFortranRuntime.a
&amp;gt;&lt;span class="w"&gt; &lt;/span&gt;node&lt;span class="w"&gt; &lt;/span&gt;hello.js
Hello,&lt;span class="w"&gt; &lt;/span&gt;Fortran!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;With a working Fortran-to-WebAssembly toolchain, we managed to compile BLAS and LAPACK (See the &lt;a href="https://github.com/emscripten-forge/recipes/blob/main/recipes/recipes_emscripten/lapack/recipe.yaml"&gt;LAPACK recipe&lt;/a&gt;). But before we could get started with building R, we needed to tackle the remaining R dependencies.&lt;/p&gt;
&lt;h2 id="walking-up-the-stack"&gt;Walking up the stack&lt;/h2&gt;
&lt;p&gt;In R (v4.4), there are a handful of dependencies that are required to provide basic functionality; these are: libiconv, zlib, bzip2, xz, pcre2, and libcurl. Thanks to the packaging efforts led by Thorsten Beier and Wolf Vollprecht, these dependencies are available on emscripten-forge with the exception of libcurl. Because of its socket-based networking architecture and reliance on system-level resource access, libcurl faces fundamental incompatibilities with WebAssembly’s sandboxed environment constraints. Therefore, libcurl had to be disabled in the R source code. As a consequence, downstream R packages which depend on libcurl cannot be ported to WebAssembly until a suitable libcurl replacement is available.&lt;/p&gt;
&lt;p&gt;Apart from the core dependencies, R also requires a BLAS implementation. Although external BLAS libraries can be used with R, the R code base contains linear algebra routines from Netlib BLAS and a subset of LAPACK where both libraries are written in C and Fortran. To simplify configuration, we opted for these internal implementations instead of using external BLAS and LAPACK libraries.&lt;/p&gt;
&lt;p&gt;Furthermore, several key optional dependencies were cross-compiled to WebAssembly to enhance R’s graphical capabilities; these include libpng, libtiff, cairo, and pango, along with their respective subdependencies. One particularly challenging aspect of packaging these libraries was the cross-compilation of glib, which both cairo and pango depend on. Compiling glib was only possible thanks to the efforts of &lt;a href="https://gist.github.com/kleisauke/acfa1c09522705efa5eb0541d2d00887"&gt;Kleis Auke Wolthuizen&lt;/a&gt; whose patches made glib compatible with Emscripten, and Johan Mabille who disabled multi-threading.&lt;/p&gt;
&lt;p&gt;The R dependencies are summarized in the following table:&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="A table summarizing the R dependencies." src="https://blog.jupyter.org/posts/2025/r-in-the-browser-announcing-our-webassembly/images/007-1_9VQSZHRow-lBASg0wxfklg.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Table of R dependencies&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="cross-compilation-of-r"&gt;Cross-compilation of R&lt;/h2&gt;
&lt;p&gt;Although R typically configures and builds seamlessly on most unix platforms, cross-compiling is not straightforward because R uses a bootstrap approach; first it creates a minimal version of R which is then used to run several R scripts to complete the build process. Bootstrapping is a challenge because the built binaries for the target platform (WebAssembly) are not executable (at least not directly) from the host platform. Therefore, the r-base package necessitates two build phases. First, we compile R for the host platform (Linux) with GCC and Flang; this generates the R and Rscript executables needed for the second phase. And then, we cross-compile to WebAssembly with Emscripten and Flang.&lt;/p&gt;
&lt;p&gt;One of the major challenges of this setup was generating the R Data Base (.rdb) and R Data Index (.rdx) files for the internal packages of r-base (base, compiler, grDevices, graphics, grid, methods, parallel, splines, stats, stats4, tools, and utils). To accomplish this, it was necessary to dynamically load some of the internal shared libraries (tools, grDevices, graphics, utils, stats, and methods) which provide essential functionality to generate the data and index files. However, the R executables we created during the first phase of the build are incompatible with the WebAssembly shared libraries. In order to work around this, we temporarily replaced the WebAssembly libraries of the internal packages with the linux shared libraries we built during the first phase (See &lt;a href="https://github.com/emscripten-forge/recipes/blob/9b08a19a531bb5e03c7d5147367f6de2acb57e40/recipes/recipes_emscripten/r-base/cross_libraries.sh"&gt;cross_libraries.sh&lt;/a&gt;). This makeshift solution is also used to cross-compile all other R packages; the setup is carried out by the activation script of the cross-r-base package (See &lt;a href="https://github.com/conda-forge/r-base-feedstock/blob/54c15117f86693d54d69aacdd2fb76f622e31e5a/recipe/activate-cross-r-base.sh#L18"&gt;activate-cross-r-base.sh&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Additionally, the R source code required a few modifications to enable cross-compilation to WebAssembly.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The Emscripten platform was added to select the correct configuration for the platform.&lt;/li&gt;
&lt;li&gt;The dependency on libcurl was removed (as mentioned in the previous section) and as a consequence, the internet package which relies on libcurl was disabled.&lt;/li&gt;
&lt;li&gt;System calls which are not compatible with our WebAssembly environment were disabled.&lt;/li&gt;
&lt;li&gt;Cairo replaced Xlib as the default bitmap type to enable graphics.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The complete list of patches applied to R is available here: &lt;a href="https://github.com/emscripten-forge/recipes/tree/main/recipes/recipes_emscripten/r-base/patches"&gt;r-base patches&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="the-r-package-ecosystem"&gt;The R package ecosystem&lt;/h2&gt;
&lt;p&gt;Building R itself was just the beginning. The next challenge was to provide a wide array of R packages to create a robust development environment. Fortunately, many packages are written in pure R and are available as “noarch” packages on conda-forge, making them directly compatible with emscripten-forge environments. However, for the R packages that require compilation, a package recipe needs to be created and added to emscripten-forge. Thanks to the help of Anutosh Bhat, the following packages have been compiled and are available to use.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;r-askpass     r-digest    r-haven      r-magrittr  r-purrr    r-tidyr
r-base64enc   r-dplyr     r-hexbin     r-mass      r-rcpp     r-tzdb
r-bit         r-ellipsis  r-htmltools  r-matrix    r-readr    r-utf8
r-bit64       r-fansi     r-isoband    r-mgcv      r-rlang    r-vctrs
r-cachem      r-farver    r-jsonlite   r-mime      r-sp       r-vroom
r-cli         r-fastmap   r-later      r-nlme      r-stringi  r-xfun
r-colorspace  r-ggrepel   r-lattice    r-plyr      r-sys      r-yaml
r-data.table  r-glue      r-lazyeval   r-promises  r-tibble
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Most of the time, cross-compiling an R package is very simple because the bulk of the work is handled by r-base. Building a package typically boils down to a single line:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nv"&gt;$R&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;CMD&lt;span class="w"&gt; &lt;/span&gt;INSTALL&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$R_ARGS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Occasionally, minor patches are applied to the package source code to enable the WebAssembly target platform or to simplify cross-compilation. Some R packages, such as r-nlme, contain Fortran code; for such packages, the custom flang compiler needs to be installed before the package can be cross-compiled. Should any package be needed for your use case, feel free to contribute them to emscripten-forge!&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="xeus-r"&gt;Xeus-R&lt;/h2&gt;
&lt;p&gt;Once a sufficient set of packages is available for the platform, the next step is to provide a development environment for end users. Our chosen tool for this purpose is Jupyter.&lt;/p&gt;
&lt;p&gt;The most popular Jupyter kernel for R is &lt;a href="https://github.com/IRkernel/IRkernel"&gt;IRkernel&lt;/a&gt;, which has been developed over several years. It includes complete ZeroMQ bindings for the R language and comprehensive coverage of the Jupyter protocol. However, since IRkernel is tied to ZeroMQ, we opted to work with the &lt;a href="https://github.com/jupyter-xeus/xeus-r"&gt;Xeus-R&lt;/a&gt; project instead, which was &lt;a href="https://blog.jupyter.org/posts/2024/meet-xeus-r-a-future-proof-jupyter-kernel-for-r/"&gt;announced last year&lt;/a&gt;. Xeus-R was developed by Romain François in collaboration with our team and with JupyterLite in mind. It is built upon the Xeus library, which provides a native implementation of the Jupyter protocol and is adapted to work with the JupyterLite frontend.&lt;/p&gt;
&lt;p&gt;Fortunately, the components of IRkernel responsible for the rich representation of R objects and rich display in Jupyter frontends were split into two separate R packages: &lt;strong&gt;IRdisplay&lt;/strong&gt; and &lt;strong&gt;repr&lt;/strong&gt;. These packages can be reused in Xeus-R. As a result, Xeus-R and IRkernel offer the same rich display functionality, ensuring that Jupyter notebooks created with one kernel will work with the other. However, Xeus-R provides a different implementation of the communication layer through &lt;a href="https://github.com/jupyterlite/xeus"&gt;jupyterlite-xeus&lt;/a&gt;, which enables integration with the JupyterLite stack. This integration was previously implemented for Xeus-Python and Xeus-Lua.&lt;/p&gt;
&lt;p&gt;One key aspect of this integration is the populating of the in-memory file system used by JupyterLite kernels with the required runtime dependencies, particularly shared libraries. This process is done upon bootstrapping the kernel. For this purpose, Anastiasiia Sliusar and Martin Renou developed &lt;a href="https://github.com/emscripten-forge/mambajs"&gt;mambajs&lt;/a&gt;, which, in combination with jupyterlite-xeus, processes conda packages in the frontend and installs them in the kernel filesystem at startup. In WebAssembly, shared libraries need to be handled with special care in order to function as expected. Drawing inspiration from the Python community, we adapted the pioneering work of Pyodide to properly load shared libraries into the filesystem.&lt;/p&gt;
&lt;h2 id="how-to-make-a-deployment-with-custom-packages"&gt;How to make a deployment with custom packages&lt;/h2&gt;
&lt;p&gt;The GitHub repository &lt;a href="https://github.com/jupyterlite/xeus-lite-demo"&gt;https://github.com/jupyterlite/xeus-lite-demo&lt;/a&gt; is a template for creating a JupyterLite deployment on GitHub pages that includes the packages specified in a conda environment.&lt;/p&gt;
&lt;p&gt;The process is as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a new repository from the GitHub template.&lt;/li&gt;
&lt;li&gt;Enable the deployment on GitHub pages from a GitHub action, as shown in the README.&lt;/li&gt;
&lt;li&gt;Edit the environment file to include the desired packages.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For example, to deploy an R kernel with coursekata installed, the environment.yml file would contain the following:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nt"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;xeus-r&lt;/span&gt;
&lt;span class="nt"&gt;channels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;https://repo.mamba.pm/emscripten-forge&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;conda-forge&lt;/span&gt;
&lt;span class="nt"&gt;dependencies&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;xeus-r&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p p-Indicator"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="l l-Scalar l-Scalar-Plain"&gt;r-coursekata&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The deployment linked at the beginning of this article was created with this template.&lt;/p&gt;
&lt;h2 id="how-to-contribute"&gt;How to contribute&lt;/h2&gt;
&lt;p&gt;Contributors are always welcome! New R packages can be requested by opening an issue on emscripten-forge, or added directly by opening a pull request with the desired package recipe. For instructions on how to contribute, please visit &lt;a href="https://emscripten-forge.org/"&gt;https://emscripten-forge.org/&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="what-is-in-the-works"&gt;What is in the works&lt;/h2&gt;
&lt;p&gt;Currently, we are developing the infrastructure to dynamically install emscripten-forge and conda-forge noarch packages in JupyterLite kernel environments. This will apply to all Xeus kernels that make use of these packages, such as Xeus-Python, Xeus-R, and Xeus-Lua. In the case of R, this may be directly bound to install.packages.&lt;/p&gt;
&lt;p&gt;Additionally, we are working on more advanced features for the R kernel, including support for Jupyter interactive widgets and the split of the pure R parts of xeus-r into a separate package, which would facilitate a possible convergence with IRkernel.&lt;/p&gt;
&lt;p&gt;Finally, other language kernels based on the same package management stack are also in the works. Stay tuned for future announcements!&lt;/p&gt;
&lt;hr&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="about-the-author"&gt;About the Author&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Isabel Paredes&lt;/strong&gt;, who led the charge on bringing R to emscripten-forge, is a senior scientific software developer at QuantStack. Prior to working on this project, she focused on porting the Robot Operating System (ROS) framework to WebAssembly.&lt;/p&gt;
&lt;h2 id="acknowledgments"&gt;Acknowledgments&lt;/h2&gt;
&lt;p&gt;This effort brought together several endeavors from many open-source developers.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;JupyterLite&lt;/strong&gt;, the Jupyter distribution that runs entirely in the web browser, was created by Jeremy Tuloup.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Xeus&lt;/strong&gt;, the C++ library implementing the Jupyter kernel protocol, enabling a custom communication layer, and is foundational to kernels like xeus-r, xeus-python, running in JupyterLite, was created by Johan Mabille and is maintained by a broader team including Martin Renou, Sylvain Corlay, and Thorsten Beier, who worked on the first integration with JupyterLite.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Emscripten-forge&lt;/strong&gt;, the distribution of conda packages for WebAssembly, was created by Thorsten Beier, who continues to lead the project. Many recipes were contributed by Isabel Paredes (for the R ecosystem), but also Kerim Birgi, Anutosh Bhat, Martin Renou, Wolf Vollprecht, and Johan Mabille.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Xeus-R&lt;/strong&gt;, the Xeus-based Jupyter kernel for R, was created by Romain François.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IRDisplay&lt;/strong&gt; and &lt;strong&gt;repr&lt;/strong&gt; are pure R packages providing rich display and rich mime type rendering of many core R types, which are used in xeus-r. These two packages stem from the IRkernel project, a Jupyter kernel for R written in R, which was started by Thomas Kluyver, and has been maintained over the years by Philipp Angerer and Jan Katins.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;MambaJS&lt;/strong&gt;, the library enabling the processing of conda packages in the frontend, was developed by Anastasiia Sliusar and Martin Renou.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Conda-forge&lt;/strong&gt;, the main distribution of conda packages, includes a large number of “noarch” recipes, including for R packages, and is developed by a broad community of contributors worldwide.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;WebR&lt;/strong&gt;, an R distribution for WebAssembly, was created by George Stagg. Although not directly used in this project, it documented numerous patches and changes to the Flang compiler that were adapted for this effort.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="funding"&gt;Funding&lt;/h2&gt;
&lt;p&gt;The work by &lt;strong&gt;Isabel Paredes&lt;/strong&gt; and other &lt;strong&gt;QuantStack&lt;/strong&gt; team members on bringing R and Xeus-R to Emscripten-Forge was supported by the &lt;a href="https://www.gatesfoundation.org/"&gt;&lt;strong&gt;Bill &amp;amp; Melinda Gates Foundation&lt;/strong&gt;&lt;/a&gt; through a grant to &lt;strong&gt;CourseKata&lt;/strong&gt;. CourseKata is a nonprofit project dedicated to improving statistics and data science education through interactive, research-backed curricula that integrate professional tools like R and Jupyter notebooks. This grant was part of CourseKata’s broader mission to scale its innovative curriculum, equipping students with the skills and confidence to engage with statistics, data science, and coding in meaningful ways.&lt;/p&gt;
&lt;hr class="footnotes-sep"&gt;
&lt;section class="footnotes"&gt;
&lt;ol class="footnotes-list"&gt;
&lt;li id="fn1" class="footnote-item"&gt;&lt;p&gt;Even though it powers the deployment of Jupyter on the main Jupyter website, JupyterLite is not an officially sanctioned Jupyter project. &lt;a href="#fnref1" class="footnote-backref"&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content><category term="JupyterLite"/><category term="kernels"/><category term="WebAssembly"/><category term="xeus"/></entry><entry><title>Meet Xeus-R: a future-proof Jupyter kernel for R</title><link href="https://blog.jupyter.org/posts/2024/meet-xeus-r-a-future-proof-jupyter-kernel-for-r/" rel="alternate"/><published>2024-01-22T17:20:00+00:00</published><updated>2024-01-22T17:20:00+00:00</updated><author><name>Romain François</name></author><id>tag:blog.jupyter.org,2024-01-22:/posts/2024/meet-xeus-r-a-future-proof-jupyter-kernel-for-r/</id><summary type="html">&lt;p&gt;The Jupyter ecosystem provides a versatile and user-friendly platform for data analysis and scientific computing, it has democratised access to powerful tools for researchers, scientists, educators, and data professionals.&lt;/p&gt;</summary><content type="html">&lt;figure&gt;
&lt;img alt="Screenshot of a Jupyter notebook with two cells displayed alongside a contextual help panel. The first cell shows the execution of an R command display(head(mtcars, 3)). The output is a nicely formatted table display with 3 rows. The second cell contains is a call to the ggplot function from the ggplot2 package. The output is a scatter plot of the variables hwy and displ, coloured by the class factor. The cursor shows auto completion for ggplot. On the right, contextual help for ggplot." src="https://blog.jupyter.org/posts/2024/meet-xeus-r-a-future-proof-jupyter-kernel-for-r/images/001-1_cFmKZKFycjvG1v_Xub4snQ.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;JupyterLab session with a notebook powered by the Xeus-R kernel for R&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The &lt;em&gt;Jupyter&lt;/em&gt; ecosystem provides a versatile and user-friendly platform for data analysis and scientific computing, it has democratised access to powerful tools for researchers, scientists, educators, and data professionals.&lt;/p&gt;
&lt;p&gt;The name &lt;em&gt;Jupyter&lt;/em&gt;, a blend of &lt;em&gt;Julia&lt;/em&gt;, &lt;em&gt;Python&lt;/em&gt;, and &lt;em&gt;R&lt;/em&gt; has always hinted at its relevance in multiple scientific programming languages and has since conquered new horizons thanks to its flexible and extensible design.&lt;/p&gt;
&lt;p&gt;Underneath the interactive surface of &lt;em&gt;Jupyter&lt;/em&gt; lie the &lt;em&gt;Jupyter&lt;/em&gt; kernels, a set of language specific engines orchestrating the dynamic execution and exploration of code. Kernels implement the &lt;em&gt;Jupyter&lt;/em&gt; protocol, a shared specification of the communication process between notebooks and kernels, defining how messages, commands and outputs are exchanged and processed.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;Xeus&lt;/em&gt; framework is a central piece of the puzzle, offering a reference to facilitate &lt;em&gt;Jupyter&lt;/em&gt; kernel implementations. The speed, extensibility, and alignment with the official protocol make &lt;em&gt;Xeus&lt;/em&gt; a perfect technology to implement new kernels.&lt;/p&gt;
&lt;h2 id="xeus-r"&gt;Xeus-R&lt;/h2&gt;
&lt;p&gt;Today, we, &lt;em&gt;a collaborative team led by Romain François and supported by QuantStack&lt;/em&gt;, are thrilled to announce the initial release of &lt;em&gt;Xeus-R&lt;/em&gt;, a future-proof &lt;em&gt;Jupyter&lt;/em&gt; kernel for R. &lt;em&gt;Xeus-R&lt;/em&gt; builds upon the components of &lt;em&gt;Xeus&lt;/em&gt; to facilitate the use of &lt;em&gt;R&lt;/em&gt; in &lt;em&gt;Jupyter&lt;/em&gt; notebooks and already supports typical capabilities: &lt;em&gt;R&lt;/em&gt; code execution, inspection, completion, and contextual help.&lt;/p&gt;
&lt;p&gt;The recent advancements in support for &lt;em&gt;WebAssembly&lt;/em&gt; in the &lt;em&gt;R&lt;/em&gt; world led by the &lt;em&gt;WebR&lt;/em&gt; project, the flexible design of Xeus, and the rise of &lt;em&gt;JupyterLite&lt;/em&gt; all contribute to our strong belief that &lt;em&gt;Xeus-R&lt;/em&gt; has the potential to deliver &lt;em&gt;Jupyter&lt;/em&gt; in-browser experience for data scientists using &lt;em&gt;R&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Xeus-R&lt;/em&gt; is currently at the stage of a proof of concept, but we wanted to communicate about it early to broadcast our excitement about its potential, share some of our thoughts, and initiate a conversation.&lt;/p&gt;
&lt;h2 id="relationship-with-irkernel"&gt;Relationship with IRkernel&lt;/h2&gt;
&lt;p&gt;While the &lt;em&gt;IRkernel&lt;/em&gt; project paved the way and is the current reference implementation of a &lt;em&gt;Jupyter&lt;/em&gt; kernel for R, it does not take advantage of the &lt;em&gt;Xeus&lt;/em&gt; infrastructure and includes a complete implementation of the &lt;em&gt;Jupyter&lt;/em&gt; protocol, down to the composition of all of the &lt;em&gt;JSON&lt;/em&gt; messages and most importantly how they are transported through &lt;em&gt;ZeroMQ&lt;/em&gt; sockets.&lt;/p&gt;
&lt;p&gt;In contrast, &lt;em&gt;Xeus-R&lt;/em&gt; fully embraces and leverages the capabilities of &lt;em&gt;Xeus&lt;/em&gt;, while borrowing some higher level concepts from &lt;em&gt;IRkernel&lt;/em&gt; and reusing features from its dependent packages &lt;em&gt;IRdisplay&lt;/em&gt; and &lt;em&gt;repr&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;We believe this path will benefit future development as it gives us the freedom to work on innovations that are specific to the needs of &lt;em&gt;R&lt;/em&gt; users, and let &lt;em&gt;Xeus&lt;/em&gt; absorb evolutions of the &lt;em&gt;Jupyter&lt;/em&gt; protocol.&lt;/p&gt;
&lt;h2 id="key-features"&gt;Key features&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Xeus-R&lt;/em&gt; implements the basic building blocks of what you would expect from a &lt;em&gt;Jupyter&lt;/em&gt; kernel. The results of a code cell, i.e. the value of its last expression are displayed in the output, taking advantage of &lt;em&gt;ANSI&lt;/em&gt; escape codes for colours as were made popular by the &lt;em&gt;crayon&lt;/em&gt; and later &lt;em&gt;cli&lt;/em&gt; &lt;em&gt;R&lt;/em&gt; packages.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2024/meet-xeus-r-a-future-proof-jupyter-kernel-for-r/images/002-1_XznRckf13HpNy_S7h7-_iA.webp" alt="Screenshot of a Jupyter notebook with 3 cells visible. The first cell [2] contains a line of R code that uses cat and glue to print “hello world” with “world” coloured in green thanks the col_green function from the cli package. The second cell [3] shows the command head(mtcars) which outputs a plain text version of the first 6 rows of the mtcars data frame. The third cell [9] contains R code that loads the tibble package and then prints mtcars as a tibble, therefore benefitting from formatting." loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;Traditional and &lt;em&gt;ggplot2&lt;/em&gt;-powered graphics are captured and displayed as images. The aspect ratio of plots can be controlled by setting the &lt;em&gt;repr.plot.height&lt;/em&gt; and &lt;em&gt;repr.plot.width&lt;/em&gt; options either globally, or locally via the &lt;em&gt;cell_options()&lt;/em&gt; function.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2024/meet-xeus-r-a-future-proof-jupyter-kernel-for-r/images/003-1_oi1bSbjYZg_I_H104v-75g.webp" alt="A Jupyter notebook cell [13] with R code and its output. The code sets options locally with the cell_options() function and then creates a box plot with the following code: boxplot(decrease ~ treatment, data = OrchardSprays, col = “bisque”, log = “y”). The output is a a graphic with 8 boxplots, representing the treatment factor and its levels A to H on the x axis, and the variable decrease on the y axis, with a logarithmic scale." loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2024/meet-xeus-r-a-future-proof-jupyter-kernel-for-r/images/004-1_7bZITs9PxXYWwqgDWEniJg.webp" alt="Screenshot of a Jupyter notebook cell [15] with R code and output. The code is loading the ggplot2 package and then creating a scatterplot with the following code: ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point(). The resulting plot is a scatter plot with displ on the x axis and fwy on the y axis, showing different colored points representing different classes of vehicles from the class factor." loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;Thanks to the scaffolding in place in the &lt;em&gt;IRdisplay&lt;/em&gt; and &lt;em&gt;repr&lt;/em&gt; packages, &lt;em&gt;Xeus-R&lt;/em&gt; is also able to emit richer displays through mime bundles.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2024/meet-xeus-r-a-future-proof-jupyter-kernel-for-r/images/005-1_-T33jRshu16eWh96_OVuvA.webp" alt="Screenshot of a Jupyter notebook with 2 cells with R code. The first cell [16] contains the command display(1:10). The output shows a rich representation of 1:10: the numbers 1 to 10 separated by dots. The second cell [17] also uses the display function to create a rich display of the first 6 rows of the mtcars data frame: display(head(mtcars)). The result presents the data frame as a well formatted table display with alternating shading for rows to improve readability." loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;In contrast with &lt;em&gt;IRkernel&lt;/em&gt;, the rich displays need to be explicitly requested with the &lt;em&gt;display()&lt;/em&gt; function. There are cases however, such as &lt;em&gt;HTML&lt;/em&gt; widgets, where automatic rich display makes the most sense because a text/plain representation is not valuable.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2024/meet-xeus-r-a-future-proof-jupyter-kernel-for-r/images/006-1_5QOitnpbBdDNpQ9ERIILpg.webp" alt="Screenshot of a Jupyter notebook cell [24] showing R code that uses packages htmltools and plotly to create an HTML widget with 2 plotly-powered histograms. The result first shows information messages about conflicts, then shows two typical plotly-powered histograms. The top histogram shows a selection, indicating that the display is about to be zoomed in a smaller value range, to show that the HTML widget can be interacted with." loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Xeus-R&lt;/em&gt; also supports contextual help and includes a basic completion system, based on the internal &lt;em&gt;utils::.getTokenFromLine()&lt;/em&gt; system.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2024/meet-xeus-r-a-future-proof-jupyter-kernel-for-r/images/007-1_jWuiihVGV0_7utFx3Tzvng.webp" alt="Screenshot of a Jupyter notebook interface with an open R code cell and a contextual help panel side by side. On the left side, the code cell is active with the incomplete R function call “rnorm(“ being typed, and an auto-completion tooltip showing the options “n=”, “mean=”, “sd=”. The tooltip also shows a repetition of the function name “rnorm”. On the right side, the contextual help panel shows the documentation for the rnorm function." loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;h2 id="installation-and-getting-started"&gt;Installation and Getting Started&lt;/h2&gt;
&lt;p&gt;At the time of writing this article, &lt;em&gt;Xeus-R&lt;/em&gt; is only available and tested to work on Unix-based systems. We consciously decided to focus initial efforts on features rather than platform comprehensiveness, but we should be able to fix this soon enough.&lt;/p&gt;
&lt;p&gt;The easiest way to get up and running with &lt;em&gt;Xeus-R&lt;/em&gt; is to install it from conda-forge:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;mamba&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;xeus-r
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Instructions to build from source are available in the github repository for &lt;em&gt;Xeus-R&lt;/em&gt;: &lt;a href="https://github.com/jupyter-xeus/xeus-r"&gt;https://github.com/jupyter-xeus/xeus-r&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="looking-ahead-jupyterlite-integration"&gt;Looking ahead: JupyterLite Integration&lt;/h2&gt;
&lt;p&gt;Another benefit of a &lt;em&gt;Xeus&lt;/em&gt;-based approach is that it has been designed in a way that supports in-browser experience to power &lt;em&gt;JupyterLite&lt;/em&gt;. Together with the recent developments around &lt;em&gt;WebR&lt;/em&gt;, we can envision &lt;em&gt;R&lt;/em&gt; becoming a first-class citizen in the &lt;em&gt;JupyterLite&lt;/em&gt; world.&lt;/p&gt;
&lt;p&gt;This is an exciting vision and will serve as our North Star ⭐️ for future developments of &lt;em&gt;Xeus-R&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id="conclusion"&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Join us in welcoming &lt;em&gt;Xeus-R&lt;/em&gt;, a &lt;em&gt;Jupyter&lt;/em&gt; kernel for &lt;em&gt;R&lt;/em&gt; that leverages the robust foundation of &lt;em&gt;Xeus&lt;/em&gt; architecture. &lt;em&gt;R&lt;/em&gt; is a language of paramount importance for Data Science and Scientific Computing and it rightfully deserves its place as a first-class citizen within the &lt;em&gt;Jupyter&lt;/em&gt; ecosystem.&lt;/p&gt;
&lt;p&gt;We firmly believe that &lt;em&gt;Xeus-R&lt;/em&gt; has the potential to become a reference implementation for an &lt;em&gt;R&lt;/em&gt; kernel, well positioned to tackle the challenges of the ever-evolving landscape of in-browser Scientific Computing, a promising future led by the &lt;em&gt;JupyterLite&lt;/em&gt; and &lt;em&gt;WebR&lt;/em&gt; projects.&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="acknowledgements"&gt;Acknowledgements&lt;/h2&gt;
&lt;p&gt;The work by Romain François on Xeus-R was funded by &lt;a href="https://twitter.com/QuantStack"&gt;QuantStack&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="author-bio"&gt;Author Bio&lt;/h2&gt;
&lt;p&gt;&lt;a href="http://www.linkedin.com/in/romain-francois"&gt;Romain François&lt;/a&gt; is a prominent figure in the &lt;em&gt;R&lt;/em&gt; community, recognised for his longstanding contributions to &lt;em&gt;R&lt;/em&gt; programming and Data Analysis. With a profound passion for open-source software and commitment to advancing the capabilities of &lt;em&gt;R&lt;/em&gt;, he has earned a well-deserved reputation as a respected expert.&lt;/p&gt;
&lt;p&gt;Romain’s expertise encompasses a wide spectrum of &lt;em&gt;R&lt;/em&gt;-related fields, including package development, data manipulation, and interoperability with other programming languages. He is widely recognized for his work on packages like &lt;em&gt;dplyr&lt;/em&gt;, which has become a cornerstone for efficient data manipulation in &lt;em&gt;R&lt;/em&gt;, and for his contributions to &lt;em&gt;Rcpp&lt;/em&gt;, a library that bridges the power of &lt;em&gt;C++&lt;/em&gt; with &lt;em&gt;R&lt;/em&gt; for optimizing &lt;em&gt;R&lt;/em&gt; packages and enhancing performance.&lt;/p&gt;
</content><category term="kernels"/><category term="xeus"/></entry><entry><title>Plug your application into the Jupyter world</title><link href="https://blog.jupyter.org/posts/2023/plug-your-application-into-the-jupyter-world/" rel="alternate"/><published>2023-10-23T06:09:00+00:00</published><updated>2023-10-23T06:09:00+00:00</updated><author><name>David Brochart</name></author><id>tag:blog.jupyter.org,2023-10-23:/posts/2023/plug-your-application-into-the-jupyter-world/</id><summary type="html">&lt;p&gt;Kernels are a simple but powerful abstraction in the Jupyter architecture. They encapsulate language interpreters and make them accessible through a standardized interface. This is the key to Jupyter’s remarkable versatility, with over 100 supported languages.&lt;/p&gt;</summary><content type="html">&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2023/plug-your-application-into-the-jupyter-world/images/001-1_ENzq7i52UtqxESs4UTKBYw.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;Kernels are a simple but powerful abstraction in the Jupyter architecture. They encapsulate language interpreters and make them accessible through a standardized interface. This is the key to Jupyter’s remarkable versatility, with over 100 supported languages. Embedding a kernel in your custom application can seamlessly expose it to the Jupyter ecosystem. Not only can you attach JupyterLab to your program for e.g. state inspection, as you would do with a debugger, but you can truly extend your application with all the power of the Jupyter ecosystem.&lt;/p&gt;
&lt;h2 id="applications-gui-and-api"&gt;Applications: GUI and API&lt;/h2&gt;
&lt;p&gt;Several applications such as &lt;a href="https://www.freecad.org/"&gt;FreeCAD&lt;/a&gt;, &lt;a href="https://docs.blender.org/api/current/"&gt;Blender&lt;/a&gt;, or &lt;a href="https://docs.qgis.org/3.28/en/docs/pyqgis_developer_cookbook/index.html"&gt;QGIS&lt;/a&gt; provide a Python API to access their functionalities programmatically, and include an embedded Python console which allows using this API from within the application. Users can both use the graphical user interface and operate on the application in a scripted fashion depending on their needs.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Python consoles in FreeCAD, Blender, and QGIS (from left to right)." src="https://blog.jupyter.org/posts/2023/plug-your-application-into-the-jupyter-world/images/002-1_EMYG_XFNokXREwsUa9pbFA.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Python consoles in FreeCAD, Blender, and QGIS (from left to right).&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;If you think about it, these are the kinds of workflows that Jupyter has always been about, but Jupyter has evolved in the opposite direction. Instead of adding scripting to GUIs, Jupyter added GUIs to scripting. At first, Jupyter was IPython, a console for interactive computing. Then it went to the Web and became IPython Notebook, renamed to Jupyter Notebook. With the browser it became possible to display richer content and create small GUIs, using Jupyter Widgets. Then JupyterLab was created and allowed to create fully-fledged desktop-like applications in the browser, like 3-D CAD modelers.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="JupyterLab showing notebooks using JupyterCAD and ipyleaflet." src="https://blog.jupyter.org/posts/2023/plug-your-application-into-the-jupyter-world/images/003-1_m4WwlNYiIvMeZu1eXhrl7Q.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;JupyterLab showing notebooks using JupyterCAD and ipyleaflet.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Jupyter put a lot of attention on building a good experience interacting with the Python REPL, which is not the main focus of domain-specific desktop applications. The Python console embedded in desktop applications is often quite raw. Allowing users to connect from Jupyter can enable a much better experience.&lt;/p&gt;
&lt;p&gt;What if there was a bridge that allowed you to connect both worlds, your application on one side and Jupyter on the other side? What is the common denominator allowing code to interact with an application, while also being shared with Jupyter? In the Jupyter infrastructure, we call it a kernel.&lt;/p&gt;
&lt;h2 id="jupyter-kernels"&gt;Jupyter kernels&lt;/h2&gt;
&lt;p&gt;Kernels provide a standardized way to expose language interpreters to applications, in a language-agnostic fashion. You can think of it as a server that accepts requests such as “execute this piece of code” and that replies with a result. The result is actually a data representation, it can be as simple as “3” for an input of “1+2”, or a complex interactive plot. A kernel usually lives in a separate process on your machine, but it can also run in the same process, or even remotely on another machine. Someone wanting to connect to this kernel will need the connection information such as the IP address and the ports of the different communication “channels”. It is stored in what is called a connection file.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="The Jupyter kernel protocol allows clients to interact with different languages." src="https://blog.jupyter.org/posts/2023/plug-your-application-into-the-jupyter-world/images/004-1_ywYEVpCKlbL6aBEGERsXSw.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The Jupyter kernel protocol allows clients to interact with different languages.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Anyone who has access to this connection file can then execute code in the kernel. This is “shared code”, meaning that every client to this kernel eventually runs code in the same interpreter. If one client sets a variable “a=1”, other clients will see this variable. They are all running the “same program”. If the kernel runs in the same process as the application, then the kernel can interact directly with it. This way of sharing the execution engine serves as a bridge between the application and Jupyter.&lt;/p&gt;
&lt;p&gt;Now it is just a matter of exposing the connection file so that e.g. JupyterLab can see it. The application launching the kernel can save the connection file to a specific directory, and give the path to JupyterLab. And that’s it, JupyterLab can run a notebook using this kernel, allowing it to interact with the application.&lt;/p&gt;
&lt;h2 id="getting-started"&gt;Getting started&lt;/h2&gt;
&lt;p&gt;The &lt;a href="https://github.com/jupyter-xeus/xeus-qt-python"&gt;xeus-qt-python&lt;/a&gt; repository is a great place to start and see how to embed a Python kernel inside a Qt application. Under the hood, it uses &lt;a href="https://github.com/jupyter-xeus/xeus-qt"&gt;xeus-qt&lt;/a&gt;, an integration of the &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;xeus&lt;/a&gt; kernel architecture in the Qt event loop. The Qt application actually runs JupyterLab in a Qt WebEngine window. Users can run code in a notebook and interact with the application, which in turn can interact with the notebook. Here, we create a Qt button from a notebook. When clicking on the button, a callback prints a message in the notebook. This demonstrates a two-way binding between the Qt application and JupyterLab.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Example of a Qt application embedding JupyterLab." src="https://blog.jupyter.org/posts/2023/plug-your-application-into-the-jupyter-world/images/005-1_FTlpril_YV5W6-xYelNrtA.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Example of a Qt application embedding JupyterLab.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;a href="https://github.com/Slicer/SlicerJupyter"&gt;SlicerJupyter&lt;/a&gt; from Kitware was one of the first applications to take advantage of this approach. You can read more in this &lt;a href="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/"&gt;blog post&lt;/a&gt;. We hope that this technology will unlock a new brand of use-cases and allow applications to reach a new audience through the Jupyter ecosystem. Please reach out to us if you need help!&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h3 id="about-the-author"&gt;About the author&lt;/h3&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2023/plug-your-application-into-the-jupyter-world/images/006-1_gGWqElhixsQA-cGOzWcb7w.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://twitter.com/davidbrochart"&gt;&lt;strong&gt;David Brochart&lt;/strong&gt;&lt;/a&gt; is a technical director at QuantStack. He mostly works on the Jupyter backend stack. He contributed to the development of real-time collaboration in JupyterLab, and created the &lt;a href="https://davidbrochart.github.io/jupyverse/"&gt;Jupyverse&lt;/a&gt; project, a next-generation implementation of the Jupyter server.&lt;/p&gt;
&lt;h3 id="acknowledgments"&gt;Acknowledgments&lt;/h3&gt;
&lt;p&gt;This work was made possible thanks to several contributors. &lt;a href="https://twitter.com/mari_meir"&gt;&lt;strong&gt;Mariana Meireles&lt;/strong&gt;&lt;/a&gt; was the initial author of &lt;a href="https://github.com/jupyter-xeus/xeus-qt"&gt;xeus-qt&lt;/a&gt;. &lt;a href="https://twitter.com/ThorstenBeier"&gt;&lt;strong&gt;Thorsten Beier&lt;/strong&gt;&lt;/a&gt; is a scientific software developer at QuantStack and contributes to the &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;xeus&lt;/a&gt; kernel ecosystem. He is the initial creator of the &lt;a href="https://github.com/jupyter-xeus/xeus-qt-python"&gt;xeus-qt-python&lt;/a&gt; demonstration. &lt;a href="https://twitter.com/JohanMabille"&gt;&lt;strong&gt;Johan Mabille&lt;/strong&gt;&lt;/a&gt; is a technical director at QuantStack and he is the main author of &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;xeus&lt;/a&gt;. &lt;strong&gt;Afshin Darian&lt;/strong&gt; is a technical director at QuantStack and worked on the UI in JupyterLab 4.0 allowing to use an external kernel.&lt;/p&gt;
</content><category term="kernels"/><category term="xeus"/></entry><entry><title>A Jupyter kernel for GNU Octave</title><link href="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/" rel="alternate"/><published>2023-01-11T17:33:00+00:00</published><updated>2023-01-11T17:33:00+00:00</updated><author><name>Giulio Girardi</name></author><id>tag:blog.jupyter.org,2023-01-11:/posts/2023/a-jupyter-kernel-for-gnu-octave/</id><summary type="html">&lt;p&gt;Today, we are happy to announce the xeus-octave project, a Jupyter kernel for GNU Octave.&lt;/p&gt;
</summary><content type="html">&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/images/001-0__HZJpXD-awr4mPDG.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;GNU Octave is a long-standing member of the scientific computing ecosystem, featuring a mathematics-oriented syntax with built-in 2D/3D plotting and visualization tools, and compatible with the Matlab syntax. It is a natural candidate for high-quality integration in the Jupyter ecosystem.&lt;/p&gt;
&lt;p&gt;Jupyter has been devised with language agnosticism in mind since it was spun off from the IPython project. The Kernel (the part of the infrastructure responsible for executing the code input by the user) is a key extension point to Jupyter, and dozens of language kernels exist in the ecosystem.&lt;/p&gt;
&lt;p&gt;Prior art on Jupyter / GNU Octave integration includes the &lt;a href="https://github.com/Calysto/octave_kernel"&gt;Calysto/Octave_kernel&lt;/a&gt; project by Steven Silvester (who is also a core Jupyter maintainer and the co-creator of JupyterLab). This existing kernel is part of the family of kernels built on top of the &lt;a href="https://github.com/ipython/ipykernel"&gt;ipykernel&lt;/a&gt; reference implementation of the Jupyter protocol, in Python.&lt;/p&gt;
&lt;p&gt;Today, we are happy to announce the &lt;a href="https://github.com/jupyter-xeus/xeus-octave/"&gt;xeus-octave&lt;/a&gt; project, a Jupyter kernel for GNU Octave. Xeus-octave was created by &lt;a href="http://rapgenic.it/"&gt;Giulio Girardi&lt;/a&gt;, recently joined by &lt;a href="https://twitter.com/AntoineProuvost"&gt;Antoine Prouvost&lt;/a&gt; — and has been incorporated into the Project Jupyter governance.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/images/002-0__YEF9gl4rxnapBiz.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;Xeus-octave is built upon the &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt; library, a C++ implementation of the Jupyter kernel protocol that enables fast development of new kernels using programming languages’ native APIs, unlocking new possibilities without parsing standard outputs or requiring a Python interpreter at runtime. After all, a Jupyter kernel is merely an executable providing a well-defined communication protocol. It is not bound to Python APIs.&lt;/p&gt;
&lt;h2 id="a-fully-featured-kernel"&gt;A fully-featured kernel&lt;/h2&gt;
&lt;p&gt;We strove to make the xeus-octave kernel as complete as possible for this first iteration.&lt;/p&gt;
&lt;h3 id="multiple-graphical-toolkits"&gt;Multiple graphical toolkits&lt;/h3&gt;
&lt;h4 id="notebook"&gt;Notebook&lt;/h4&gt;
&lt;p&gt;A &lt;code&gt;notebook&lt;/code&gt; Octave graphical toolkit can be used to render plots natively, and present the figure as an image in the notebook.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Screenshot of GNU Octave in action in Jupyter with the native Octave plots" src="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/images/003-0_0tfvTOYDrjvK6SyO.jpg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The classic Octave sombrero plot rendered as an image inside the notebook&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h4 id="plotly"&gt;Plotly&lt;/h4&gt;
&lt;p&gt;An experimental &lt;code&gt;plotly&lt;/code&gt; Octave graphical toolkit can also use &lt;a href="https://plotly.com/"&gt;Plotly&lt;/a&gt; to render code in the browser, with dynamic views, zooms, and hover tooltips.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Screenshot of GNU Octave in action in Jupyter with the Plotly plots" src="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/images/004-0_ZT86_erLnKUyRvP4.jpg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Multiple plots rendered in a single plotly figure&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h3 id="rich-display"&gt;Rich display&lt;/h3&gt;
&lt;p&gt;The kernel binds with the C++ interface of GNU Octave to provide a complete Octave experience. Having access to the exact internal type of the objects, xeus-octave can present data with rich output.&lt;/p&gt;
&lt;p&gt;Matrices can be presented as HTML or LaTeX tables.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/images/005-0_015CLZOO-yfxSRSe.webp" alt="Screenshot of GNU Octave in action in Jupyter with the rich rendering of matrices" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;Symbolic expressions can be presented as LaTeX formulas.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/images/006-0_U-Nxc_9FqhxARiGF.webp" alt="Screenshot of GNU Octave in action in Jupyter with the rich rendering of equations" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;Structured data can be visualized as interactive tree views&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/images/007-0_oshl__rdb1-OtfCM.webp" alt="Screenshot of GNU Octave in action in Jupyter with the rich rendering of Octave structured data as interactive tree views." loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;h3 id="interactive-help"&gt;Interactive help&lt;/h3&gt;
&lt;p&gt;Formatted help, extracted from the GNU Octave reference manual, can be queried using the &lt;code&gt;?&lt;/code&gt; syntax.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/images/008-0_zQcXBUjgbwqY0IHG.webp" alt="Screenshot of GNU Octave in action in Jupyter with the interactive help displayed in an output cell" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;h2 id="trying-it-online"&gt;Trying it online&lt;/h2&gt;
&lt;p&gt;You can try the new Jupyter kernel for GNU Octave by clicking on the link below:&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://mybinder.org/v2/gh/jupyter-xeus/xeus-octave/stable?urlpath=/lab/tree/notebooks/xeus-octave.ipynb"&gt;&lt;img src="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/images/009-0_SDB4IuVwEGuk2yz1.webp" alt="Logo of Binder" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The Binder linked above includes examples of notebooks in the fields of Electronics, demonstrating the usability of xeus-octave in real-life complex scenarios.&lt;/p&gt;
&lt;p&gt;This interactive demo is also featured on the Jupyter website at &lt;a href="https://jupyter.org/try#kernels"&gt;https://jupyter.org/try#kernels&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="installing-xeus-octave"&gt;Installing xeus-octave&lt;/h2&gt;
&lt;p&gt;Xeus-octave has been packaged on conda-forge and can be installed with mamba or conda.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;$&lt;span class="w"&gt; &lt;/span&gt;mamba&lt;span class="w"&gt; &lt;/span&gt;install&lt;span class="w"&gt; &lt;/span&gt;xeus-octave&lt;span class="w"&gt; &lt;/span&gt;-c&lt;span class="w"&gt; &lt;/span&gt;conda-forge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="future-work"&gt;Future Work&lt;/h2&gt;
&lt;p&gt;In future iterations, we will work towards consolidating the xeus-octave experience, by adding cell magics and improving the Plotly integration.&lt;/p&gt;
&lt;p&gt;A major ongoing development is the implementation of an Octave backend for Jupyter interactive widgets, based on the &lt;a href="https://github.com/jupyter-xeus/xwidgets"&gt;xwidgets&lt;/a&gt; project. Combined with &lt;a href="https://github.com/voila-dashboards/voila"&gt;Voilà&lt;/a&gt;, it will be possible to use GNU Octave to create standalone web dashboards.&lt;/p&gt;
&lt;p&gt;Another ongoing endeavor is to port a growing portion of the scientific computing stack to WebAssembly (using the emscripten-forge project). Producing a Wasm build of GNU Octave will enable its use with &lt;a href="https://github.com/jupyterlite/jupyterlite"&gt;Jupyterlite&lt;/a&gt;, enabling large-scale deployments on websites, blogs, and arbitrary web pages without any need for scalable cloud infrastructure.&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="about-the-authors"&gt;About the authors&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/images/010-1_h3ZtdyQicGecxGFPkc3tYQ.jpeg" alt="Headshot of Antoine Prouvost" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://twitter.com/AntoineProuvost"&gt;Antoine Prouvost&lt;/a&gt; is a Scientific Software Engineer at &lt;a href="https://twitter.com/QuantStack"&gt;QuantStack&lt;/a&gt; and a xeus-octave maintainer. Previously, Antoine was researching Machine Learning and Combinatorial Optimization at the &lt;a href="https://twitter.com/DS4DM"&gt;DS4DM&lt;/a&gt; research chair and &lt;a href="https://twitter.com/MILAMontreal"&gt;Mila&lt;/a&gt;.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2023/a-jupyter-kernel-for-gnu-octave/images/011-1_vUpNORkYEpszm-vTZoSXwg.jpeg" alt="Headshot of Giulio Girardi" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://rapgenic.it/"&gt;Giulio Girardi&lt;/a&gt; is a Master’s degree student in Electronic Engineering at the &lt;a href="https://twitter.com/UniPadova"&gt;UNIPD&lt;/a&gt;, currently working as an Electronic Engineer at &lt;a href="http://protechgroup.it/"&gt;Protech Engineering&lt;/a&gt;. Giulio is the creator and a maintainer of the xeus-octave project.&lt;/p&gt;
</content><category term="kernels"/><category term="xeus"/></entry><entry><title>Mamba meets JupyterLite</title><link href="https://blog.jupyter.org/posts/2022/mamba-meets-jupyterlite/" rel="alternate"/><published>2022-07-14T11:19:00+00:00</published><updated>2022-07-15T10:26:00+00:00</updated><author><name>Thorsten Beier</name></author><id>tag:blog.jupyter.org,2022-07-14:/posts/2022/mamba-meets-jupyterlite/</id><summary type="html">&lt;p&gt;Introducing a mamba-based distribution for WebAssembly, and deploying scalable computing environments with JupyterLite.&lt;/p&gt;
</summary><content type="html">&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2022/mamba-meets-jupyterlite/images/001-1_dbJO26hiSR8EFygX1rnqrA.webp" alt="JupyterLite logo" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;JupyterLite is a Jupyter distribution that runs entirely in the web browser without any server components. To achieve this, all language kernels must also run in the browser.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="A screenshot of JupyterLite running in the Browser. One can see as Matplotlib figure and some Pandas DataFrame code. Furthermore a p5.js kernel instance is visible." src="https://blog.jupyter.org/posts/2022/mamba-meets-jupyterlite/images/002-0_MoW-XpW5yQgCxinq.jpg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;JupyterLite running in the browser as a static website&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;A significant benefit of this approach is the &lt;strong&gt;ease of deployment&lt;/strong&gt;. With JupyterLite, the only requirement to provide a live computing environment is a collection of static assets. It makes it possible to embed a console or a notebook interface on any static page or blog without having to deal with a server architecture deployment. The &lt;strong&gt;scalability&lt;/strong&gt; of this approach allowed several major projects of our ecosystem (&lt;a href="https://numpy.org"&gt;NumPy&lt;/a&gt;, &lt;a href="https://www.sympy.org/en/shell.html"&gt;SymPy&lt;/a&gt;, &lt;a href="https://pandas.pydata.org/getting_started.html"&gt;Pandas&lt;/a&gt;, &lt;a href="https://www.pymc.io/welcome.html"&gt;PyMC&lt;/a&gt;, and many more) to embed interactive examples on their websites, which are visited by millions of users monthly.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;JupyterLite is the easiest and most scalable way to embed an interactive console or notebook on a web page without any server component.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The most prominent JupyterLite kernel is the &lt;em&gt;Pyolite&lt;/em&gt; Python kernel, which is based on the &lt;a href="https://pyodide.org/en/stable/"&gt;Pyodide&lt;/a&gt; distribution for WebAssembly. Beyond the CPython interpreter, Pyodide includes many popular scientific computing packages such as NumPy, Pandas, and Matplotlib. Pyodide also provides a foreign function interface (FFI) that allows calling Python from JavaScript and vice versa.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="The JupyterLite inline console embedded on the SymPy project website" src="https://blog.jupyter.org/posts/2022/mamba-meets-jupyterlite/images/003-1_rKzDNlHO6LnhH1ZDyb996g.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The JupyterLite inline console embedded on the &lt;a href="https://www.sympy.org/en/shell.html"&gt;SymPy project website&lt;/a&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="pyodide-and-beyond"&gt;Pyodide — and beyond&lt;/h2&gt;
&lt;p&gt;While Pyodide provides many scientific computing packages, its monolithic distribution model does not allow to specify package versions, although versions of pure python packages installed on top can be set. Our goal is to enable the &lt;strong&gt;composability of computing environments&lt;/strong&gt; allowed by package managers and to adopt the conda-forge model for large-scale software distribution crowdsourcing.&lt;/p&gt;
&lt;p&gt;Being able to pin down package versions in an environment is a strong requirement for software &lt;strong&gt;reproducibility.&lt;/strong&gt; In fact, a locked WebAssembly environment could be seen as a reproducibility &lt;strong&gt;time capsule&lt;/strong&gt;. As WebAssembly is a recognized web standard, it ought to be runnable for much longer than native binary packages: these are bound to a combination of architecture and platform and will eventually require an emulator.&lt;/p&gt;
&lt;p&gt;This is why we developed a mamba-based distribution of WebAssembly packages built with Emscripten.&lt;/p&gt;
&lt;h2 id="emscripten-forge"&gt;Emscripten-forge&lt;/h2&gt;
&lt;p&gt;The choice of the Mamba/Conda package manager was natural. Its main strength is the conda-forge community-maintained distribution, which has become the &lt;em&gt;de facto&lt;/em&gt; standard source of packages for scientific computing.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Beyond its solid technological foundations and the multi-platform nature of the conda-forge distribution, its main strength is its social model. It allowed for a crowdsourcing approach of the packaging problem, with a balance of separation of concerns between maintainer teams and across-the-board automation, plus an amazing maintainers community.&lt;/p&gt;
&lt;p&gt;We plan on contributing this work to the conda-forge project, so that all recipes live in the same space.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The Mamba/Conda package manager has support for many platforms and architectures such as Linux, OS X (for both x86 and arm64), and Windows. However, the &lt;strong&gt;WebAssembly&lt;/strong&gt; family of platforms is not supported yet.&lt;/p&gt;
&lt;h3 id="adding-support-for-webassembly-to-mamba-conda"&gt;Adding support for WebAssembly to mamba &amp;amp; conda&lt;/h3&gt;
&lt;p&gt;To create conda packages for the WebAssembly platform, we relied on the &lt;a href="https://emscripten.org/"&gt;Emscripten toolchain&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We defined a new target platform for conda-build and boa, namely &lt;code&gt;wasm32-unknown-emscripten&lt;/code&gt; for which we use the &lt;code&gt;emscripten-32&lt;/code&gt; shorthand name. We then associated the &lt;a href="https://emscripten.org/"&gt;Emscripten&lt;/a&gt; compiler, &lt;a href="https://github.com/emscripten-forge/recipes/tree/main/recipes/recipes/emscripten_emscripten-32"&gt;wrapped in a conda package&lt;/a&gt; as the C/C++ compiler for this new target.&lt;br&gt;
This already allowed us to build many packages, including simple libraries like &lt;code&gt;bzip2&lt;/code&gt; and &lt;code&gt;zlib&lt;/code&gt;, but also more complex packages like &lt;code&gt;Python&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For Python extension modules we used &lt;a href="https://github.com/benfogle/crossenv"&gt;&lt;code&gt;crossenv&lt;/code&gt;&lt;/a&gt; which can create virtual environments for cross-compiling, and &lt;a href="https://github.com/conda-forge/cross-python-feedstock"&gt;&lt;code&gt;cross-python&lt;/code&gt;&lt;/a&gt; which integrates &lt;a href="https://github.com/benfogle/crossenv"&gt;&lt;code&gt;crossenv&lt;/code&gt;&lt;/a&gt; into conda. All the code and recipes for cross-compilation are hosted on the &lt;a href="https://github.com/emscripten-forge/recipes"&gt;emscripten-forge GitHub repository&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;We then used &lt;a href="https://github.com/emscripten-forge/recipes/blob/main/.github/workflows/build_recipes.yaml"&gt;GitHub actions&lt;/a&gt; to build packages with Emscripten and upload them to a package server.&lt;/li&gt;
&lt;li&gt;Packages are hosted on a deployment of the &lt;a href="https://github.com/mamba-org/quetz"&gt;Quetz&lt;/a&gt; open-source server.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With this, you can easily create an environment for the &lt;code&gt;emscripten-32&lt;/code&gt; target:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;micromamba create -n my-env --platform=emscripten-32 \
    -c https://repo.mamba.pm/emscripten-forge \
    -c https://repo.mamba.pm/conda-forge \
    python ipython numpy jedi
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that we not only added emscripten-forge as a channel, but also &lt;a href="https://repo.mamba.pm/conda-forge"&gt;conda-forge&lt;/a&gt;. This means all noarch packages can be used.&lt;/p&gt;
&lt;h3 id="adding-new-packages-to-the-emscripten-forge-channel"&gt;Adding new packages to the emscripten-forge channel&lt;/h3&gt;
&lt;p&gt;Adding new packages is a simple procedure:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;fork the repository &lt;a href="https://github.com/emscripten-forge/recipes"&gt;https://github.com/emscripten-forge/recipes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;create a folder for your package in &lt;a href="https://github.com/emscripten-forge/recipes/tree/main/recipes/recipes_emscripten"&gt;&lt;strong&gt;recipes/recipes_emscripten/&amp;lt;my_package&amp;gt;&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;add a &lt;a href="https://github.com/emscripten-forge/recipes/blob/main/recipes/recipes_emscripten/widgetsnbextension/recipe.yaml"&gt;&lt;code&gt;recipe.yaml&lt;/code&gt;&lt;/a&gt; for your package in &lt;code&gt;recipes/recipes_emscripten/&amp;lt;your_package&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;create a pull request containing the recipe. Once the pull request is merged, the package is automatically uploaded to the &lt;code&gt;emscripten-forge&lt;/code&gt; channel.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="integration-with-jupyterlite"&gt;Integration with JupyterLite&lt;/h2&gt;
&lt;p&gt;Even though this is a general-purpose conda-based distribution for Emscripten packages, we had one particular application in mind for this first iteration: &lt;strong&gt;JupyterLite&lt;/strong&gt;. The existing Pyolite kernel is too tightly coupled with the Pyodide distribution, so we decided to go with &lt;a href="https://github.com/jupyter-xeus/xeus-python"&gt;&lt;strong&gt;xeus-python&lt;/strong&gt;&lt;/a&gt; instead.&lt;/p&gt;
&lt;p&gt;The main reason for picking &lt;a href="https://github.com/jupyter-xeus/xeus-python"&gt;xeus-python&lt;/a&gt; (over ipykernel) is that with xeus-based kernels, it is possible to override the communication layer of the kernel (switching e.g. from ZMQ to HTTP/2). In the case of JupyterLite, the implementation simply relies on direct JavaScript function calls.&lt;/p&gt;
&lt;p&gt;You can check out our &lt;a href="https://blog.jupyter.org/posts/2021/xeus-lite/"&gt;earlier blog post&lt;/a&gt; for more details on the JupyterLite xeus-based kernels.&lt;/p&gt;
&lt;h3 id="providing-a-complete-python-development-experience"&gt;Providing a complete Python development experience&lt;/h3&gt;
&lt;p&gt;Some remaining intrinsic limitations to the WebAssembly platform need to be worked around to provide a complete experience to end-users. For example, sockets cannot be created in WebAssembly, preventing the use of the default asyncio event loop implementation. Luckily, the Pyodide authors developed a custom asyncio event-loop called &lt;a href="https://pyodide.org/en/latest/usage/api/python-api/webloop.html"&gt;WebLoop&lt;/a&gt;: it wraps the browser event loop using the Python — JavaScript foreign function interface (FFI) provided with &lt;a href="https://pyodide.org/en/stable/usage/type-conversions.html"&gt;Pyodide&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id="pyjs"&gt;Pyjs&lt;/h4&gt;
&lt;p&gt;Since it is non-trivial to extract Pyodide’s FFI and use it for other projects, we created a modern Python - JavaScript FFI from scratch. This was done with the following tricks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/pybind/pybind11"&gt;Pybind11&lt;/a&gt; is used to call Python from C++ and vice versa,&lt;/li&gt;
&lt;li&gt;&lt;a href="https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html"&gt;Embind&lt;/a&gt; is used to call JavaScript from C++ and vice versa.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When we use &lt;a href="https://github.com/pybind/pybind11"&gt;Pybind11&lt;/a&gt; and &lt;a href="https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html"&gt;Embind&lt;/a&gt; together we can call Python from JavaScript and vice versa, with C++ as a man in the middle. This not only allows us to write a simple FFI from scratch with relatively little code but also avoids calling any low-level CPython APIs and enables using high-level constructs — like &lt;a href="https://pybind11.readthedocs.io/en/stable/advanced/pycpp/object.html#calling-python-functions"&gt;&lt;code&gt;pybind11::object&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://emscripten.org/docs/api_reference/val.h.html"&gt;&lt;code&gt;emscripten::val&lt;/code&gt;&lt;/a&gt;— instead.&lt;br&gt;
The code is available in the &lt;a href="https://github.com/emscripten-forge/pyjs"&gt;pyjs&lt;/a&gt; repository. The API is very similar to Pyodide’s so that it can be used as a drop-in replacement in code, like Pyodide’s &lt;a href="https://pyodide.org/en/latest/usage/api/python-api/webloop.html"&gt;WebLoop&lt;/a&gt; implementation.&lt;/p&gt;
&lt;h4 id="deployment"&gt;Deployment&lt;/h4&gt;
&lt;p&gt;The &lt;a href="https://github.com/jupyterlite/xeus-python-kernel"&gt;xeus-python-kernel&lt;/a&gt; allows conda packages to be pre-installed in the Python runtime. This can be done by passing the &lt;code&gt;XeusPythonEnv.packages&lt;/code&gt; CLI option to &lt;code&gt;jupyter lite build&lt;/code&gt;. The following command will install &lt;code&gt;NumPy&lt;/code&gt;, &lt;code&gt;Matplotlib&lt;/code&gt;, and &lt;code&gt;ipyleaflet&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nx"&gt;jupyter&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;lite&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;build&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;XeusPythonEnv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;packages&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;\
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;numpy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;\
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;matplotlib&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;\
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;ipyleaflet&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;figure&gt;
&lt;img alt="xeus-python kernel with the ipyleaflet widget visible." src="https://blog.jupyter.org/posts/2022/mamba-meets-jupyterlite/images/004-1_JCiZIwwkFen5kwEA2rK4SA.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Running the xeus-python kernel with the ipyleaflet widget in JupyterLite&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;More details can be found in the &lt;a href="https://github.com/jupyterlite/xeus-python-kernel"&gt;xeus-python-kernel GitHub repository&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="what-about-the-future"&gt;What about the future?&lt;/h2&gt;
&lt;p&gt;This combination of JupyterLite and Mamba has the potential to open Jupyter to millions of additional users.&lt;br&gt;
Given its scalability, ease of deployment, reproducibility, and accessibility, JupyterLite will be everywhere: countries, organizations, and schools that don’t have access to sovereign cloud infrastructure will be able to deploy Jupyter-based education platforms on servers that they truly own, without endangering the data of their students or becoming too reliant on resources that they do not control.&lt;/p&gt;
&lt;p&gt;In the short term, we are working on the following “next steps”:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Mambalite:&lt;/strong&gt; To support the installation of packages at runtime. Similar to Pyodide’s pip-lite, it will allow downloading packages at runtime.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fortran:&lt;/strong&gt; Compiling Fortran code with Emscripten is currently not supported, but it is necessary for key packages like SciPy. Pyodide relies on f2c, a Fortran-to-C converter, in conjunction with a set of patches to compile Fortran code with Emscripten. We are working on a more direct approach: compiling SciPy natively with &lt;a href="https://lfortran.org/"&gt;LFortran&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Binderlite:&lt;/strong&gt; Binder converts a repository of notebooks into an executable JupyterLab environment, making code immediately reproducible by anyone, anywhere. Emscripten-forge is the missing piece to build BinderLite, a version of Binder relying on JupyterLite instances instead of vanilla JupyterLab instances.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rust/PyO3 support:&lt;/strong&gt; We are working on integrating the &lt;a href="https://blog.pyodide.org/posts/rust-pyo3-support-in-pyodide/"&gt;work of the Pyodide team&lt;/a&gt; on Rust/PyO3 support in emscripten-forge. This will be important to build Rust extension modules like &lt;code&gt;cryptography&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="credits"&gt;Credits&lt;/h2&gt;
&lt;p&gt;This was built upon the work of a much bigger crowd!&lt;/p&gt;
&lt;h3 id="the-pyodide-team"&gt;The Pyodide team&lt;/h3&gt;
&lt;p&gt;The Pyodide project was started at the Mozilla foundation by &lt;a href="https://twitter.com/MDroettboom"&gt;Michael Droettboom&lt;/a&gt; and is now maintained by &lt;a href="https://github.com/hoodmane"&gt;Hood Chatham&lt;/a&gt;, &lt;a href="https://twitter.com/RomanYurchak"&gt;Roman Yurchak&lt;/a&gt;, and &lt;a href="https://github.com/ryanking13"&gt;Gyeongjae Choi&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The foundational work of the Pyodide project pioneered the use of Python in the browser and made all of the rest possible, from JupyterLite to this work.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id="the-emscripten-team"&gt;The Emscripten team&lt;/h3&gt;
&lt;p&gt;Both Pyodide and emscripten-forge are built upon the Emscripten toolchain, which provides the foundational components to be able to meaningfully run WebAssembly programs in the browser.&lt;/p&gt;
&lt;h3 id="the-jupyterlite-team"&gt;The JupyterLite team&lt;/h3&gt;
&lt;p&gt;The JupyterLite project was started by &lt;a href="https://twitter.com/jtpio"&gt;Jeremy Tuloup&lt;/a&gt;, with significant contributions from &lt;a href="https://github.com/bollwyvl"&gt;Nick Bollweg&lt;/a&gt; and &lt;a href="https://twitter.com/martinrenou"&gt;Martin Renou&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id="the-mamba-org-team"&gt;The Mamba Org team&lt;/h3&gt;
&lt;p&gt;The mamba ecosystem has been instrumental in making these developments possible. We use the Quetz open-source server for hosting the packages and the Boa tool to build them. In the mamba development team, we should highlight the work of &lt;a href="https://twitter.com/wuoulf"&gt;Wolf Vollprecht&lt;/a&gt;, &lt;a href="https://twitter.com/johanmabille"&gt;Johan Mabille&lt;/a&gt;, &lt;a href="https://twitter.com/MJKlaim"&gt;Joel Lamotte&lt;/a&gt;, and &lt;a href="https://twitter.com/atrawog"&gt;Andreas Trawöger&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id="the-xeus-team"&gt;The Xeus team&lt;/h3&gt;
&lt;p&gt;The xeus project was started by &lt;a href="https://twitter.com/johanmabille"&gt;Johan Mabille&lt;/a&gt; and &lt;a href="https://twitter.com/SylvainCorlay"&gt;Sylvain Corlay&lt;/a&gt;. It is at the foundation of the JupyterLite integration and helped to get all the pieces together (Xeus, Mamba, Jupyter). We should especially credit the work of &lt;a href="https://twitter.com/martinRenou"&gt;Martin Renou&lt;/a&gt; and &lt;a href="https://twitter.com/thorstenbeier"&gt;Thorsten Beier&lt;/a&gt; on this integration with JupyterLite.&lt;/p&gt;
&lt;h2 id="acknowledgment"&gt;Acknowledgment&lt;/h2&gt;
&lt;p&gt;The work of Thorsten Beier, Johan Mabille, Martin Renou, Sylvain Corlay, Wolf Vollprecht, Joel Lamotte, and Andreas Trawoger at &lt;a href="https://twitter.com/QuantStack"&gt;&lt;strong&gt;QuantStack&lt;/strong&gt;&lt;/a&gt; was funded by &lt;a href="https://twitter.com/TechAtBloomberg?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor"&gt;&lt;strong&gt;Bloomberg&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="about-the-authors"&gt;About the Authors&lt;/h2&gt;
&lt;h3 id="thorsten-beier"&gt;Thorsten Beier&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://twitter.com/thorstenbeier"&gt;Thorsten Beier&lt;/a&gt; is a Scientific Software Engineer at &lt;a href="https://twitter.com/QuantStack"&gt;QuantStack&lt;/a&gt;. Before joining &lt;a href="https://quantstack.net/"&gt;QuantStack&lt;/a&gt;, he graduated in computer science at the University of Heidelberg and worked at the &lt;a href="https://www.embl.org/"&gt;EMBL&lt;/a&gt;. As an open-source developer, Thorsten worked on a variety of projects, from &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;xeus&lt;/a&gt; and &lt;a href="https://github.com/QuantStack/xtensor"&gt;xtensor&lt;/a&gt; in C++ to &lt;a href="https://github.com/inferno-pytorch/inferno"&gt;inferno&lt;/a&gt;, &lt;a href="https://kipoi.org/"&gt;kipoi&lt;/a&gt;, &lt;a href="https://www.ilastik.org/"&gt;ilastik&lt;/a&gt;, and &lt;a href="https://github.com/uhlmanngroup/napari-splineit"&gt;napari-splineit&lt;/a&gt; in Python.&lt;/p&gt;
&lt;h3 id="martin-renou"&gt;Martin Renou&lt;/h3&gt;
&lt;p&gt;&lt;a href="https://twitter.com/martinRenou"&gt;Martin Renou&lt;/a&gt; is a Scientific Software Engineer at &lt;a href="https://twitter.com/QuantStack"&gt;QuantStack&lt;/a&gt;. Before joining &lt;a href="http://quantstack.net/"&gt;QuantStack&lt;/a&gt;, he studied at the French Aerospace Engineering School &lt;a href="https://www.isae-supaero.fr/en"&gt;SUPAERO&lt;/a&gt;. He also worked at Logilab in Paris and Enthought in Cambridge. As an open-source developer at &lt;a href="http://quantstack.net/"&gt;QuantStack&lt;/a&gt;, Martin worked on a variety of projects, from &lt;a href="https://github.com/QuantStack/xsimd"&gt;xsimd&lt;/a&gt;, &lt;a href="https://github.com/QuantStack/xtensor"&gt;xtensor&lt;/a&gt;, and &lt;a href="https://github.com/QuantStack/xframe"&gt;xframe&lt;/a&gt; in C++ to &lt;a href="https://github.com/jupyter-widgets/ipyleaflet"&gt;ipyleaflet&lt;/a&gt; and &lt;a href="https://github.com/maartenbreddels/ipywebrtc"&gt;ipywebrtc&lt;/a&gt; in Python and JavaScript.&lt;/p&gt;
</content><category term="JupyterLite"/><category term="WebAssembly"/><category term="xeus"/></entry><entry><title>Xeus-Lite</title><link href="https://blog.jupyter.org/posts/2021/xeus-lite/" rel="alternate"/><published>2021-10-25T09:40:00+00:00</published><updated>2021-10-25T09:40:00+00:00</updated><author><name>Thorsten Beier</name></author><id>tag:blog.jupyter.org,2021-10-25:/posts/2021/xeus-lite/</id><summary type="html">&lt;p&gt;JupyterLite + Xeus = ❤️️&lt;/p&gt;
</summary><content type="html">&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/xeus-lite/images/001-1_PUlJi6czJovO90t-Dsgt5g.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;JupyterLite is a &lt;a href="https://jupyter.org/"&gt;JupyterLab&lt;/a&gt; distribution that runs entirely in the web browser, backed by in-browser language kernels. &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt; is C++ library for writing &lt;a href="https://jupyter.org/"&gt;Jupyter&lt;/a&gt; kernels. In this blogpost we show how these two can work together.&lt;/p&gt;
&lt;h2 id="jupyterlite"&gt;JupyterLite&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/xeus-lite/images/002-1_dbJO26hiSR8EFygX1rnqrA.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;With vanilla Jupyter, kernels are running in separate processes. The communication between the kernels and the client is achieved with &lt;a href="https://zeromq.org/"&gt;ZeroMQ&lt;/a&gt;. In contrast to this, JupyterLite runs entirely in the browser, including the language kernels. The following kernels are already implemented in the JupyterLite framework:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;JavaScript Kernel&lt;/li&gt;
&lt;li&gt;P5 Kernel: Since P5 is a JavaScript library, it is easy to provide a P5 kernel running in the browser.&lt;/li&gt;
&lt;li&gt;A Python kernel based on &lt;a href="https://github.com/pyodide/pyodide"&gt;pyodide&lt;/a&gt; called pyolite: While the two JavaScript based kernels are trivial to implement as in-browser kernels, &lt;a href="https://github.com/pyodide/pyodide"&gt;pyodide&lt;/a&gt; is a Python interpreter compiled to WebAssembly via Emscripten. Not only Python itself has been compiled to WebAssembly, but also the whole Scientific Stack including packages like: Numpy, Scipy, Pandas and many more. An overview of packages can be found &lt;a href="https://github.com/pyodide/pyodide/tree/main/packages"&gt;here&lt;/a&gt;. Furthermore any pure Python package can be installed from within pyolite.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Since JupyterLite runs entirely in the browser, it is &lt;a href="https://jupyterlite.github.io/demo/lab/index.html"&gt;very easy to try it out&lt;/a&gt;!&lt;/p&gt;
&lt;h2 id="xeus"&gt;Xeus&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://xeus.readthedocs.io/en/latest/?badge=latest"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/xeus-lite/images/003-1_c-fyt4I1GOXnrq3tkexaGA.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt; is C++ library for writing &lt;a href="https://jupyter.org/"&gt;Jupyter&lt;/a&gt; kernels. It is not a kernel but a library that simplifies the process of writing kernels. &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt; implements the &lt;a href="https://jupyter-client.readthedocs.io/en/stable/messaging.html"&gt;Jupyter messaging protocol&lt;/a&gt;, so that kernel authors only need to implement a handful of methods related to the actual interpreter, like executing pieces of code and auto-completing.&lt;br&gt;
With the help of Xeus, it is very easy to write Jupyter kernels . In fact, &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt; has already been used for making several &lt;a href="https://jupyter.org/"&gt;language kernels&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/QuantStack/xeus-cling"&gt;xeus-cling&lt;/a&gt; is a Xeus-based C++ kernel.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-python"&gt;xeus-python&lt;/a&gt; is a Xeus-based Python kernel.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-lua"&gt;xeus-lua&lt;/a&gt; is a Xeus-based Lua kernel.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-sql"&gt;xeus-sql&lt;/a&gt; / &lt;a href="https://github.com/jupyter-xeus/xeus-sqlite"&gt;xeus-sqlite&lt;/a&gt; are Xeus-based kernel for SQL / SQLite databases.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-robot"&gt;xeus-robot&lt;/a&gt; is a Jupyter kernel for the &lt;a href="https://robotframework.org/"&gt;Robot Framework&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gitlab.com/lfortran/lfortran/-/merge_requests/514"&gt;LFortran&lt;/a&gt; is a modern interactive Fortran compiler with a Xeus-based Jupyter kernel.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Since it is very easy to write Xeus based kernels for Jupyter, we also want to leverage Xeus for writing JupyterLite kernels. This has been the main motivation for &lt;a href="https://blog.jupyter.org/posts/2021/xeus-2-0/"&gt;Xeus 2.0&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="xeus-architecture"&gt;Xeus Architecture&lt;/h2&gt;
&lt;p&gt;Xeus is has three extension points as depicted below&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/xeus-lite/images/004-1_CTgb-wk-_TMWVhDzB-Yx7g.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;em&gt;&lt;strong&gt;Server&lt;/strong&gt;&lt;/em&gt; is the middleware component responsible for receiving and sending messages to the Jupyter client. The default server it is built upon ZeroMQ and handles the concurrency model of the application.&lt;br&gt;
As we will see later, a custom server is needed to connect Xeus with JupyterLite.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;&lt;strong&gt;Interpreter&lt;/strong&gt;&lt;/em&gt; provides the interface that kernel authors must implement.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;&lt;strong&gt;Debugger&lt;/strong&gt;&lt;/em&gt; provides the interface that can to be implemented when the kernel shall have &lt;a href="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/"&gt;debug capabilities&lt;/a&gt;, but we do not yet support this for Xeus-JupyterLite-Kernels.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="jupyterlite-xeus-kernels"&gt;JupyterLite Xeus-Kernels&lt;/h2&gt;
&lt;p&gt;Traditionally, the Jupyter kernel and the Client to the Jupyter kernel run in separate processes as depicted below:&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/xeus-lite/images/005-1_jHLLHjTjNWlV0e38GjvACw.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;The communication between the kernels and the client (ie the Jupyter-server) are done with inter-process communication via &lt;a href="https://zeromq.org/"&gt;ZeroMQ&lt;/a&gt;. But with JupyterLite the &lt;a href="https://jupyterlite.readthedocs.io/en/latest/"&gt;kernel runs directly in the browser&lt;/a&gt;. In that case, ZeroMQ is not required anymore to communicate with the frontend. This was the motivation for &lt;a href="https://blog.jupyter.org/posts/2021/xeus-2-0/"&gt;Xeus 2.0&lt;/a&gt;, where it is possible to build Xeus without ZeroMQ. To implement JupyterLite Kernels with Xeus, we need to implement a custom Server which handles the &lt;a href="https://emscripten.org/"&gt;Emscripten&lt;/a&gt;/&lt;a href="https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html"&gt;Embind&lt;/a&gt;-based communication layer&lt;/p&gt;
&lt;p&gt;The overall architecture is best described with the picture below: The C++ Xeus-Kernel is compiled to WebAssembly with &lt;a href="https://emscripten.org/"&gt;Emscripten&lt;/a&gt; / &lt;a href="https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html"&gt;Embind&lt;/a&gt;. The WebAssembly compiled code runs in a dedicated WebWorker thread. The WebWorker communicates via Message Passing with a thin layer of TypeScript which implements the &lt;a href="https://github.com/jupyterlite/jupyterlite/blob/d94d472fcdfb5ce760820a6a9cd2c6ea6fc84014/packages/kernel/src/tokens.ts#L45"&gt;IKernel&lt;/a&gt; API of JupyterLite. The communication between JupyterLite and the JupyterLite k ernel is done entirely in JavaScript.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/xeus-lite/images/006-1_AwkYyHKDxj0_EYitMAxZ5Q.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;The C++ code needed to compile an existing xeus-kernel to WebAssembly is very minimal:&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/xeus-lite/images/007-1_Qdv9gVF_oO9n2nLffY35SQ.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;Furthermore one needs a thin layer of TypeScript / JavaScript to implement the JupyterLite &lt;a href="https://github.com/jupyterlite/jupyterlite/blob/d94d472fcdfb5ce760820a6a9cd2c6ea6fc84014/packages/kernel/src/tokens.ts#L45"&gt;IKernel API&lt;/a&gt;. A good example of this code is given in the &lt;a href="https://github.com/jupyterlite/xeus-lua-kernel"&gt;JupyterLite Xeus-Lua repository&lt;/a&gt;. While most of the repositories code is boilerplate, one needs to provide a simple &lt;a href="https://github.com/DerThorsten/jupyterlite_xeus_lua/blob/main/Dockerfile"&gt;Dockerfile&lt;/a&gt; which compiles the Xeus-Kernel to WebAssembly.&lt;/p&gt;
&lt;h2 id="xeus-lua"&gt;Xeus-Lua&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-lua"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/xeus-lite/images/008-1_XjZ84G9Ftb3krekpiqBuiw.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We recently released a &lt;a href="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/"&gt;Xeus based Lua kernel&lt;/a&gt;. Even though its worthwhile to have Xeus-Lua kernel for vanilla Jupyter, the main purpose of Xeus-Lua was to experiment with Xeus-based JupyterLite kernels.&lt;br&gt;
We choose Lua as the first language to try out Xeus-based JupyterLite kernels since Lua is easy to compile to WebAssembly.&lt;br&gt;
A JupyterLite instance with Xeus-Lua included can be found &lt;a href="https://jupyterlite.github.io/demo/lab/"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Xeus-Lua has built in support for interactive widgets" src="https://blog.jupyter.org/posts/2021/xeus-lite/images/009-1_Iwg6iPSZmr5o1ZozOlJXDQ.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Xeus-Lua has built in support for interactive widgets&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="xeus-wren"&gt;Xeus-Wren&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://github.com/DerThorsten/xeus-wren"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/xeus-lite/images/010-1_AaO7Or9i6ZDmYR3PNGXh9Q.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Wren is relatively new “&lt;a href="https://wren.io/"&gt;Classy Little scripting Language&lt;/a&gt;” created by the author of the great book &lt;a href="https://craftinginterpreters.com/"&gt;“Crafting Interpreters”&lt;/a&gt;. Wren can be described with the following:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://wren.io/"&gt;Think Smalltalk in a Lua-sized package with a dash of Erlang and wrapped up in a familiar, modern syntax&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;We choose Wren as a second language to experiment with Xeus + JupyterLite since it is small, simple to compile to WebAssembly and easy to embed in C++. A JupyterLite instance with Xeus-Wren included can be found &lt;a href="https://jupyterlite.github.io/demo/lab?path=xeus-wren%2Fiwren.ipynb"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Xeus-Wren has built in support for displaying data of various MIME-types" src="https://blog.jupyter.org/posts/2021/xeus-lite/images/011-1_b-X9cmzXfq7NIXeEwfEzow.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Xeus-Wren has built in support for displaying data of various MIME-types&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="outlook"&gt;Outlook&lt;/h2&gt;
&lt;p&gt;There are many languages which can be compiled to WebAssembly like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Julia: &lt;a href="https://github.com/Keno/julia-wasm"&gt;https://github.com/Keno/julia-wasm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Octave: &lt;a href="https://news.ycombinator.com/item?id=22926120"&gt;https://news.ycombinator.com/item?id=22926120&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;C++: &lt;a href="https://github.com/binji/wasm-clang"&gt;https://github.com/binji/wasm-clang&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Python: &lt;a href="https://github.com/pyodide/pyodide"&gt;https://github.com/pyodide/pyodide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also databases as sqlite can be compiled to WebAssembly:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Sqlite: &lt;a href="https://github.com/sql-js/sql.js/"&gt;https://github.com/sql-js/sql.js/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Our goal is to provide Xeus-based JupyterLite kernels for these projects to make the JupyterLite ecosystem even more powerful.&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="acknowledgements"&gt;Acknowledgements&lt;/h2&gt;
&lt;p&gt;We like to thank&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://twitter.com/jtpio"&gt;Jeremy Tuloup&lt;/a&gt;, &lt;a href="https://twitter.com/mad_tandon"&gt;Madhur Tandon&lt;/a&gt;, &lt;a href="https://twitter.com/martinrenou"&gt;Martin Renou&lt;/a&gt;, and &lt;a href="https://github.com/bollwyvl"&gt;Nicholas Bollweg&lt;/a&gt; for their work on JupyterLite.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://twitter.com/johanmabille"&gt;Johan Mabille&lt;/a&gt; for Xeus and his help implementing the Xeus-Emscripten server.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="about-the-author"&gt;About the Author&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://twitter.com/thorstenbeier"&gt;Thorsten Beier&lt;/a&gt; is a Scientific Software Engineer at &lt;a href="https://quantstack.net/"&gt;QuantStack&lt;/a&gt;. Before joining &lt;a href="https://quantstack.net/"&gt;QuantStack&lt;/a&gt;, he graduated in computer science at the University of Heidelberg and worked at the &lt;a href="https://www.embl.org/"&gt;EMBL&lt;/a&gt;. As an open source developer, Thorsten worked on a variety of projects, from &lt;a href="https://github.com/DerThorsten/nifty"&gt;nifty&lt;/a&gt; and &lt;a href="https://github.com/ukoethe/vigra"&gt;vigra&lt;/a&gt; in C++ to &lt;a href="https://github.com/inferno-pytorch/inferno"&gt;inferno&lt;/a&gt;, &lt;a href="https://kipoi.org/"&gt;kipoi&lt;/a&gt; and &lt;a href="https://www.ilastik.org/"&gt;ilastik&lt;/a&gt; in Python.&lt;/p&gt;
</content><category term="JupyterLite"/><category term="kernels"/><category term="WebAssembly"/><category term="xeus"/></entry><entry><title>Xeus 2.0</title><link href="https://blog.jupyter.org/posts/2021/xeus-2-0/" rel="alternate"/><published>2021-09-28T09:41:00+00:00</published><updated>2021-09-28T09:41:00+00:00</updated><author><name>Johan Mabille</name></author><id>tag:blog.jupyter.org,2021-09-28:/posts/2021/xeus-2-0/</id><summary type="html">&lt;p&gt;Announcing a major release of the Xeus library&lt;/p&gt;
</summary><content type="html">&lt;p&gt;We have just released &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt; 2. This is a major release of the library. While it includes backward-incompatible changes, they are very limited and upgrading your kernels should be relatively easy.&lt;/p&gt;
&lt;h2 id="how-to-upgrade-xeus-based-kernels"&gt;How to upgrade Xeus-based kernels&lt;/h2&gt;
&lt;p&gt;Let’s illustrate that with the code of a simple kernel before and after upgrading to Version 2. Most typically, only the kernel’s main file will have to be updated:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="gh"&gt;diff --git a/example/src/main.cpp b/example/src/main.cpp&lt;/span&gt;
&lt;span class="gh"&gt;index 29de437..eb8fdba 100644&lt;/span&gt;
&lt;span class="gd"&gt;--- a/example/src/main.cpp&lt;/span&gt;
&lt;span class="gi"&gt;+++ b/example/src/main.cpp&lt;/span&gt;
&lt;span class="gu"&gt;@@ -21,12 +21,14 @@ int main(int argc, char* argv[])&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;    std::string file_name = (argc == 1) ? &amp;quot;connection.json&amp;quot; : argv[2];
&lt;span class="w"&gt; &lt;/span&gt;    xeus::xconfiguration config = xeus::load_configuration(file_name);

&lt;span class="gi"&gt;+    auto context = xeus::make_context&amp;lt;zmq::context_t&amp;gt;();&lt;/span&gt;
&lt;span class="gi"&gt;+&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;    // Create interpreter instance
&lt;span class="w"&gt; &lt;/span&gt;    using interpreter_ptr = std::unique_ptr&amp;lt;custom::custom_interpreter&amp;gt;;
&lt;span class="w"&gt; &lt;/span&gt;    interpreter_ptr interpreter = interpreter_ptr(new custom::custom_interpreter());

&lt;span class="w"&gt; &lt;/span&gt;    // Create kernel instance and start it
&lt;span class="gd"&gt;-    xeus::xkernel kernel(config, xeus::get_user_name(), std::move(interpreter), xeus::make_xserver_zmq);&lt;/span&gt;
&lt;span class="gi"&gt;+    xeus::xkernel kernel(config, xeus::get_user_name(), std::move(context), std::move(interpreter), xeus::make_xserver_zmq);&lt;/span&gt;
&lt;span class="w"&gt; &lt;/span&gt;    kernel.start();

&lt;span class="w"&gt; &lt;/span&gt;    return 0;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The first change is that you now have to instantiate and pass an additional argument to the kernel constructor: the &lt;em&gt;context&lt;/em&gt;. Fortunately, Xeus provides a function to build such a context object, making the update straightforward. We will detail the reason for this change in the next section.&lt;/p&gt;
&lt;p&gt;The second change is that the kernel constructor now &lt;em&gt;requires&lt;/em&gt; a function to build the server while a default value was provided for it in Xeus 1.x. Again, the motivations for this change will be detailed in the next section. Finally the functions for building the servers have moved to different headers.&lt;/p&gt;
&lt;p&gt;To summarize, here is the list of the breaking changes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The kernel’s constructor now requires an additional argument, the context. Xeus provides a function to easily instantiate it.&lt;/li&gt;
&lt;li&gt;The order of kernel’s constructor arguments has changed, and the function for building the server is now required.&lt;/li&gt;
&lt;li&gt;The functions for building the servers have moved to the headers where the corresponding servers are defined.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="motivation-for-these-changes"&gt;Motivation for these changes&lt;/h2&gt;
&lt;p&gt;When we created &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt;, kernels were expected to run in separate processes. The communication between the kernels and the client was achieved with the &lt;a href="https://zeromq.org/"&gt;ZeroMQ&lt;/a&gt; middleware framework, and it was natural to heavily rely on it in Xeus.&lt;/p&gt;
&lt;p&gt;Recent &lt;a href="https://blog.jupyter.org/posts/2021/jupyterlite-jupyter-webassembly-python/"&gt;developments&lt;/a&gt; have pushed in a different direction, where the &lt;a href="https://jupyterlite.readthedocs.io/en/latest/"&gt;kernel can run directly in the browser&lt;/a&gt;. In that case, a middleware library is not required anymore to communicate with the frontend. The architecture of Xeus was not suitable for this new kind of kernels. An update was required so that it is possible to build Xeus without the dependency on ZeroMQ.&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="about-the-developers"&gt;About the developers&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/xeus-2-0/images/001-0_tHIyMRx_JbgkU2xy.jpeg" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Johan Mabille&lt;/strong&gt; is a scientific software developer at QuantStack. Johan is a co-author of Xeus, and developed the debugger extension to xeus-python.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/xeus-2-0/images/002-0_zUMSbNcno1BZSfjO.jpeg" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sylvain Corlay&lt;/strong&gt; is the founder and CEO of QuantStack, and a core Jupyter developer. He co-authored Xeus and xeus-python.&lt;/p&gt;
</content><category term="kernels"/><category term="releases"/><category term="xeus"/></entry><entry><title>From Jupyter to the Moon</title><link href="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/" rel="alternate"/><published>2021-09-24T12:24:00+00:00</published><updated>2021-09-24T12:24:00+00:00</updated><author><name>Thorsten Beier</name></author><id>tag:blog.jupyter.org,2021-09-24:/posts/2021/from-jupyter-to-the-moon/</id><summary type="html">&lt;p&gt;A new Jupyter kernel for Lua based on Xeus&lt;/p&gt;
</summary><content type="html">&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/001-1_Or2bu8twFwywgACqLOE9AA.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Jupyter architecture in a nutshell" src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/002-0_jvG9j3sKufQRiuLl.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;&lt;a href="https://jupyter.org/"&gt;Jupyter&lt;/a&gt; architecture in a nutshell&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;A key principle in Jupyter’s design is &lt;em&gt;&lt;strong&gt;language agnosticism&lt;/strong&gt;&lt;/em&gt;, and one of the main extension points of the Jupyter ecosystem is the &lt;em&gt;&lt;strong&gt;kernel&lt;/strong&gt;&lt;/em&gt;, the part of the architecture responsible for executing the user’s code.&lt;/p&gt;
&lt;p&gt;In the end, a Jupyter kernel is merely an executable implementing a well-defined inter-process communication protocol.&lt;/p&gt;
&lt;p&gt;A reference implementation of the kernel is ipykernel, which provides the default Python kernel, and utilities to build other language kernels. Another reference implementation of the protocol is &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="xeus"&gt;Xeus&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt; is C++ library for writing &lt;a href="https://jupyter.org/"&gt;Jupyter&lt;/a&gt; kernels. It is not a kernel but a library that simplifies the process of writing kernels. &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt; implements the &lt;a href="https://jupyter-client.readthedocs.io/en/stable/messaging.html"&gt;Jupyter messaging protocol&lt;/a&gt;, so that kernel authors only need to implement a handful of methods related to the actual interpreter, like executing pieces of code and auto-completing. There is a long &lt;a href="https://github.com/dbohdan/embedded-scripting-languages"&gt;list of scripting languages&lt;/a&gt; which can be embedded in C/C++. With the help of Xeus, it is very easy to write kernels for such languages. In fact, &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt; has already been used for making several &lt;a href="https://jupyter.org/"&gt;language kernels&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/QuantStack/xeus-cling"&gt;xeus-cling&lt;/a&gt; is a Xeus-based C++ kernel.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-python"&gt;xeus-python&lt;/a&gt; is a Xeus-based Python kernel.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-sql"&gt;xeus-sql&lt;/a&gt; / &lt;a href="https://github.com/jupyter-xeus/xeus-sqlite"&gt;xeus-sqlite&lt;/a&gt; are Xeus-based kernel for SQL / SQLite databases.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-robot"&gt;xeus-robot&lt;/a&gt; is a Jupyter kernel for the &lt;a href="https://robotframework.org/"&gt;Robot Framework&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gitlab.com/lfortran/lfortran/-/merge_requests/514"&gt;LFortran&lt;/a&gt; is a modern interactive Fortran compiler with a Xeus-based Jupyter kernel.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="xwidgets"&gt;xwidgets&lt;/h2&gt;
&lt;p&gt;The &lt;a href="https://github.com/jupyter-xeus/xwidgets"&gt;xwidget&lt;/a&gt; library is a C++ implementation of the &lt;a href="https://ipywidgets.readthedocs.io/en/latest/"&gt;Jupyter Interactive Widget protocol&lt;/a&gt;. Xwidgets were initially developed for xeus-cling, the Xeus C++ kernel, but any Xeus-based kernel can reuse these components.&lt;/p&gt;
&lt;h2 id="a-xeus-based-lua-kernel"&gt;A xeus-based Lua kernel&lt;/h2&gt;
&lt;p&gt;Today, I am pleased to announce the release of &lt;a href="https://github.com/jupyter-xeus/xeus-lua"&gt;xeus-lua&lt;/a&gt;, a new &lt;a href="https://jupyter.org/"&gt;Jupyter&lt;/a&gt; kernel for &lt;a href="https://www.lua.org/"&gt;Lua&lt;/a&gt; based on &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt;.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/003-0_xQYvimlGgIZuuZC2.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;h2 id="lua"&gt;Lua&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://www.lua.org/"&gt;Lua&lt;/a&gt;, which means “Moon” in Portuguese, is a lightweight embeddable scripting language written in C. While Python is one of the leading scripting languages for scientific application, &lt;a href="https://www.lua.org/"&gt;Lua&lt;/a&gt; is the leading scripting language used in games / game engines. The &lt;a href="https://en.wikipedia.org/wiki/Category:Lua_(programming_language)-scripted_video_games"&gt;list of video games using Lua&lt;/a&gt; is long and includes triple-a games like Crisys and Farcry. Not only games rely on Lua, but &lt;a href="https://en.wikipedia.org/wiki/List_of_applications_using_Lua"&gt;also applications like Adobe Photoshop Lightroom&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="sol2"&gt;Sol2&lt;/h2&gt;
&lt;figure&gt;
&lt;img alt="With the Sol2 library, Lua can be embedded into C++ in a very elegant way." src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/004-0_qDdOEdX0PhOKNTMJ.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;With the &lt;a href="https://github.com/ThePhD/sol2"&gt;Sol2&lt;/a&gt; library, Lua can be embedded into C++ in a very elegant way.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;While Lua itself can be embedded in a C++ application quite easy, it is even easier when using &lt;a href="https://github.com/ThePhD/sol2"&gt;Sol2&lt;/a&gt;. &lt;a href="https://github.com/ThePhD/sol2"&gt;Sol2&lt;/a&gt; is a C++ library that simplifies the usage of Lua from C++. Furthermore &lt;a href="https://github.com/ThePhD/sol2"&gt;Sol2&lt;/a&gt; can be used to expose C++ classes to Lua, in a similar fashion as &lt;a href="https://github.com/pybind/pybind11"&gt;pybind11&lt;/a&gt; can be used to expose C++ classes to Python.&lt;/p&gt;
&lt;h2 id="xeus-lua"&gt;Xeus-lua&lt;/h2&gt;
&lt;figure&gt;
&lt;img alt="The compulsory “Hello, World!” from xeus-lua. This blog-post would be incomplete without it." src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/005-0_Rw3rs6Cdj5FEfAQf.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The compulsory “Hello, World!” from xeus-lua. This blog-post would be incomplete without it.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;I am pleased to announce &lt;a href="https://github.com/jupyter-xeus/xeus-lua"&gt;xeus-lua&lt;/a&gt;, a new Jupyter kernel for the Lua language based on &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt;. Using &lt;a href="https://github.com/ThePhD/sol2"&gt;Sol2&lt;/a&gt; and &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt;, it was very easy to implement a feature rich kernel using modern C++. With the help of &lt;a href="https://github.com/ThePhD/sol2"&gt;Sol2&lt;/a&gt;, it was trivial to expose the xwidgets classes to Lua such that we can use the widgets within &lt;a href="https://github.com/jupyter-xeus/xeus-lua"&gt;xeus-lua&lt;/a&gt; notebooks.&lt;/p&gt;
&lt;h2 id="but-why-a-lua-kernel"&gt;But why a Lua kernel?&lt;/h2&gt;
&lt;p&gt;While &lt;a href="https://www.lua.org/"&gt;Lua&lt;/a&gt; might not be the hippest language in 2021, there are multiple reasons while I choose to implement such a &lt;a href="https://www.lua.org/"&gt;Lua&lt;/a&gt; kernel, and why such a kernel can be useful:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Writing a &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt;-based kernel is the best way to learn and familiarize oneself with the &lt;a href="https://github.com/jupyter-xeus"&gt;xeus ecosystem&lt;/a&gt;. And since Lua is so easy to build and embed, Lua and Xeus are perfect match. Implementing this kernel gave me great insights into Xeus and Jupyter itself.&lt;/li&gt;
&lt;li&gt;Learning &lt;a href="https://www.lua.org/"&gt;Lua&lt;/a&gt; with &lt;a href="https://github.com/jupyter-xeus/xeus-lua"&gt;xeus-lua&lt;/a&gt; is fun! Before writing &lt;a href="https://github.com/jupyter-xeus/xeus-lua"&gt;xeus-lua&lt;/a&gt;, I had zero Lua experience. While implementing xeus-lua I learned &lt;a href="https://www.lua.org/"&gt;Lua&lt;/a&gt; from within Jupyter by playing around with xwidgets from within Lua — this was a very joyful experience.&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://github.com/jupyter-xeus/xeus-lua"&gt;xeus-lua&lt;/a&gt; implementation might serve as reference for future kernel authors. In particular the &lt;a href="https://github.com/jupyter-xeus/xeus-lua/blob/main/src/xwidgets.cpp"&gt;integration of xwidgets in xeus-lua&lt;/a&gt; might be useful for future implementations.&lt;/li&gt;
&lt;li&gt;Since Lua is so easy to build, &lt;a href="https://github.com/jupyter-xeus/xeus-lua"&gt;xeus-lua&lt;/a&gt; can be built for WebAssembly and will be integrated in &lt;a href="https://jupyterlite.readthedocs.io/en/latest/"&gt;JupyterLite&lt;/a&gt; — &lt;strong&gt;stay tuned!&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="features"&gt;Features&lt;/h2&gt;
&lt;p&gt;Obviously &lt;a href="https://github.com/jupyter-xeus/xeus-lua"&gt;xeus-lua&lt;/a&gt; supports the execution of code.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Simple code execution" src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/006-0_AzW845V1EKlvxO2j.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Simple code execution&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Streams are redirected to the notebooks output&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Redirection of streams" src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/007-0_A-2SpNknQua_D73o.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Redirection of streams&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Errors messages are shown in the notebooks output&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Error Handling" src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/008-0_yMSCAFt70y43daKm.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Error Handling&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Input streams are redirected to the notebooks input system&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="User Input" src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/009-0_Pfa9ASycXFejuZKp.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;User Input&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Statements can be auto-completed with a press of tab&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Code Completion" src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/010-0_dQfGwr6PtuQaSUAb.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Code Completion&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Data of different sources as Latex, JSON and html can be displayed.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Display Data" src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/011-0_tHhXDPzcThHTqor5.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Display Data&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Interactive widgets can be added to the notebook!&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Widgets" src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/012-0_066MCiSNqv21zJOS.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Widgets&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;We can feed the widgets with data!&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Binary buffers for widgets" src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/013-0_ArP2iU5tKYDHvvZd.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Binary buffers for widgets&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="try-it-out"&gt;Try It Out&lt;/h2&gt;
&lt;p&gt;You can try it right now with &lt;a href="https://mybinder.org/"&gt;binder&lt;/a&gt;, without the need of installing anything on your computer, just by clicking on &lt;a href="https://mybinder.org/v2/gh/jupyter-xeus/xeus-lua/main?urlpath=/lab/tree/notebooks/game_of_life.ipynb"&gt;&lt;strong&gt;this link&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://mybinder.org/v2/gh/jupyter-xeus/xeus-lua/main?urlpath=/lab/tree/notebooks/game_of_life.ipynb"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/from-jupyter-to-the-moon/images/014-0_NiFI9An8ZGVDSYyG.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="other-lua-kernels"&gt;Other Lua kernels&lt;/h2&gt;
&lt;p&gt;There are several &lt;a href="https://www.lua.org/"&gt;Lua&lt;/a&gt; kernels available:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/tomstitt/lupyter"&gt;lupyter&lt;/a&gt;: A Python based implementation of a Lua Jupyter kernel. The heavy lifting is done in a C-extension.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/guysv/ilua"&gt;ILua&lt;/a&gt;: A feature rich implementation. Ilua is implemented in Python and does the communication with Lua via IPC.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pakozm/IPyLua"&gt;IPyLua&lt;/a&gt;: IPyLua is a pure Lua implementation.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While these implementations are feature rich and work well, none of the above supports interactive widgets. Since &lt;a href="https://github.com/jupyter-xeus/xeus-lua"&gt;xeus-lua&lt;/a&gt; is based on &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt;, we can reuse components from the Xeus ecosystem like &lt;a href="https://github.com/jupyter-xeus/xwidgets"&gt;xwidgets&lt;/a&gt; with minimal effort.&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="acknowledgments"&gt;Acknowledgments&lt;/h2&gt;
&lt;p&gt;We are grateful to &lt;a href="https://twitter.com/juliettetaka?lang=en"&gt;Juliette Taka&lt;/a&gt; for the illustration.&lt;/p&gt;
&lt;h2 id="about-the-author"&gt;About the Author&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://quantstack.net/thorsten.html"&gt;Thorsten Beier&lt;/a&gt; is a Scientific Software Engineer at &lt;a href="https://quantstack.net/"&gt;QuantStack&lt;/a&gt;. Before joining &lt;a href="https://quantstack.net/"&gt;QuantStack&lt;/a&gt;, he graduated in computer science at the University of Heidelberg and worked at the &lt;a href="https://www.embl.org/"&gt;EMBL&lt;/a&gt;. As an open source developer, Thorsten worked on a variety of projects, from &lt;a href="https://github.com/DerThorsten/nifty"&gt;nifty&lt;/a&gt;, and &lt;a href="https://github.com/ukoethe/vigra"&gt;vigra&lt;/a&gt; in C++ to &lt;a href="https://github.com/inferno-pytorch/inferno"&gt;inferno&lt;/a&gt;, &lt;a href="https://kipoi.org/"&gt;kipoi&lt;/a&gt; and &lt;a href="https://www.ilastik.org/"&gt;ilastik&lt;/a&gt; in Python.&lt;/p&gt;
</content><category term="kernels"/><category term="xeus"/></entry><entry><title>Abracadabra! Bringing the magics to xeus-python</title><link href="https://blog.jupyter.org/posts/2021/abracadabra-bringing-the-magics-to-xeus-python/" rel="alternate"/><published>2021-02-18T13:30:00+00:00</published><updated>2021-02-18T14:06:00+00:00</updated><author><name>Martin Renou</name></author><id>tag:blog.jupyter.org,2021-02-18:/posts/2021/abracadabra-bringing-the-magics-to-xeus-python/</id><summary type="html">&lt;p&gt;Last year, we set ourselves to implement a visual debugger for JupyterLab. This endeavor required major developments in the JupyterLab front-end, in core-Jupyter protocols, and on the kernel side (the part of the Jupyter infrastructure responsible for executing the code).&lt;/p&gt;</summary><content type="html">&lt;p&gt;Last year, we set ourselves to implement a &lt;strong&gt;visual debugger for JupyterLab&lt;/strong&gt;. This endeavor required major developments in the JupyterLab front-end, in core-Jupyter protocols, and on the kernel side (the part of the Jupyter infrastructure responsible for executing the code).&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-python"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/abracadabra-bringing-the-magics-to-xeus-python/images/001-0_B0kK-zNJr0Suisyv.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For kernel-side development, we decided to start with the &lt;a href="https://blog.jupyter.org/posts/2019/a-new-python-kernel-for-jupyter/"&gt;&lt;strong&gt;xeus-python&lt;/strong&gt; kernel&lt;/a&gt;, a lightweight implementation of a Jupyter kernel for the Python programming language. Based on &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;&lt;strong&gt;xeus&lt;/strong&gt;&lt;/a&gt;, xeus-python has a flexible concurrency model that was required to &lt;em&gt;e.g.&lt;/em&gt; add breakpoints while executing code.&lt;/p&gt;
&lt;p&gt;Unfortunately, xeus-python did not provide all ipykernel features (magics, Matplotlib support, &lt;em&gt;etc.&lt;/em&gt;). Furthermore, many notebooks depend on IPython, as they import it explicitely or make use of the IPython configuration system.&lt;/p&gt;
&lt;p&gt;Today, we are proud to announce that xeus-python supports 100% of the IPython magics! This was achieved by leveraging the core IPython package. This is getting us closer to feature parity with ipykernel.&lt;/p&gt;
&lt;h2 id="magics"&gt;Magics&lt;/h2&gt;
&lt;p&gt;xeus-python now supports all magics that IPython provides and even user-defined magics!&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Support for builtin IPython magics and user-defined magics" src="https://blog.jupyter.org/posts/2021/abracadabra-bringing-the-magics-to-xeus-python/images/002-1_PTiGVyDsazc_ziz6Bk4EnA.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Support for builtin IPython magics and user-defined magics&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="matplotlib"&gt;Matplotlib&lt;/h2&gt;
&lt;p&gt;Most Matplotlib back-ends are now supported by xeus-python, allowing you to show static plots with the inline back-end or interactive plots with &lt;a href="https://github.com/matplotlib/ipympl"&gt;ipympl&lt;/a&gt; in your Notebook:&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Matplotlib inline back-end and ipympl interactive back-end" src="https://blog.jupyter.org/posts/2021/abracadabra-bringing-the-magics-to-xeus-python/images/003-1_cmnPUKlhHHwUf8PZhNQx2g.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Matplotlib inline back-end and ipympl interactive back-end&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="extending"&gt;Extending&lt;/h2&gt;
&lt;p&gt;IPython has a rich configuration system that you can tweak in order to get an enhanced Notebook experience. Xeus-python now supports any configuration you setup for IPython:&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Automatically import NumPy in the IPython settings" src="https://blog.jupyter.org/posts/2021/abracadabra-bringing-the-magics-to-xeus-python/images/004-1_bB5hiXIbVAlV3kX9KJfLfg.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Automatically import NumPy in the IPython settings&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="visual-debugging"&gt;Visual Debugging&lt;/h2&gt;
&lt;p&gt;The latest JupyterLab version introduced a visual debugger in its interface. xeus-python was the first Jupyter kernel to add support for it!&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Stepping into Python code in JupyterLab with the visual debugger" src="https://blog.jupyter.org/posts/2021/abracadabra-bringing-the-magics-to-xeus-python/images/005-1_efZAtaJQqeirAZoEqbxvdw.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Stepping into Python code in JupyterLab with the visual debugger&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;xeus-python is not the only Jupyter kernel that supports debugging anymore: &lt;a href="https://github.com/jupyter-xeus/xeus-robot"&gt;xeus-robot&lt;/a&gt; is a xeus-based Jupyter kernel for the &lt;a href="https://robotframework.org/"&gt;RobotFramework&lt;/a&gt; language that supports the JupyterLab visual debugger.&lt;/p&gt;
&lt;h2 id="try-it-online"&gt;Try it online&lt;/h2&gt;
&lt;p&gt;Thanks to &lt;a href="https://mybinder.org/"&gt;MyBinder&lt;/a&gt;, you can try it out without the need of installing anything on your computer. Just follow this link:&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://mybinder.org/v2/gh/jupyter-xeus/xeus-python/stable?urlpath=/lab/tree/notebooks/xeus-python.ipynb"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/abracadabra-bringing-the-magics-to-xeus-python/images/006-0_2sBOFFsk_322apCe.jpg" alt="" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="installation"&gt;Installation&lt;/h2&gt;
&lt;p&gt;You can install the latest xeus-python version using mamba or conda:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;mamba install xeus-python -c conda-forge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;conda install xeus-python -c conda-forge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can also compile it yourself, instructions can be found in the repository:&lt;br&gt;
&lt;a href="https://github.com/jupyter-xeus/xeus-python"&gt;https://github.com/jupyter-xeus/xeus-python&lt;/a&gt;&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="acknowledgments"&gt;Acknowledgments&lt;/h2&gt;
&lt;p&gt;My work on &lt;a href="https://github.com/QuantStack/xeus"&gt;xeus&lt;/a&gt; and &lt;a href="https://github.com/QuantStack/xeus-python"&gt;xeus-python&lt;/a&gt; at &lt;a href="https://twitter.com/QuantStack"&gt;&lt;strong&gt;QuantStack&lt;/strong&gt;&lt;/a&gt; was funded by &lt;a href="https://www.techatbloomberg.com/"&gt;&lt;strong&gt;Bloomberg&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="about-the-author"&gt;About the Author&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/abracadabra-bringing-the-magics-to-xeus-python/images/007-0_5XdymjYwzZe-hvy8.jpg" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;My name is &lt;a href="https://twitter.com/martinRenou"&gt;Martin Renou&lt;/a&gt;, I am a Scientific Software Engineer at &lt;a href="https://quantstack.net/"&gt;&lt;strong&gt;QuantStack&lt;/strong&gt;&lt;/a&gt;. Before joining QuantStack, I studied at the aerospace engineering school &lt;a href="https://www.isae-supaero.fr/en"&gt;SUPAERO&lt;/a&gt; in Toulouse, France. I also worked at Logilab in Paris, France and Enthought in Cambridge, UK. As an open-source developer at QuantStack, I work on a variety of projects, from &lt;a href="https://github.com/QuantStack/xtensor"&gt;xtensor&lt;/a&gt; and &lt;a href="https://github.com/QuantStack/xeus-python/"&gt;xeus-python&lt;/a&gt; in C++ to &lt;a href="https://github.com/jupyter-widgets/ipyleaflet"&gt;ipyleaflet&lt;/a&gt; and &lt;a href="https://github.com/bqplot/bqplot"&gt;bqplot&lt;/a&gt; in Python and JavaScript/TypeScript.&lt;/p&gt;
</content><category term="IPython"/><category term="kernels"/><category term="xeus"/></entry><entry><title>An SQL solution for Jupyter</title><link href="https://blog.jupyter.org/posts/2021/an-sql-solution-for-jupyter/" rel="alternate"/><published>2021-02-03T12:03:00+00:00</published><updated>2023-01-10T18:33:00+00:00</updated><author><name>Mariana Meireles</name></author><id>tag:blog.jupyter.org,2021-02-03:/posts/2021/an-sql-solution-for-jupyter/</id><summary type="html">&lt;p&gt;xeus-sql: A xeus-sqlite sequel&lt;/p&gt;
</summary><content type="html">&lt;p&gt;A few months ago we released &lt;a href="https://github.com/jupyter-xeus/xeus-sqlite"&gt;xeus-sqlite&lt;/a&gt;, a Jupyter kernel that allows users to make SQLite queries directly from the notebook. With the needs of the Jupyter data science community in mind we decided to expand on this project.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="RDBMSes supported by xeus-sql" src="https://blog.jupyter.org/posts/2021/an-sql-solution-for-jupyter/images/001-1_tbfa_AWoqb-yB1Tk6Uq3ng.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;RDBMSes supported by xeus-sql&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Today, we’re happy to announce the next step of this endeavour, bringing you &lt;a href="https://github.com/jupyter-xeus/xeus-sql"&gt;&lt;strong&gt;xeus-sql&lt;/strong&gt;&lt;/a&gt; a general-purpose database access tool for Jupyter, which allows you to make SQL queries on many different databases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;MySQL&lt;/li&gt;
&lt;li&gt;PostgreSQL&lt;/li&gt;
&lt;li&gt;SQLite3&lt;/li&gt;
&lt;li&gt;DB2&lt;/li&gt;
&lt;li&gt;Oracle&lt;/li&gt;
&lt;li&gt;Firebird&lt;/li&gt;
&lt;li&gt;and any database with an ODBC driver.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To offer all these integrations we rely on the &lt;a href="http://soci.sourceforge.net/"&gt;SOCI&lt;/a&gt; library as the backbone of the project. SOCI abstracts all the different database connections and query details behind a unified C++ API. xeus-sql uses SOCI and &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;xeus&lt;/a&gt; to expose SQL functionalities to Jupyter.&lt;/p&gt;
&lt;p&gt;Xeus-sql, as well as the MySQL, PostgreSQL and SQLite3 backends of SOCI are available on conda-forge, meaning you can install them easily with &lt;strong&gt;conda&lt;/strong&gt; or &lt;a href="https://github.com/mamba-org/mamba"&gt;&lt;strong&gt;mamba&lt;/strong&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;# Installing xeus-sql and the mysql backend
mamba install xeus-sql soci-mysql -c conda-forge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;# Installing xeus-sql and the postgresql backend
mamba install xeus-sql soci-postgresql -c conda-forge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;# Installing xeus-sql and the sqlite backend
mamba install xeus-sql soci-sqlite -c conda-forge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There are idiosyncrasies between these different SQL backends which we detail in the xeus-sql &lt;a href="http://xeus-sql.readthedocs.io/en/latest/"&gt;documentation&lt;/a&gt; and &lt;a href="https://github.com/jupyter-xeus/xeus-sql/tree/master/examples"&gt;examples&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="visualizing-your-queries"&gt;Visualizing your queries&lt;/h2&gt;
&lt;figure&gt;
&lt;img alt="HTML and text table visualizations for different Jupyter interfaces" src="https://blog.jupyter.org/posts/2021/an-sql-solution-for-jupyter/images/002-1_1cl12TkS8uqKDgXvZCJQtQ.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;HTML and text table visualizations for different Jupyter interfaces&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;You’re probably familiar with visualizing your SQL tables and query results in the form of… tables, of course. Jupyter’s rich display system offers the option of showing them in rich-text display or plain-text display depending on which application you’re using.&lt;/p&gt;
&lt;p&gt;Beyond displaying queries with tables, you can now easily create &lt;a href="https://vega.github.io/vega-lite/"&gt;Vega-Lite&lt;/a&gt; graphs from your query results directly in the notebook:&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Running a series of examples on a notebook" src="https://blog.jupyter.org/posts/2021/an-sql-solution-for-jupyter/images/003-1_pyLtQiOV5uzGk-VKAVyD4Q.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Running a series of examples on a notebook&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;To support this feature xeus-sql relies on &lt;a href="https://github.com/Quantstack/xvega"&gt;xvega&lt;/a&gt;, a C++ backend to vega, and custom Jupyter magics for plotting through a mini-language implemented in the &lt;a href="https://github.com/jupyter-xeus/xvega-bindings/"&gt;xvega-bindings&lt;/a&gt; utility library. Besides using the mini-language you can directly provide the JSON specification for your visualization, thanks to contributions by &lt;a href="https://github.com/wangfenjin"&gt;Wang Fenjin&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Vega-Lite is a powerful library and there are many different visualizations you can create from your relational data using xeus-sql. You can see some other examples below:&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Examples of different visualizations generated with xeus-sql and xvega-lite by Wang Fenjin" src="https://blog.jupyter.org/posts/2021/an-sql-solution-for-jupyter/images/004-1_Rh5QEx6ntJHJ7gSpxgp29A.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;&lt;a href="https://github.com/wangfenjin/xeus-tidb/blob/develop/examples/TiDB.ipynb"&gt;Examples&lt;/a&gt; of different visualizations generated with xeus-sql and xvega-lite by Wang Fenjin&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;We’re looking forward to exchange with users and learn more about their use cases for xeus-sql and xvega, so if you have any questions please drop them on the public &lt;a href="https://gitter.im/QuantStack/Lobby"&gt;QuantStack chat&lt;/a&gt;, or open an issue at the project’s &lt;a href="https://github.com/jupyter-xeus/xeus-sql"&gt;GitHub page&lt;/a&gt;. As always, contributions are welcome!&lt;/p&gt;
&lt;h2 id="try-it-online"&gt;Try it online!&lt;/h2&gt;
&lt;p&gt;You can try the stable version on Binder without the need of installing anything on your computer just by clicking on the image below:&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://mybinder.org/v2/gh/jupyter-xeus/xeus-sql/stable?urlpath=lab/tree/examples/XVega%20operations.ipynb"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/an-sql-solution-for-jupyter/images/005-0_cZCb7p2dP8Y27P7P.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="acknowledgements"&gt;Acknowledgements&lt;/h2&gt;
&lt;p&gt;We are grateful to &lt;a href="https://github.com/wangfenjin"&gt;Wang Fenjin&lt;/a&gt; for his contributions with respect to the use of vega specs in xeus-sql. The plotting mini-language was built upon the xvega library by &lt;a href="https://twitter.com/mad_tandon"&gt;Madhur Tandon&lt;/a&gt;. We are also grateful to the &lt;a href="https://github.com/SOCI/soci/"&gt;SOCI&lt;/a&gt; contributors for their awesome package that made this work possible.&lt;/p&gt;
&lt;h2 id="about-the-author"&gt;About the author&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/an-sql-solution-for-jupyter/images/006-1_S-w69baox7Q1D997a5yKNw.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;My name is &lt;a href="https://twitter.com/mari_meir"&gt;Mariana Meireles&lt;/a&gt; and I’m a software developer working for &lt;a href="http://quantstack.net/"&gt;QuantStack&lt;/a&gt;. I care deeply about the impacts that technology has in the world and try my best to be the change I want to see by contributing to open source projects that stand upon libre and diverse standards.&lt;/p&gt;
</content><category term="kernels"/><category term="xeus"/></entry><entry><title>A Curiously Recurring Widget Library</title><link href="https://blog.jupyter.org/posts/2021/a-curiously-recurring-widget-library/" rel="alternate"/><published>2021-01-27T14:22:00+00:00</published><updated>2021-01-27T21:41:00+00:00</updated><author><name>Sylvain Corlay</name></author><id>tag:blog.jupyter.org,2021-01-27:/posts/2021/a-curiously-recurring-widget-library/</id><summary type="html">&lt;p&gt;Diving into the implementation of xwidgets&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Interactive widgets allow Jupyter users to create user interfaces inline in their notebooks, and to turn them into standalone applications with tools such as &lt;a href="https://github.com/voila-dashboards/voila"&gt;Voilà&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Language backends for Jupyter interactive widgets exist in Python (with &lt;a href="https://github.com/jupyter-widgets/ipywidgets"&gt;ipywidgets&lt;/a&gt;), and C++ (with &lt;a href="https://github.com/jupyter-xeus/xwidgets"&gt;xwidgets&lt;/a&gt;, and the &lt;a href="https://github.com/jupyter-xeus/xeus-cling"&gt;xeus-cling&lt;/a&gt; C++ Jupyter kernel), reusing the same frontend implementation of the widgets in JavaScript.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Simple interactive widgets at play in JupyterLab with the xeus-cling C++ kernel" src="https://blog.jupyter.org/posts/2021/a-curiously-recurring-widget-library/images/001-1_b_2s5wfIzrqGapkhBytHSg.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Simple interactive widgets at play in JupyterLab with the xeus-cling C++ kernel&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;In this article, we dive into some of the C++ techniques used in the implementation of the xwidgets library, including&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;discussions on &lt;strong&gt;value semantics&lt;/strong&gt; and &lt;strong&gt;RAII&lt;/strong&gt; (&lt;em&gt;Resource Acquisition Is Initialization&lt;/em&gt;),&lt;/li&gt;
&lt;li&gt;an original application of &lt;strong&gt;CRTP&lt;/strong&gt; (&lt;em&gt;Curiously Recurring Template Pattern&lt;/em&gt;),&lt;/li&gt;
&lt;li&gt;an original implementation of the &lt;strong&gt;observer&lt;/strong&gt; pattern, xproperty,&lt;/li&gt;
&lt;li&gt;a plea for allowing the &lt;strong&gt;overloading of the dot operator&lt;/strong&gt; in C++, to enable better proxy types.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;For readers interested in knowing more about &lt;strong&gt;interpreted C++&lt;/strong&gt;, we recommend the following posts:&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://blog.jupyter.org/posts/2017/interactive-workflows-for-c-with-jupyter/"&gt;Interactive workflows for C++ with Jupyter&lt;/a&gt; &lt;em&gt;(Jupyter blog), by Sylvain Corlay, Loic Gouarin, Johan Mabille, and Wolf Vollprecht&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.llvm.org/posts/2020-12-21-interactive-cpp-for-data-science/"&gt;Interactive C++ for Data Science&lt;/a&gt; &lt;em&gt;(LLVM blog), by Vassil Vassilev, David Lange, Simeon Ehrig, and Sylvain Corlay&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.jupyter.org/posts/2018/interpreted-c-for-gis-with-jupyter/"&gt;Interpreted C++ for GIS with Jupyter&lt;/a&gt; &lt;em&gt;(Jupyter blog), by Martin Renou&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h2 id="using-the-raii-pattern-for-a-widget-library"&gt;Using the RAII pattern for a widget library&lt;/h2&gt;
&lt;p&gt;Jupyter widgets are special objects that trigger the creation of a counterpart JavaScript model object in the Jupyter frontend upon creation. The state of the object in the backend is synchronized with the state of the JavaScript frontend object. Views of that widget model are instantiated upon display.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="The MVC (Model View Controller) architecture of Jupyter widgets, and synchronization with the backend" src="https://blog.jupyter.org/posts/2021/a-curiously-recurring-widget-library/images/002-1_ThTvsqji0l85Pr__5hs9bQ.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The MVC (Model View Controller) architecture of Jupyter widgets, and synchronization with the backend&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;This MVC (Model-View-Controller) architecture for Jupyter interactive widgets allowed us to reuse all of the frontend implementation, by simply providing an alternative backend in C++, implementing the same messaging protocol.&lt;/p&gt;
&lt;p&gt;In order to tie the lifetime of the kernel and frontend objects, we decided to use the &lt;a href="https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization"&gt;RAII (Resource Acquisition Is Initialization)&lt;/a&gt; pattern. RAII is a common programming idiom that consists of tying the lifetime of an object with the holding of a resource. Most typically, the resource is&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;acquired&lt;/strong&gt;&lt;/em&gt; in the &lt;em&gt;&lt;strong&gt;constructor&lt;/strong&gt;&lt;/em&gt; of the object,&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;released&lt;/strong&gt;&lt;/em&gt; in the &lt;em&gt;&lt;strong&gt;destructor&lt;/strong&gt;&lt;/em&gt; of the object.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The RAII pattern is not common in garbage-collected languages because unlike in C++, the time when objects are destroyed is not deterministic. The Python programming language mitigates that issue by introducing&lt;/em&gt; &lt;a href="https://docs.python.org/3/reference/compound_stmts.html#the-with-statement"&gt;&lt;em&gt;context managers&lt;/em&gt;&lt;/a&gt;&lt;em&gt;, often used to&lt;/em&gt; e.g. &lt;em&gt;open and close files.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A consequence of relying on object lifetime for resource management in C++ is to adopt the “&lt;em&gt;&lt;strong&gt;value semantics&lt;/strong&gt;&lt;/em&gt;” for widget instances, instead of “&lt;em&gt;&lt;strong&gt;reference semantics&lt;/strong&gt;&lt;/em&gt;” which is more typical for widget frameworks like Qt.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note: value semantics vs reference semantics&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If you are not familiar with the concepts of&lt;/em&gt; &lt;strong&gt;value&lt;/strong&gt; &lt;em&gt;and&lt;/em&gt; &lt;strong&gt;reference&lt;/strong&gt; &lt;strong&gt;semantics&lt;/strong&gt; &lt;em&gt;in C++, I recommend reading the&lt;/em&gt; &lt;a href="https://isocpp.org/wiki/faq/value-vs-ref-semantics"&gt;&lt;em&gt;&lt;strong&gt;excellent FAQ&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; &lt;em&gt;of isocpp.org.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;To summarize:&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;with &lt;strong&gt;value semantics&lt;/strong&gt;, objects hold actual values, and copying an object copies their attributes. With value semantics, one should provide implementations of &lt;strong&gt;copy, and move constructors&lt;/strong&gt;, as well as &lt;strong&gt;copy and move assignment operators&lt;/strong&gt;. Besides, values should not have virtual methods.&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;with &lt;strong&gt;reference semantics&lt;/strong&gt;, objects are manipulated through references (or pointers) and never by value. Reference semantics is typically used for polymorphic programming with &lt;strong&gt;virtual methods&lt;/strong&gt;. With reference semantics, it is recommended to delete copy and move constructors, as well as copy and move assignment operators to avoid accidental copies when passing objects to functions taking arguments by values, causing object slicing. (They can also be made private). Explicit cloning of a reference semantics object is generally allowed via a call to a &lt;strong&gt;clone&lt;/strong&gt; virtual method.&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;In a C++ codebase, the existence of public copy or move constructors alongside virtual methods in the same class is generally a sign of a bad design.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The use of value semantics for xwidgets provides clear lifetime management for associated resources. Careful use of the move semantics provides fine-grained control.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Illustration of the move semantics for xwidgets" src="https://blog.jupyter.org/posts/2021/a-curiously-recurring-widget-library/images/003-1_i1D4_PqaKhej-XRSKkoyBw.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Illustration of the move semantics for xwidgets&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Another advantage of using value semantics in xwidgets is that C++ &lt;strong&gt;beginners&lt;/strong&gt; who are typical users of the Jupyter notebook (often used by instructors) can easily manipulate “widgets as values” without having to deal with manual memory allocation etc.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;With value semantics, addressing the lifetime of objects becomes the responsibility of the framework author, in a carefull implementation of (copy and move) constructors, destructors, and (copy and move) assignment operators.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="static-polymorphism-and-the-crtp-pattern"&gt;Static polymorphism and the CRTP pattern&lt;/h2&gt;
&lt;p&gt;While the use of value semantics provides fine-grained control over the lifetime of widgets, it prevents the use of virtual methods in their implementation. Code reuse is achieved with static polymorphism techniques and specifically the CRTP pattern.&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern"&gt;Curiously Recurring Template Pattern (CRTP)&lt;/a&gt; is the practice of making a class &lt;code&gt;X&lt;/code&gt; derive from a class template instantiation using &lt;code&gt;X&lt;/code&gt; itself as a template argument.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="o"&gt;X&lt;/span&gt; : &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="nb"&gt;base&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;X&lt;/span&gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;CRTP is commonly used by matrix or tensor algebra libraries making use of expression templates (such as &lt;a href="https://github.com/xtensor-stack/xtensor"&gt;xtensor&lt;/a&gt;, &lt;a href="http://eigen.tuxfamily.org/index.php?title=Main_Page"&gt;eigen&lt;/a&gt;, or &lt;a href="https://github.com/blitzpp/blitz"&gt;blitz&lt;/a&gt;) to prevent the overhead of virtual function dispatch for operations likely to be performed in a loop, such as element access.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Placing common code in a CRTP base allows code reuse without the overhead of virtual dispatch. However, the template base class is specialized for each final type increasing the resulting &lt;strong&gt;binary size&lt;/strong&gt;. This can be mitigated by factoring as much of the code in a base class that would not be templated by the derived type.&lt;/p&gt;
&lt;h2 id="crtp-in-xwidgets-closing-the-recursion"&gt;CRTP in xwidgets — closing the recursion&lt;/h2&gt;
&lt;p&gt;In order to allow for code reuse without virtual inheritance, xwidgets’ class hierarchy is entirely based on CRTP. Our naming scheme is that CRTP bases, which should not be instantiated directly are prefixed with the letter &lt;code&gt;x&lt;/code&gt; and final concrete widget types are not.&lt;/p&gt;
&lt;p&gt;Upon construction of &lt;em&gt;e.g.&lt;/em&gt; the &lt;strong&gt;&lt;code&gt;button&lt;/code&gt;&lt;/strong&gt; widget, constructors of base types are called in the order of inheritance, which is why we need to establish the connection with the frontend in the constructor of the most derived type, after all attributes have been initialized, and send a message to the frontend with all the values.&lt;/p&gt;
&lt;p&gt;The pattern for creating the most derived type being always the same, we defined the &lt;strong&gt;&lt;code&gt;xmaterialize&lt;/code&gt;&lt;/strong&gt; template class closing the CRTP hierarchy with&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;using button = xmaterialize&amp;lt;xbutton&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;strong&gt;&lt;code&gt;xmaterialize&lt;/code&gt;&lt;/strong&gt; template class is defined as &lt;strong&gt;final&lt;/strong&gt;, to prevent further inheritance. The constructors and assignment operators forward to those of the CRTP bases and implement the RAII pattern.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;xmaterialize&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;final&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;public&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;B&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;xmaterialize&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt;&lt;span class="o"&gt;...&amp;gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;public&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;using&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;self_type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;xmaterialize&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;using&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;base_type&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;B&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;self_type&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;xmaterialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;base_type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nx"&gt;forward&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;A&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;open&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="c1"&gt;//  RAII: create the frontend model.&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;inline&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;xmaterialize&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;P&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="o"&gt;::~&lt;/span&gt;&lt;span class="nx"&gt;xmaterialize&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(!&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;moved_from&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;close&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="c1"&gt;// RAII: delete the frontend model.&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;

&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The full implementation of &lt;strong&gt;&lt;code&gt;xmaterialize&lt;/code&gt;&lt;/strong&gt; (as of xwidgets 0.25) is available &lt;a href="https://raw.githubusercontent.com/jupyter-xeus/xwidgets/0.25.0/include/xwidgets/xmaterialize.hpp"&gt;here&lt;/a&gt;. Beyond the logic described in this section, it also includes the handling of the move semantics and the method chaining API which is the subject of a later section.&lt;/p&gt;
&lt;h2 id="precompilation-and-binary-size-optimization"&gt;Precompilation and binary size optimization&lt;/h2&gt;
&lt;p&gt;Even though xwidgets is fully based on template types, we decided to precompile all final widget types for faster interactive use with the xeus-cling kernel. This is achieved with&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;an &lt;strong&gt;&lt;code&gt;extern&lt;/code&gt;&lt;/strong&gt; declaration in the header (here in &lt;code&gt;xbutton.hpp&lt;/code&gt;)&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;extern template class xmaterialize&amp;lt;xbutton&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;and in the source file (here in &lt;code&gt;xbutton.cpp&lt;/code&gt;), an instruction for the precompilation&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;template class XWIDGETS_API xmaterialize&amp;lt;xbutton&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Doing this for all widget types of the library initially resulted in a large compiled binary size. Using the &lt;strong&gt;&lt;code&gt;button&lt;/code&gt;&lt;/strong&gt; widget as an example, we see that base types are templated by the final type in the class hierarchy &lt;strong&gt;&lt;code&gt;button -&amp;gt; xbutton&amp;lt;button&amp;gt; -&amp;gt; xwidgets&amp;lt;button&amp;gt; -&amp;gt; xobject&amp;lt;button&amp;gt;&lt;/code&gt;&lt;/strong&gt;, and therefore, their binary representation is duplicated for each final type.&lt;/p&gt;
&lt;p&gt;A strategy for reducing the binary size has been to factor out as much of the logic of &lt;strong&gt;&lt;code&gt;xobject&amp;lt;D&amp;gt;&lt;/code&gt;&lt;/strong&gt; in a non-template base &lt;strong&gt;&lt;code&gt;xcommon&lt;/code&gt;&lt;/strong&gt; improving compilation speed and preventing binary code duplication.&lt;/p&gt;
&lt;h2 id="xproperty-an-implementation-of-the-observer-pattern"&gt;Xproperty: an implementation of the observer pattern&lt;/h2&gt;
&lt;p&gt;In order to update the frontend upon changes of widget properties, xwidgets relies on an implementation of the observer pattern called &lt;a href="https://github.com/jupyter-xeus/xproperty"&gt;&lt;strong&gt;&lt;code&gt;xproperty&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt;. xproperty is to xwidgets what &lt;a href="https://github.com/ipython/traitlets"&gt;traitlets&lt;/a&gt; are to ipywidgets.&lt;/p&gt;
&lt;p&gt;In order to trigger observers and validators in the owner object upon assignment of new values, xproperty relies on the overload of the assignment operator &lt;strong&gt;&lt;code&gt;=&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;template&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;O&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="n"&gt;template&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;V&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="n"&gt;inline&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;auto&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;xproperty&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;O&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;::&lt;/span&gt;&lt;span class="n"&gt;operator&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;V&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;reference&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// Before assigning the new value, invoke validators&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// which may also mutate the value.&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;m_value&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;template&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;invoke_validators&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;forward&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;V&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// Call class-level observer.&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;m_value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// Call registered observers for that attribute&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;invoke_observers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m_name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="c1"&gt;// Return the new value &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;m_value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="method-chaining-for-widget-initialization"&gt;Method chaining for widget initialization&lt;/h2&gt;
&lt;p&gt;Jupyter interactive widgets have many attributes that may be specified at construction time.&lt;/p&gt;
&lt;p&gt;In the Python implementation, this is handled with keyword arguments, but the C++ programming language does not support keyword arguments. There exist various approaches to enable this feature with advanced metaprogramming techniques. In the case of xwidgets, this need is limited to the initialization of xproperty attributes, which allowed us to adopt a more scoped approach: a method chaining API for property initialization:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nf"&gt;auto&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;slider&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;slider&lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;double&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="no"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="na"&gt;.min&lt;/span&gt;&lt;span class="p"&gt;(-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="no"&gt;.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="na"&gt;.max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="no"&gt;.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="na"&gt;.description&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Another slider&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="na"&gt;.finalize&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;this was enabled by overriding the function call operator () on xproperties to pass an intial value (only when the said property is an rvalue). A static &lt;strong&gt;&lt;code&gt;initialize&lt;/code&gt;&lt;/strong&gt; method is used instead of the default constructor to prevent the initialization of the JavaScript counterpart while all attributes may not have been set yet. The frontend counterpart is only acquired with the &lt;strong&gt;&lt;code&gt;finalize()&lt;/code&gt;&lt;/strong&gt; call.&lt;/p&gt;
&lt;h2 id="building-upon-xwidgets"&gt;Building upon xwidgets&lt;/h2&gt;
&lt;p&gt;Jupyter interactive widgets are not limited to the controls available in the core package. In fact, there is a rich ecosystem of widget libraries built upon the core framework: &lt;a href="https://github.com/maartenbreddels/ipyvolume"&gt;ipyvolume&lt;/a&gt; (3-D plotting), &lt;a href="https://github.com/jupyter-widgets/ipyleaflet"&gt;ipyleaflet&lt;/a&gt; (maps visualization), &lt;a href="https://github.com/bqplot/bqplot"&gt;bqplot&lt;/a&gt; (2-D plotting), &lt;a href="https://github.com/QuantStack/ipygany"&gt;ipygany&lt;/a&gt; (3-D mesh visualization), &lt;a href="https://github.com/martinRenou/ipycanvas"&gt;ipycanvas&lt;/a&gt; (generic drawing), &lt;a href="https://github.com/maartenbreddels/ipywebrtc"&gt;ipywebrtc&lt;/a&gt; (streaming video and audio), and many many more.&lt;/p&gt;
&lt;p&gt;For the C++ programming language, we have already provided:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/jupyter-xeus/xleaflet"&gt;xleaflet&lt;/a&gt; (the C++ equivalent to ipyleaflet, reusing the same frontend),&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/QuantStack/xwebrtc"&gt;xwebrtc&lt;/a&gt; (the C++ equivalent to ipywebrtc, reusing the same frontend).&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
&lt;img alt="Screencast of xleaflet in JupyterLab, loading and visualizing a GeoJSON dataset in a C++ notebook." src="https://blog.jupyter.org/posts/2021/a-curiously-recurring-widget-library/images/004-1_IULQ8LZDnLFMmB1nsbNF0Q.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Screencast of xleaflet in JupyterLab, loading and visualizing a GeoJSON dataset in a C++ notebook.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Potentially, C++ backend to all Jupyter interactive widget packages could be provided, creating a huge opportunity for interactive data visualization in C++.&lt;/p&gt;
&lt;h2 id="c-should-allow-overloading-the-dot-operator"&gt;C++ should allow overloading the dot operator&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;xwidgets&lt;/strong&gt; and &lt;strong&gt;xproperty&lt;/strong&gt; makes heavy use of value semantics, and proxy objects.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;At the moment, to access an attribute or method of a value held in an xproperty object, we must first call the function call operator () to access the undelying object first, which is cumbersome.&lt;/li&gt;
&lt;li&gt;This is also an issue in other places in the xwidgets stack, when making use of &lt;em&gt;e.g.&lt;/em&gt; reference proxies.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Being able to automatically map all methods of the underlying type to be accessible in the xproperty would be incredibly powerful, and remove the need for explicitly accessing the underlying.&lt;/p&gt;
&lt;p&gt;Interestingly, the C++ standard does have the equivalent operator overload when it comes to pointer semantics, with the arrow operator &lt;strong&gt;&lt;code&gt;-&amp;gt;&lt;/code&gt;&lt;/strong&gt;. If overloading the dot operator . was allowed, this could enable this kind of usecase:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;struct V
{
    void f();
};

struct X
{
    V&amp;amp; operator.() { return m_value; }
    V m_value;
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;in which case, &lt;strong&gt;&lt;code&gt;X::f&lt;/code&gt;&lt;/strong&gt; would call &lt;strong&gt;&lt;code&gt;V::f&lt;/code&gt;&lt;/strong&gt; .&lt;/p&gt;
&lt;p&gt;Allowing the overloading of the dot operator . would also enable usecases such as &lt;strong&gt;smart references&lt;/strong&gt; (similar to smart pointers, but with value semantics) and fully-fledged &lt;strong&gt;reference proxies&lt;/strong&gt; (such as the return type of &lt;code&gt;operator[]&lt;/code&gt; for &lt;code&gt;std::vector&amp;lt;bool&amp;gt;&lt;/code&gt;).&lt;/p&gt;
&lt;h2 id="try-it-online"&gt;Try it online!&lt;/h2&gt;
&lt;p&gt;Thanks to &lt;a href="https://mybinder.org/"&gt;MyBinder&lt;/a&gt;, you can try xwidgets without the need of installing anything on your computer. Just follow this link:&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://mybinder.org/v2/gh/jupyter-xeus/xwidgets/stable?filepath=notebooks/xwidgets.ipynb"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/a-curiously-recurring-widget-library/images/005-0_TQpdhVZSAnE-XOrm.jpg" alt="&amp;quot;Launch binder&amp;quot; badge" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="about-the-author"&gt;About the author&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://twitter.com/SylvainCorlay"&gt;Sylvain Corlay&lt;/a&gt; is the founder and CEO of &lt;a href="https://twitter.com/QuantStack"&gt;QuantStack&lt;/a&gt;, an open-source software development studio comprising maintainers of key projects of the scientific computing ecosystem.&lt;/p&gt;
&lt;p&gt;As an open-source developer, Sylvain is very active in the Jupyter project, contributing to the &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;Xeus&lt;/a&gt; stack, Jupyter interactive widgets, &lt;a href="https://github.com/voila-dashboards/voila"&gt;Voilà dashboards&lt;/a&gt;. He is a member of the Jupyter steering committee and was the vice chair of &lt;a href="https://jupytercon.com/"&gt;JupyterCon 2020&lt;/a&gt;. Sylvain also contributes to the &lt;a href="https://conda-forge.org/"&gt;conda-forge&lt;/a&gt; project and he is the co-creator of the &lt;a href="https://github.com/xtensor-stack/xtensor"&gt;Xtensor&lt;/a&gt; C++ tensor algebra library.&lt;/p&gt;
</content><category term="C++"/><category term="widgets"/><category term="xeus"/></entry><entry><title>Robotic Process Automation with JupyterLab</title><link href="https://blog.jupyter.org/posts/2021/robotic-process-automation-with-jupyterlab/" rel="alternate"/><published>2021-01-18T10:36:00+00:00</published><updated>2021-01-18T10:36:00+00:00</updated><author><name>Martin Renou</name></author><id>tag:blog.jupyter.org,2021-01-18:/posts/2021/robotic-process-automation-with-jupyterlab/</id><summary type="html">&lt;p&gt;Introducing a new Jupyter kernel for Robot Framework&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Robotic Process Automation (RPA) differs from classical automation tools in that the actions to automate can be developed by observing a user perform a task in a graphical user interface, across multiple applications.&lt;/p&gt;
&lt;p&gt;It is a means to lower the entry barrier of process automation and enable the use of tools that don’t provide a programmatic interface.&lt;/p&gt;
&lt;p&gt;Most typically, RPA developers will use a mixed approach between textual programming and performing actions manually. The resulting programs are typically called software &lt;em&gt;robots&lt;/em&gt;. Therefore, interactive computing tools like Jupyter are a natural environment for RPA, as the interactive nature of Jupyter allows for quick iterations and trial-and-errors when developing such robots.&lt;/p&gt;
&lt;p&gt;While many RPA tools are commercial software, &lt;a href="https://robotframework.org/"&gt;Robot Framework&lt;/a&gt; and the tooling developed by &lt;a href="https://robocorp.com/"&gt;Robocorp&lt;/a&gt; provide an open-source RPA programming language, with a high-level syntax, extensible with Python plugins. It has a rich ecosystem of libraries and tools that are developed as separate projects.&lt;/p&gt;
&lt;h2 id="robot-framework-and-project-jupyter"&gt;Robot Framework and Project Jupyter&lt;/h2&gt;
&lt;p&gt;Today, we are happy to announce the first release of &lt;a href="https://github.com/jupyter-xeus/xeus-robot"&gt;&lt;strong&gt;xeus-robot&lt;/strong&gt;&lt;/a&gt;, a Jupyter kernel for &lt;a href="https://robotframework.org/"&gt;Robot Framework&lt;/a&gt; based on &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;xeus&lt;/a&gt;, supporting the new JupyterLab 3.0 visual debugger, auto-completion, and much more!&lt;/p&gt;
&lt;p&gt;But before we dive into xeus-robot, we should recognize the earlier work by &lt;a href="https://github.com/bollwyvl"&gt;Nick Bollweg&lt;/a&gt; and &lt;a href="https://github.com/datakurre"&gt;Asko Soukka&lt;/a&gt;, who developed two Jupyter kernels for Robot Framework, &lt;a href="https://github.com/gtri/irobotframework"&gt;irobotframework&lt;/a&gt;, and &lt;a href="https://github.com/robots-from-jupyter/robotkernel"&gt;robotkernel&lt;/a&gt;, and gave an &lt;a href="https://www.youtube.com/watch?v=rbYF_RmiAR8"&gt;amazing talk&lt;/a&gt; together at &lt;a href="https://robocon.io/"&gt;RoboCon&lt;/a&gt; in 2019!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The motivation for us to reboot this effort with a kernel based on xeus was to enable the &lt;strong&gt;JupyterLab Visual Debugger&lt;/strong&gt; for this kernel. This requires a different concurrency model than that of ipykernel, which underlies both irobotframework and robotkernel. In the end, we were able to provide the same features and more, including e.g. code completion in Python cells, debugging etc.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="diving-into-xeus-robot"&gt;Diving into Xeus-robot&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/robotic-process-automation-with-jupyterlab/images/001-1_3HNfLnwDpXNZ6n6HPD2lXQ.webp" alt="Xeus robot logo" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-robot"&gt;xeus-robot&lt;/a&gt; is a reboot of the already existing robotkernel, based on xeus.&lt;/p&gt;
&lt;p&gt;Like most language kernels, &lt;a href="https://github.com/jupyter-xeus/xeus-robot"&gt;xeus-robot&lt;/a&gt; supports code completion, inspection, error handling, etc. It also allows using Python cells to define custom robot keywords in Python, those Python cells support code completion as well.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Code completion in Robot framework" src="https://blog.jupyter.org/posts/2021/robotic-process-automation-with-jupyterlab/images/002-1_OPqkYEI78eT1dj5P6WEeXg.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Code Completion in Robot Framework&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;By using the libraries robotframework-seleniumlibrary and robotframework-seleniumscreenshots, you can even complete the selection of elements on the page you are currently testing!&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="RPA code completion" src="https://blog.jupyter.org/posts/2021/robotic-process-automation-with-jupyterlab/images/003-1_Z-aWN6goZH_1YcabAYj2fQ.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Code completion with an action of the user in the UI.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The &lt;code&gt;%%python&lt;/code&gt; cell magic makes it possible to extend Robotframework with Python modules in the notebook.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Robot Framework extenions in Python" src="https://blog.jupyter.org/posts/2021/robotic-process-automation-with-jupyterlab/images/004-1_TSiSmKHJOGE0PQ_c7alv1w.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Extending RobotFramework with Python, and code completion in Python cells&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Widget-based UIs are provided to test Robotframework “keywords”.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Robot Framework and Jupyter widgets" src="https://blog.jupyter.org/posts/2021/robotic-process-automation-with-jupyterlab/images/005-1_nyXQAQivNvV23xvS_1KCYQ.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Testing Robot Framework “keywords” with Jupyter widgets&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Last but not least, xeus-robot comes with full support for the JupyterLab Visual Debugger! After the xeus-python kernel, it is the second Jupyter kernel to support the Jupyter Debugger Protocol! We hope that many more will come.&lt;/p&gt;
&lt;p&gt;You can set breakpoints, step in defined keywords (the equivalent of functions), inspect variables, and see the callstack, as shown below.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="JupyterLab Visual Debugger" src="https://blog.jupyter.org/posts/2021/robotic-process-automation-with-jupyterlab/images/006-1_EFxI8mzCwYwnK9DB_xGxTQ.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The JupyterLab Visual Debugger in action with Robot Framework&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="installing-xeus-robot"&gt;Installing xeus-robot&lt;/h2&gt;
&lt;p&gt;Xeus-robot is available for all platforms on conda-forge, and can be installed with conda or mamba.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;mamba install xeus-robot -c conda-forge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;jupyterlab-robotmode&lt;/code&gt; package, which provides JupyterLab syntax highlighting for Robot Framework will also be installed as a dependency.&lt;/p&gt;
&lt;p&gt;For your conda installation, we recommend starting from &lt;strong&gt;mambaforge&lt;/strong&gt; or &lt;strong&gt;miniforge&lt;/strong&gt; which are available for download &lt;a href="https://github.com/conda-forge/miniforge"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;, and default to the conda-forge channel (making the &lt;code&gt;-c conda-forge&lt;/code&gt; argument unnecessary).&lt;/p&gt;
&lt;h2 id="try-it-online"&gt;Try it online&lt;/h2&gt;
&lt;p&gt;Thanks to &lt;a href="https://mybinder.org/"&gt;MyBinder&lt;/a&gt;, you can try it out without the need of installing anything on your computer. Just follow this link:&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://mybinder.org/v2/gh/jupyter-xeus/xeus-robot/stable?urlpath=/lab/tree/notebooks/xrobot.ipynb"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/robotic-process-automation-with-jupyterlab/images/007-0_TQpdhVZSAnE-XOrm.jpg" alt="&amp;quot;Launch binder&amp;quot; badge" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="acknowledgments"&gt;Acknowledgments&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://robocorp.com/"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/robotic-process-automation-with-jupyterlab/images/008-1_E9XGge6uWrbmvndUoZ1Qug.webp" alt="Robocorp logo" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The work on xeus-robot by &lt;a href="https://twitter.com/QuantStack"&gt;QuantStack&lt;/a&gt; was funded by &lt;a href="https://robocorp.com/"&gt;Robocorp&lt;/a&gt;, and is part of their initiative to create an open-source RPA ecosystem. Beyond the xeus-robot kernel, Robocorp also funds the integration of Robot Framework with &lt;a href="https://marketplace.visualstudio.com/items?itemName=robocorp.robocorp-code"&gt;Visual Studio Code&lt;/a&gt;, &lt;a href="https://rpaframework.org/"&gt;RPA Framework&lt;/a&gt;, and other development to push the Robot Framework project forward.&lt;/p&gt;
&lt;p&gt;The implementation of the debugger in xeus-robot relies on &lt;a href="https://github.com/robocorp/robotframework-lsp"&gt;robotframework-lsp&lt;/a&gt; by &lt;a href="https://twitter.com/fabiofz"&gt;Fabio Zadrozny&lt;/a&gt; and we want to thank him for his help in integrating it in xeus-robot.&lt;/p&gt;
&lt;h2 id="about-the-authors"&gt;About the authors&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/robotic-process-automation-with-jupyterlab/images/009-1_zwPmx9pH4pkXOxowHQOsuQ.jpeg" alt="Martin Renou" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Martin Renou&lt;/strong&gt; is a scientific software developer at QuantStack. He is the creator of the xeus-python and xeus-robot kernels.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2021/robotic-process-automation-with-jupyterlab/images/010-1_YQZupQRMB6JJfhM_byi2KA.jpeg" alt="Johan Mabille" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Johan Mabille&lt;/strong&gt; is a scientific software developer at QuantStack. He is a co-author of the xeus project, and developed the debugger extensions to xeus-python and xeus-robot. He also co-authored the front-end for the JupyterLab visual debugger.&lt;/p&gt;
</content><category term="debugging"/><category term="JupyterLab"/><category term="kernels"/><category term="xeus"/></entry><entry><title>SlicerJupyter: a 3D Slicer kernel for interactive publications</title><link href="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/" rel="alternate"/><published>2020-07-08T16:29:00+00:00</published><updated>2020-07-08T16:58:00+00:00</updated><author><name>Jean-Christophe Fillion-Robin</name></author><id>tag:blog.jupyter.org,2020-07-08:/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/</id><summary type="html">&lt;p&gt;Use Jupyter and 3D Slicer kernel to implement biomedical data processing workflows in a notebook.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;em&gt;Use Jupyter and 3D Slicer kernel to implement biomedical data processing workflows in a notebook.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The Jupyter ecosystem is a powerful platform for exploratory computational science, and now it can connect with some of the deep and rich domain-specific desktop applications that have decades of feature development already invested in them. With the integration of &lt;a href="https://www.slicer.org/"&gt;3D Slicer&lt;/a&gt; with Jupyter through the &lt;a href="https://github.com/jupyter-xeus/xeus-python"&gt;xeus-python&lt;/a&gt;’s interpreter, we demonstrate how a &lt;a href="https://www.qt.io/"&gt;Qt-based&lt;/a&gt; graphical desktop application with 3D visualization provided by &lt;a href="https://vtk.org/"&gt;Visualization Toolkit (VTK)&lt;/a&gt;, image processing provided by the &lt;a href="https://itk.org/"&gt;Insight Toolkit (ITK)&lt;/a&gt;, can be used through a Jupyter notebook. This approach is available on the &lt;a href="https://github.com/Slicer/SlicerJupyter"&gt;SlicerJupyter&lt;/a&gt; GitHub repository and could be extended to other applications that embed Python, such as Blender, FreeCAD, or ParaView.&lt;/p&gt;
&lt;p&gt;This xeus-python integration is beneficial both for the Jupyter ecosystem and desktop applications. Features that have been developed for decades for desktop applications become readily available for Jupyter users without learning a new working environment or redeveloping features. For a desktop application, the Jupyter notebook can serve as a way to create reproducible data processing workflows, scientific publications, and maintainable tutorials without requiring local software installation. From Jupyter, you can now quickly create simple medical imaging applications with extremely rich interactivity from 3D Slicer. Read below for a discussion of the features available and the history of the project.&lt;/p&gt;
&lt;h2 id="powerful-medical-imaging-capabilities-available-through-jupyter"&gt;Powerful Medical Imaging Capabilities Available Through Jupyter&lt;/h2&gt;
&lt;p&gt;3D Slicer (or Slicer for short) is a C++ desktop application that uses Qt, ITK, and VTK libraries for visualization and medical image analysis. Slicer’s embedded Python interpreter makes all its features accessible with the Python programming language. Slicer has a simple built-in console to run Python commands interactively and can run Python scripts from files, but these are not as convenient as cell-base interactive notebooks, which have become popular among data scientists and researchers in recent years.&lt;/p&gt;
&lt;p&gt;By integrating the xeus-python kernel, we can use a Slicer process as a Jupyter kernel. xeus-python leverages the &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;xeus&lt;/a&gt; C++ implementation of the Jupyter kernel protocol. xeus-python is &lt;a href="https://blog.jupyter.org/posts/2019/a-new-python-kernel-for-jupyter/"&gt;an alternative to ipykernel&lt;/a&gt;, which can be used with a vanilla CPython interpreter, interfacing to standard CPython Jupyter widgets like &lt;a href="https://github.com/InsightSoftwareConsortium/itkwidgets"&gt;itkwidgets&lt;/a&gt;, but it can also be coupled with custom interpreters and GUI event loops, like the Slicer interpreter and its Qt event loop. This allows you to represent a complete scene in Medical Reality Markup Language, MRML, Slicer’s internal data structure. The kernel exposes the full medical imaging API and representation of your data in a meaningful way for Python developers, allowing access through standard Python ecosystem formats such as pandas dataframes and NumPy arrays in the Notebook.&lt;/p&gt;
&lt;h3 id="interactivity-levels"&gt;Interactivity Levels&lt;/h3&gt;
&lt;p&gt;You can also use Jupyter interactive widgets (sliders, buttons, etc.) to control Slicer, modify data, or adjust processing and visualization parameters. Interactivity can be implemented at different levels.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Level 1&lt;/strong&gt;: Standard Jupyter widgets display application specific objects by automatic conversion of application-specific data objects to standard Python objects. For example, Slicer markup fiducial lists are displayed as a nicely formatted table and model nodes are rendered as 3D objects.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Level 2&lt;/strong&gt;: Static image widgets display content that the desktop application renders. These widgets can be made interactive by modifying data and rendering parameters using additional standard widgets. This makes rich visualization capabilities — sophisticated rendering various data types, rendering of very large data sets, etc. directly available in Jupyter.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Level 3&lt;/strong&gt;: Dynamic viewer widgets display 2D and 3D views rendered by the desktop application. Mouse and keyboard events are forwarded to the desktop application that allows zooming/rotating views, and to utilize all 3D interactions implemented in the desktop such as placing annotations, making measurements, or segmenting images the same way as if it was done on the desktop appication’s screen. This is implemented in the Slicer Jupyter kernel using &lt;a href="https://ipycanvas.readthedocs.io/en/latest/"&gt;ipycanvas&lt;/a&gt; and &lt;a href="https://github.com/mwcraig/ipyevents"&gt;ipyevents&lt;/a&gt; packages.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Level 4&lt;/strong&gt;: Full desktop graphical user interface integration. Users can see parts of the application window rendered in notebook cells, including standard desktop widgets (sliders, menus, etc.). It is implemented using noVNC and TigerVNC in Slicer Jupyter. This is particularly useful when the application runs on a remote server.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
&lt;iframe src="https://www.youtube-nocookie.com/embed/oZ3_cRXX2QM" title="Medical image processing in your web browser using Jupyter notebooks and 3D Slicer" width="560" height="315" style="aspect-ratio: 560 / 315" loading="lazy" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen&gt;&lt;/iframe&gt;
&lt;figcaption&gt;
&lt;p&gt;Video demonstrating how to run 3D Slicer using Binder&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;These interactive tools allow developers to implement complete data processing workflows in a notebook, even if certain steps require manual user inputs such as segmenting 3D regions or setting seed points.&lt;/p&gt;
&lt;h3 id="try-it-online"&gt;Try it online!&lt;/h3&gt;
&lt;p&gt;Since Jupyter notebooks can be used from any web browser, it can essentially turn any desktop application to a web application. By setting up a remote Jupyter server, users do not have to install anything on their computers. We have set up a demonstration of this using Binder (&lt;a href="http://www.mybinder.org"&gt;www.mybinder.org&lt;/a&gt;) that anybody can try at &lt;a href="https://mybinder.org/v2/gh/Slicer/SlicerNotebooks/master"&gt;https://mybinder.org/v2/gh/Slicer/SlicerNotebooks/master&lt;/a&gt;.&lt;/p&gt;
&lt;figure&gt;
&lt;a href="https://mybinder.org/v2/gh/Slicer/SlicerNotebooks/master"&gt;&lt;img alt="Click on the binder image to launch the demo" src="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/images/001-0_powLrWNrbtb0dRWs.webp" loading="lazy" data-body-image=""&gt;&lt;/a&gt;
&lt;figcaption&gt;Click on the binder image to launch the demo&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The docker image that installs and configures Slicer and all dependencies (ipycanvas, ipyevents, VNC, etc.) is available at &lt;a href="https://github.com/Slicer/SlicerDocker/tree/master/slicer-notebook"&gt;https://github.com/Slicer/SlicerDocker/tree/master/slicer-notebook&lt;/a&gt;. For deployment to non-technical users, applications can be deployed using Voilà (&lt;a href="https://voila.readthedocs.io/"&gt;https://voila.readthedocs.io/&lt;/a&gt;), which only shows relevant content and interactive widgets, so the notebook looks like a simple dynamic web page.&lt;/p&gt;
&lt;p&gt;The current implementation is already stable and offers a wide range of features, but there is still room for design and performance improvements. For example, we could not implement fully automatic conversion of application-specific data objects to displayable Python objects (due to complex implementation of display hooks); xeus-python debugger’s threading model needs to be improved to allow using it without locking the application’s main thread; and dynamic viewer widget’s performance (level 3 interaction) could be optimized to achieve higher refresh rates.&lt;/p&gt;
&lt;h2 id="history-of-slicer-and-this-integration"&gt;History of Slicer and this integration&lt;/h2&gt;
&lt;p&gt;Built over two decades with support from the NIH and a worldwide open source developer community, 3D Slicer is a unique, multi-platform desktop application for analysis, integration, and visualization of medical images that is heavily used by researchers globally for basic and applied research in a wide range of topics. The 3D Slicer Community includes physician-scientists with disease-specific knowledge of clinical challenges, computer scientists and physicists who develop novel algorithms, imaging informatics researchers, software engineers with the ability to understand clinical problems and create reliable tools, and application engineers with the multidisciplinary skills to deploy these tools in a range of cancer research settings. Slicer is maintained by Kitware, Inc., and the NAMIC consortium, and has an active open source software community. Slicer is used in hospitals and by researchers, with more than 10k academic citations and more than 150k downloads in the last year alone.&lt;/p&gt;
&lt;figure&gt;
&lt;a href="https://download.slicer.org"&gt;&lt;img alt="Click on the image to download 3D Slicer" src="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/images/002-1_ePhHKkjqV-AW0mvDkaeurw.webp" loading="lazy" data-body-image=""&gt;&lt;/a&gt;
&lt;figcaption&gt;Click on the image to download 3D Slicer&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;It can be used for image processing workflows on 2D, 3D, and 4D images. What makes Slicer so useful is its huge set of community contributed modules that extend its functionality, as well as its ability to read DICOM and a wide array of exotic file formats.&lt;/p&gt;
&lt;p&gt;Slicer has been scriptable in Python for well over a decade, but a robust &lt;a href="https://github.com/Slicer/SlicerJupyter"&gt;SlicerJupyter&lt;/a&gt; extension is born from significant development effort by the community. The idea for this integration dates back to SciPy in 2014, when Jean-Christophe Fillion-Robin of Kitware organized a sprint intended to integrate Slicer and an IPython notebook, motivated by the dream of creating interactive and fun tutorials for Slicer. Mike Sarahan and Jean-Christophe created this proof of concept &lt;a href="https://github.com/commontk/QEmbedIPython#qt-embed-ipython"&gt;https://github.com/commontk/QEmbedIPython#qt-embed-ipython&lt;/a&gt;, but it was far from usable. In 2015 Matt McCormick of Kitware, created the &lt;a href="https://github.com/Slicer/SlicerDocker"&gt;SlicerDocker&lt;/a&gt; repository to support headless builds and rendering in a Docker image. Then in June 2018, while attending the Slicer Project Week, Andras Lasso (Queen’s University) and Jean-Christophe learned about Xeus, a C++ implementation of the Jupyter kernel protocol developed by QuantStack that would help streamline the integration of Slicer with Jupyter. To support this effort, Andras and Jean-Christophe created the &lt;a href="https://github.com/Slicer/SlicerJupyter"&gt;Slicer/SlicerJupyter&lt;/a&gt; GitHub repository. They also contributed changes to Xeus to support this new integration paradigm where the event loop of the kernel is driven by a Qt-based Desktop application (see &lt;a href="https://github.com/jupyter-xeus/xeus/pull/63"&gt;here&lt;/a&gt;). Building on this foundation, Isaiah Norton, then working at Brigham and Women’s Hospital, contributed additional improvements like a better auto-completion using jedi (see &lt;a href="https://github.com/Slicer/SlicerJupyter/pull/12"&gt;https://github.com/Slicer/SlicerJupyter/pull/12&lt;/a&gt;) as well as integration with Binder. More recently, Jean-Christophe and Sylvain Corlay (QuantStack) met after the Slicer project week while attending SciPy in Austin. Following the creation of a new project called xeus-python (started by Martin Renou at QuantStack), we took the integration of Jupyter and Slicer to the next level by adding support for improved interactive use and MRML data node visualization directly in the notebook.&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="about-the-authors"&gt;About the authors&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Alphabetically ordered&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Sylvain Corlay&lt;/strong&gt; is the founder and CEO of QuantStack, and a core Jupyter developer. He co-authored xeus and xeus-python.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Sylvain Corlay" src="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/images/003-1_DKAhOe_Y4JdGYkgi9jHBSQ.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Sylvain Corlay&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Jean-Christophe Fillion-Robin&lt;/strong&gt; is an open-source enthusiast, original author of the SlicerJupyter extension and a principal engineer at Kitware Inc where he leads the development of “3D Slicer” based commercial applications. J-Christophe also maintains &lt;a href="https://scikit-build.org"&gt;scikit-build&lt;/a&gt;, an improved build system generator for CPython C/C++/Fortran/Cython extensions.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Jean-Christophe Fillion-Robin" src="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/images/004-1_slg9clPxU3DhL4W2pE2kCA.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Jean-Christophe Fillion-Robin&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Mike Grauer&lt;/strong&gt; is a Technical Leader on the data and analytics team at Kitware. He is specialized in building scalable server-side processing frameworks that enable scientific workflows over web platforms.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Mike Grauer" src="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/images/005-1_SuBw-BD8efPla8tfd98RUg.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Mike Grauer&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Andras Lasso&lt;/strong&gt; is an original author of the SlicerJupyter extension, Senior Research Engineer and Associate Director of the Laboratory for Percutaneous Surgery at Queen’s University.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Andras Lasso" src="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/images/006-1_kINpFRIt94iHaxTA90zncQ.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Andras Lasso&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Matt McCormick&lt;/strong&gt; is an open source, medical imaging researcher working at Kitware Inc. Matt is an active, contributing member of scientific open source software efforts such as the Insight Toolkit (ITK) and scientific Python (SciPy) communities, and maintains the Jupyter 3D widget, &lt;a href="https://github.com/InsightSoftwareConsortium/itkwidgets"&gt;itkwidgets&lt;/a&gt;.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Matt McCormick" src="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/images/007-1_Pm17Os2v8Kf_GiZQw1G_ZQ.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Matt McCormick&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Isaiah Norton&lt;/strong&gt; is a Senior Software Developer at TileDB, Inc. with experience in digital pathology and image-guided surgical navigation.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Isaiah Norton" src="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/images/008-1_eR4Y9MX-2lcRsXEKodCJrQ.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Isaiah Norton&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Steve Pieper&lt;/strong&gt; is a Chief Architect and active developer of the 3D Slicer application for well over a decade. He is CEO of Isomics, Inc, where he uses a range of software technologies to perform medical imaging research with leading universities and companies.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Steve Pieper" src="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/images/009-1_aNwZz5TLENXuS2WQRb_N9w.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Steve Pieper&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Martin Renou&lt;/strong&gt; is a scientific software developer at QuantStack. He is the original author of xeus-python, the xeus-based Python kernel, and contributed to the new concurrency model used for the debugger.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Martin Renou" src="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/images/010-1_Cy9QfZytimqXQut2-bdcIA.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Martin Renou&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Mike Sarahan&lt;/strong&gt; is a software engineer at RStudio, PBC working on bringing language ecosystems together. He is passionate about making software work for data scientists in ways that are easy to maintain and improve.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Mike Sarahan" src="https://blog.jupyter.org/posts/2020/slicerjupyter-a-3d-slicer-kernel-for-interactive/images/011-1_YKNdPIBH39iFBIL9nD_kfg.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Mike Sarahan&lt;/figcaption&gt;
&lt;/figure&gt;
</content><category term="kernels"/><category term="science"/><category term="visualization"/><category term="xeus"/></entry><entry><title>A Jupyter kernel for SQLite</title><link href="https://blog.jupyter.org/posts/2020/a-jupyter-kernel-for-sqlite/" rel="alternate"/><published>2020-06-11T08:42:00+00:00</published><updated>2020-12-30T15:29:00+00:00</updated><author><name>Mariana Meireles</name></author><id>tag:blog.jupyter.org,2020-06-11:/posts/2020/a-jupyter-kernel-for-sqlite/</id><summary type="html">&lt;p&gt;While it is well known in the Python scientific computing community, Jupyter is in fact a language-agnostic development environment. High-quality language kernels exist for the main languages of data sciences, such as Python, C++, R or Julia.&lt;/p&gt;</summary><content type="html">&lt;p&gt;While it is well known in the Python scientific computing community, Jupyter is in fact a language-agnostic development environment. High-quality language kernels exist for the main languages of data sciences, such as &lt;a href="https://github.com/jupyter-xeus/xeus-python"&gt;Python&lt;/a&gt;, &lt;a href="https://github.com/jupyter-xeus/xeus-cling"&gt;C++&lt;/a&gt;, &lt;a href="https://github.com/JuniperKernel/JuniperKernel"&gt;R&lt;/a&gt; or &lt;a href="https://github.com/JuliaLang/IJulia.jl"&gt;Julia&lt;/a&gt;.&lt;br&gt;
But another important tool for data science is the SQL family of programming languages. Today, we announce the release of a Jupyter kernel for SQLite.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2020/a-jupyter-kernel-for-sqlite/images/001-1_pzPTGCJVgIO10N7OwOGWKw.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;This new kernel allows the user to use the complete SQLite syntax as well as some extra operations such as opening or closing a database file, or visualizing the data in different ways using Jupyter magics.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="HTML and Text table visualizations for different Jupyter interfaces" src="https://blog.jupyter.org/posts/2020/a-jupyter-kernel-for-sqlite/images/002-1_Pj5UkLChFO3BIMx7NIDRdA.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;HTML and Text table visualizations for different Jupyter interfaces&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;To make the task of implementing a new Kernel for Jupyter easier, we make use of &lt;a href="https://github.com/jupyter-xeus/xeus"&gt;&lt;strong&gt;Xeus&lt;/strong&gt;&lt;/a&gt;, a library providing a solid implementation of the Jupyter kernel protocol, so that we can focus on implementing the language-specific parts of the kernel.&lt;/p&gt;
&lt;p&gt;As a connection between SQLite’s native C implementation and C++ we’re using SRombauts’ library &lt;a href="https://github.com/SRombauts/SQLiteCpp"&gt;&lt;strong&gt;SQLiteCpp&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="current-state"&gt;Current state&lt;/h2&gt;
&lt;p&gt;xeus-SQLite is still under active development but it offers a fully functional SQLite interface and magics to perform higher-level operations that are outside of the scope of the SQL syntax, such as creating, opening, or closing SQLite databases. Some of the things you can do with xeus-SQLite are creating a new database, loading it, backing it up or deleting it. You can also check if a table exists, set and reset keys of a database and get information about it. You can find more about the use of these methods in SQLite’s &lt;a href="https://xeus-sqlite.readthedocs.io/en/latest/"&gt;documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;xeus-SQLite provides rich HTML display of tables in the Jupyter Notebook and Jupyter Lab. For the Jupyter Console we make use of the &lt;a href="https://github.com/p-ranav/tabulate"&gt;&lt;strong&gt;tabulate&lt;/strong&gt;&lt;/a&gt; library for textual display.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Different commands being executed on xeus-SQLite" src="https://blog.jupyter.org/posts/2020/a-jupyter-kernel-for-sqlite/images/003-1_BIDimBvS_g8QH5fuHS_QRQ.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Different commands being executed on xeus-SQLite&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="the-future"&gt;The future&lt;/h2&gt;
&lt;p&gt;For the future of xeus-SQLite we want to create an intuitive form of visualizing data: creating plots, graphs, charts, maps and much more from your SQLite query results, all in the same notebook. Currently we’re exploring the use of &lt;a href="https://vega.github.io/vega/"&gt;&lt;strong&gt;Vega&lt;/strong&gt;&lt;/a&gt; in xeus-SQLite, a declarative language for creating interactive visualization designs and can do bar plots using jupyter magics:&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="SQLite query result with bar and table outputs for same query" src="https://blog.jupyter.org/posts/2020/a-jupyter-kernel-for-sqlite/images/004-1_eWZyoVvu5c_k_Yerv1eT-A.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;SQLite query result with bar and table outputs for same query&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;This feature is still in very early stages and being developed in this &lt;a href="https://github.com/jupyter-xeus/xeus-sqlite/tree/vega-visualization"&gt;branch&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We also plan on producing a static build of xeus-SQLite bundling xeus and the SQLite library into a single executable that can be easily distributed.&lt;/p&gt;
&lt;h2 id="try-it-online"&gt;Try it online!&lt;/h2&gt;
&lt;p&gt;You can try the stable version without the need of installing anything on your computer just by clicking on the image below:&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;a href="https://mybinder.org/v2/gh/jupyter-xeus/xeus-sqlite/stable"&gt;&lt;img src="https://blog.jupyter.org/posts/2020/a-jupyter-kernel-for-sqlite/images/005-1_wiJsOB9OWiAGwuaoycfc0w.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This won’t grant you access to the experimental branch where we’re testing, if you’re interested in trying it please check the &lt;a href="https://github.com/jupyter-xeus/xeus-sqlite#installation"&gt;installation&lt;/a&gt; guide and make sure you’re in the right &lt;a href="https://github.com/jupyter-xeus/xeus-sqlite/tree/vega-visualization"&gt;branch&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="installation"&gt;Installation&lt;/h2&gt;
&lt;p&gt;Note that you first need to have Jupyter installed on your computer. You can install &lt;code&gt;xeus-sqlite&lt;/code&gt; using mamba:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;mamba install xeus-sqlite -c conda-forge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or conda:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;conda install xeus-sqlite -c conda-forge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="about-the-author"&gt;About the author&lt;/h2&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2020/a-jupyter-kernel-for-sqlite/images/006-1_S-w69baox7Q1D997a5yKNw.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;My name is &lt;a href="https://twitter.com/mari_meir"&gt;Mariana Meireles&lt;/a&gt; and I’m a software developer working for &lt;a href="http://quantstack.net/"&gt;QuantStack&lt;/a&gt;. I care deeply about the impacts that technology has in the world and try my best to be the change I want to see by contributing to open source projects that stand upon libre and diverse standards.&lt;/p&gt;
&lt;p&gt;Prior to QuantStack I worked as a developer on the PySide team at the Qt Company and as a web performance developer at Mozilla.&lt;/p&gt;
</content><category term="kernels"/><category term="xeus"/></entry><entry><title>A visual debugger for Jupyter</title><link href="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/" rel="alternate"/><published>2020-03-25T15:53:00+00:00</published><updated>2020-03-26T09:12:00+00:00</updated><author><name>Project Jupyter</name></author><id>tag:blog.jupyter.org,2020-03-25:/posts/2020/a-visual-debugger-for-jupyter/</id><summary type="html">&lt;p&gt;Most of the progress made in software projects comes from incrementalism. The ability to quickly see the outcome of an execution and iterate has been one of the main reasons for the success of Jupyter, especially in scientific exploratory workflows.&lt;/p&gt;</summary><content type="html">&lt;p&gt;Most of the progress made in software projects comes from &lt;em&gt;incrementalism&lt;/em&gt;. The ability to quickly see the outcome of an execution and iterate has been one of the main reasons for the success of Jupyter, especially in scientific exploratory workflows.&lt;/p&gt;
&lt;p&gt;Jupyter users like to &lt;em&gt;experiment&lt;/em&gt; in the notebook, and to use the notebook as an interactive communication tool. However, for more classical software development tasks such as the refactoring of a large codebase, they often switch to general-purpose IDEs.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="The JupyterLab environment." src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/001-1_u8y-ggU2O513KjXdGbdEuQ.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The JupyterLab environment.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The Jupyter project has made strides in the past few years towards filling that gap, notably with the &lt;strong&gt;JupyterLab&lt;/strong&gt; project, which enables a richer UI including a file browser, text editors, consoles, notebooks, and a rich layout system.&lt;/p&gt;
&lt;p&gt;However, a missing piece (which has remained one of the main reasons for users to switch to a different tool) is a &lt;strong&gt;visual debugger&lt;/strong&gt;. This feature has long been requested by users, especially those accustomed to general-purpose development environments.&lt;/p&gt;
&lt;h2 id="a-debugger-for-jupyter"&gt;A debugger for Jupyter&lt;/h2&gt;
&lt;p&gt;Today, after several months of development, we are glad to announce the first public release of the Jupyter visual debugger!&lt;/p&gt;
&lt;p&gt;This is just the first release, but we can already set breakpoints in notebook cells and source files, inspect variables, navigate the call stack and more.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Screencast of the JupyterLab visual debugger in action" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/002-1_NP0bYBdrhwgpJpKDhPLWrQ.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Screencast of the JupyterLab visual debugger in action&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="try-the-debugger-on-binder"&gt;Try the debugger on binder&lt;/h2&gt;
&lt;p&gt;You can also try the debugger online with binder. Just click on the binder link:&lt;/p&gt;
&lt;figure&gt;
&lt;a href="https://mybinder.org/v2/gh/jupyterlab/debugger/stable?urlpath=/lab/tree/examples/index.ipynb"&gt;&lt;img alt="Click on the binder link to launch the demo" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/003-1_NbZ_56IL0J-q0V32qgiq3A.webp" loading="lazy" data-body-image=""&gt;&lt;/a&gt;
&lt;figcaption&gt;Click on the binder link to launch the demo&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="installation"&gt;Installation&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The debugger &lt;em&gt;&lt;strong&gt;front-end&lt;/strong&gt;&lt;/em&gt; can be installed as a JupyterLab extension.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;jupyter&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;labextension&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;@jupyterlab&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;debugger&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;The debugger front-end will be included in JupyterLab by default in a future release.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In the &lt;em&gt;&lt;strong&gt;back-end&lt;/strong&gt;&lt;/em&gt;, a kernel implementing the &lt;strong&gt;Jupyter Debug Protocol&lt;/strong&gt; (which will be detailed in the next section) is required. The only kernel implementing this protocol, for now, is &lt;code&gt;xeus-python&lt;/code&gt; a new Jupyter kernel for the Python programming language. (Support for the debugger protocol in ipykernel is also on the roadmap).&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;conda install xeus-python -c conda-forge
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Once xeus-python and the debugger extension are installed, you should be all set to use the Jupyter visual debugger!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Depending on the platform, PyPI wheels are available for xeus-python, but they are still &lt;em&gt;&lt;strong&gt;experimental&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id="the-jupyter-debug-protocol"&gt;The Jupyter Debug Protocol&lt;/h2&gt;
&lt;h3 id="new-message-types-for-the-control-and-iopub-channels"&gt;New message types for the Control and IOPub channels&lt;/h3&gt;
&lt;p&gt;Jupyter kernels (the part of the infrastructure that executes the user’s code) communicate with the rest of the infrastructure with a &lt;a href="https://jupyter-client.readthedocs.io/en/stable/messaging.html"&gt;well-specified inter-process communication protocol&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Several communication channels exist, such as&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the &lt;strong&gt;Shell&lt;/strong&gt; channel, which is a request/reply channel for e.g. execution requests&lt;/li&gt;
&lt;li&gt;the &lt;strong&gt;IOPub&lt;/strong&gt; channel, which is a one-directional communication channel from the kernel to the client, and is used e.g. to forward the content of the standard output streams (stdout and stderr).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;strong&gt;Control&lt;/strong&gt; channel is similar to Shell but operates on a separate socket so that &lt;em&gt;&lt;strong&gt;messages are not queued behind execution requests&lt;/strong&gt;&lt;/em&gt;, and have a higher priority. Control was already used for Interrupt and Shutdown requests, and we decided to use the same channel for the commands sent to the debugger.&lt;/p&gt;
&lt;p&gt;Two message types were added to the protocol:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the &lt;code&gt;debug_[request/reply]&lt;/code&gt; to request specific actions to be performed by the debugger such as adding a breakpoint or stepping into a code, which is sent to the &lt;strong&gt;Control&lt;/strong&gt; channel.&lt;/li&gt;
&lt;li&gt;the &lt;code&gt;debug_event&lt;/code&gt; uni-directional message used by debugging kernels to send debugging events to the front-end. Debug events are sent over the IOPub channel.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="extending-the-debug-adapter-protocol"&gt;Extending the Debug Adapter Protocol&lt;/h3&gt;
&lt;p&gt;A key principle to the Jupyter design is the &lt;strong&gt;agnosticism to the programming language&lt;/strong&gt;. It is important for the Jupyter debug protocol to be adaptable to other kernel implementations.&lt;/p&gt;
&lt;p&gt;A popular standard for debugging is Microsoft’s “&lt;strong&gt;Debug Adapter Protocol&lt;/strong&gt;” (DAP) which is a JSON-based protocol underlying the debugger of Visual Studio Code and for which there already exist multiple language back-ends.&lt;/p&gt;
&lt;p&gt;It was therefore natural for us to use the DAP messages over the &lt;code&gt;debug_[request/reply]&lt;/code&gt; and &lt;code&gt;debug_event&lt;/code&gt; messages that we just added.&lt;/p&gt;
&lt;p&gt;However, it was not quite &lt;em&gt;sufficient&lt;/em&gt; in the case of Jupyter. Indeed&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In order to support page reloading, or a client connecting at a later stage, Jupyter kernels must store the state of the debugger (breakpoints, whether the debugger is currently stopped). The front-end can request that state over with a &lt;code&gt;debug_request&lt;/code&gt; message.&lt;/li&gt;
&lt;li&gt;In order to support the debugging of notebook cells and of Jupyter consoles, which are not based on source files, we also needed messages to submit code to the debugger to which breakpoints can be added.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Besides these two differences, the content of the debug requests and replies corresponds to the debug adapter protocol.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;All these extensions to the Jupyter kernel protocol have been proposed for inclusion in the official specification. The JEP (Jupyter Enhancement Proposal) can be found &lt;a href="https://github.com/jupyter/enhancement-proposals/pull/47"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="xeus-python-the-first-jupyter-kernel-to-support-debugging"&gt;Xeus-python, the first Jupyter Kernel to support debugging&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://github.com/QuantStack/xeus"&gt;Xeus&lt;/a&gt; is a C++ implementation of the Jupyter kernel protocol. It is not a kernel by itself but a library that helps kernel authoring. &lt;a href="https://github.com/QuantStack/xeus"&gt;Xeus&lt;/a&gt; is useful when developing a kernel for a language that has a C or a C++API (like Python, Lua, or SQL). It takes the cumbersome task of implementing the &lt;a href="https://jupyter-client.readthedocs.io/en/stable/messaging.html"&gt;Jupyter messaging protocol&lt;/a&gt; for the kernel author to focus on the core interpreter tasks: executing code, inspecting, etc.&lt;/p&gt;
&lt;p&gt;Several kernels have been developed with xeus, including the popular &lt;a href="https://github.com/jupyter-xeus/xeus-cling"&gt;xeus-cling&lt;/a&gt; kernel for the C++ programming language, based on the cling C++ interpreter from CERN. The &lt;a href="https://github.com/jupyter-xeus/xeus-python.git"&gt;xeus-python&lt;/a&gt; kernel is an alternative Python kernel to ipykernel, based on xeus. The first release of the xeus-python kernel was announced on this blog earlier this year: &lt;a href="https://blog.jupyter.org/posts/2019/a-new-python-kernel-for-jupyter/"&gt;A new Python kernel for Jupyter&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Xeus-python was an appropriate choice for this first implementation of the debugging protocol because&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;it has a &lt;strong&gt;pluggable concurrency model&lt;/strong&gt;, which allowed running the processing of the Control channel in a different thread.&lt;/li&gt;
&lt;li&gt;it has a &lt;strong&gt;lighter-weight codebase&lt;/strong&gt; which made it a convenient sandbox to iterate upon. Implementing the first version of the protocol in ipykernel would have required more significant refactoring and consensus building at an early stage.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="the-roadmap-of-xeus-python"&gt;The roadmap of Xeus-python&lt;/h3&gt;
&lt;p&gt;The short-term roadmap for xeus-python includes&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;adding support for IPython magics in xeus-python, which is the main missing feature with respect to ipykernel.&lt;/li&gt;
&lt;li&gt;improving the PyPI wheels of xeus-python.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="what-about-other-kernels"&gt;What about other kernels?&lt;/h3&gt;
&lt;p&gt;The work in the front-end is valid for any kernel implementing the extended kernel protocol.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;We will be working in 2020 to enable debugging with as many kernels as possible.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This will soon be the case for other xeus-based kernels which share a large part of the implementation with xeus-python, such as xeus-cling.&lt;/p&gt;
&lt;h2 id="diving-into-the-debugger-front-end-architecture"&gt;Diving into the debugger front-end architecture&lt;/h2&gt;
&lt;p&gt;The &lt;a href="https://github.com/jupyterlab/debugger"&gt;debugger extension for JupyterLab&lt;/a&gt; provides what users would typically expect from an IDE:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a sidebar with a variable explorer, a list of breakpoints, a source preview and the possibility to navigate the call stack&lt;/li&gt;
&lt;li&gt;the ability to set breakpoints directly next to the code, namely in code cells and code consoles&lt;/li&gt;
&lt;li&gt;visual markers to indicate where the current execution has stopped&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When working with Jupyter notebooks, the state of the execution is kept in the kernel. But a cell can be executed and then deleted from the notebook. What should happen when a user wants to step in deleted code?&lt;/p&gt;
&lt;p&gt;The extension supports that particular use case and enables retrieving a read-only view of the previously executed cell.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Stepping into a deleted cell" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/004-0_gsIleEb7Q-sq05f0.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Stepping into a deleted cell&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Consoles and files also have support for debugging.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Debugging code consoles in JupyterLab" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/005-0_G5-dLqkhH5CEvQQv.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Debugging code consoles in JupyterLab&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;figure&gt;
&lt;img alt="Debugging files in JupyterLab" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/006-0_ZejsDIpKOEPDgoTs.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Debugging files in JupyterLab&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Debugging can be enabled on a notebook level, which lets users debug a notebook and work on a different one at the same time.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Debugging multiple notebooks simultaneously" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/007-0_EtApkSznZEY-GJhA.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Debugging multiple notebooks simultaneously&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Variables can be inspected using a tree viewer and a table viewer:&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="The variable explorer" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/008-0_9pVDg58cTz5Yezw8.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The variable explorer&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The debugger extension for JupyterLab has been designed to work with any kernel that supports debugging.&lt;/p&gt;
&lt;p&gt;By relying on the Debug Adapter Protocol, the debugger extension abstracts away language-specific features and provides a consistent debugging interface to the user.&lt;/p&gt;
&lt;p&gt;The following diagram shows how the debug messages flow between the user, the JupyterLab extension and the kernel during a debugging session.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Using the Debug Adapter Protocol in the debugger extension (source)" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/009-0_fwLQQWxKtGUiMpq1.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Using the Debug Adapter Protocol in the debugger extension (&lt;a href="https://github.com/jupyterlab/debugger/issues/64"&gt;source&lt;/a&gt;)&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="future-developments"&gt;Future developments&lt;/h2&gt;
&lt;p&gt;In 2020, we plan on making major improvements to the debugger experience:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Support for rich mime type rendering in the variable explorer.&lt;/li&gt;
&lt;li&gt;Support for conditional breakpoints in the UI.&lt;/li&gt;
&lt;li&gt;General improvements of the debugger user experience.&lt;/li&gt;
&lt;li&gt;Enable the debugging of &lt;a href="https://github.com/voila-dashboards/voila/"&gt;Voilà dashboards&lt;/a&gt;, from the JupyterLab Voilà preview extension.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="acknowledgements"&gt;Acknowledgements&lt;/h2&gt;
&lt;p&gt;The JupyterLab debugger is the result of the collaboration and coordination of developers from several institutions, including QuantStack, Two Sigma, and Bloomberg.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The work on both the front-end and the back-end at &lt;a href="https://twitter.com/QuantStack"&gt;&lt;strong&gt;QuantStack&lt;/strong&gt;&lt;/a&gt; by &lt;a href="https://twitter.com/jtpio"&gt;&lt;strong&gt;Jeremy Tuloup&lt;/strong&gt;&lt;/a&gt;, &lt;a href="https://twitter.com/johanmabille"&gt;&lt;strong&gt;Johan Mabille&lt;/strong&gt;&lt;/a&gt;, &lt;a href="https://twitter.com/martinRenou"&gt;&lt;strong&gt;Martin Renou&lt;/strong&gt;&lt;/a&gt;, and &lt;a href="https://twitter.com/SylvainCorlay"&gt;&lt;strong&gt;Sylvain Corlay&lt;/strong&gt;&lt;/a&gt;, was funded by &lt;a href="https://twitter.com/techatbloomberg"&gt;&lt;strong&gt;Bloomberg&lt;/strong&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The work on the Jupyter debugger by &lt;strong&gt;Borys Palka&lt;/strong&gt; and &lt;a href="https://twitter.com/micronova"&gt;&lt;strong&gt;Afshin Darian&lt;/strong&gt;&lt;/a&gt; was made possible by &lt;a href="https://twitter.com/twosigma"&gt;&lt;strong&gt;Two Sigma&lt;/strong&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="about-the-developers"&gt;About the developers&lt;/h2&gt;
&lt;figure&gt;
&lt;img alt="Jeremy Tuloup" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/010-1_4RE97odgcRtRruh0najsVg.jpg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Jeremy Tuloup&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Jeremy Tuloup&lt;/strong&gt; is a Scientific Software developer at QuantStack. He authored a large part of the front-end of the JupyterLab debugger.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Borys Palka" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/011-1_IJw8VB7Sq8v4FwUgP7DY_Q.jpeg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Borys Palka&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Borys Palka&lt;/strong&gt; is a software developer at Codete. He authored a large part of the front-end of the JupyterLab debugger.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Johan Mabille" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/012-1_y5KkUTTgNArZGajQWW38EA.jpeg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Johan Mabille&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Johan Mabille&lt;/strong&gt; is a scientific software developer at QuantStack. Johan is a co-author of xeus, and developed the debugger extension to xeus-python. He also authored a large part of the debugger front-end.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Martin Renou" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/013-1_GafIA37eUPz6XQDTKS6D8A.jpeg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Martin Renou&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Martin Renou&lt;/strong&gt; is a scientific software developer at QuantStack. He is the original author of xeus-python, the xeus-based Python kernel, and contributed to the new concurrency model used for the debugger.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Afshin Darian" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/014-1_FEspm1Hcty29Jxwpb-cHXw.jpeg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Afshin Darian&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Afshin Darian&lt;/strong&gt; is a software developer at Two Sigma, and one of the authors of JupyterLab.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Sylvain Corlay" src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/015-1_aSY0NNigA16fvOHVZCOaeQ.jpeg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Sylvain Corlay&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Sylvain Corlay&lt;/strong&gt; is the founder and CEO of QuantStack, and a core Jupyter developer. He co-authored xeus and xeus-python.&lt;/p&gt;
&lt;p class="standalone-image"&gt;&lt;img src="https://blog.jupyter.org/posts/2020/a-visual-debugger-for-jupyter/images/016-1_Trh8fKqP0c_4Vvnzmu5SvA.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
</content><category term="debugging"/><category term="JupyterLab"/><category term="kernels"/><category term="xeus"/></entry><entry><title>Xeus is now a Jupyter subproject</title><link href="https://blog.jupyter.org/posts/2020/xeus-is-now-a-jupyter-subproject/" rel="alternate"/><published>2020-02-04T12:08:00+00:00</published><updated>2020-02-08T13:30:00+00:00</updated><author><name>Johan Mabille</name></author><id>tag:blog.jupyter.org,2020-02-04:/posts/2020/xeus-is-now-a-jupyter-subproject/</id><summary type="html">&lt;p&gt;The Xeus project has been incorporated as a Jupyter subproject.&lt;/p&gt;
</summary><content type="html">&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;It is a great pleasure to announce that the Xeus project has been incorporated as a Jupyter subproject. Xeus will now be subject to the &lt;a href="https://github.com/jupyter/governance/blob/master/governance.md"&gt;Jupyter governance&lt;/a&gt; and &lt;a href="https://github.com/jupyter/governance/blob/master/conduct/code_of_conduct.md"&gt;code of conduct&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;For reference, the Jupyter Enhancement Proposal (JEP) for the Xeus incorporation is available &lt;a href="https://github.com/jupyter/enhancement-proposals/pull/44"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="what-is-xeus"&gt;What is Xeus?&lt;/h2&gt;
&lt;p&gt;The &lt;a href="https://github.com/jupyter-xeus/xeus/"&gt;Xeus&lt;/a&gt; project is a C++ implementation of the Jupyter kernel protocol. Xeus is not a kernel, but a library meant to facilitate the authoring of kernels.&lt;br&gt;
Several Jupyter kernels have been created with Xeus:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-cling"&gt;xeus-cling&lt;/a&gt;, a kernel for the C++ programming language, based on the Cling C++ interpreter. The &lt;a href="https://github.com/root-project/cling"&gt;cling&lt;/a&gt; project comes from CERN and is at the foundation of the &lt;a href="https://github.com/root-project/root.git"&gt;ROOT&lt;/a&gt; project.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="The xeus-cling Jupyter kernel for the C++ programming language." src="https://blog.jupyter.org/posts/2020/xeus-is-now-a-jupyter-subproject/images/001-0_SSdFFWmES-6AW8Yo.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The xeus-cling Jupyter kernel for the C++ programming language.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-python"&gt;xeus-python&lt;/a&gt;, a kernel for the Python programming language, embedding the Python interpreter.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="The xeus-python Jupyter kernel for the Python programming language" src="https://blog.jupyter.org/posts/2020/xeus-is-now-a-jupyter-subproject/images/002-0_Mh5cOdG7YWJxrFSw.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The xeus-python Jupyter kernel for the Python programming language&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://github.com/jupyter-xeus/xeus-calc"&gt;xeus-calc&lt;/a&gt;, a calculator kernel, meant as an educational example on how to make Jupyter kernels with Xeus.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Beyond these three kernels built on top of Xeus by the Xeus maintainers, third-parties have developed other Jupyter kernels with Xeus:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/JuniperKernel/JuniperKernel"&gt;JuniperKernel&lt;/a&gt;, a kernel for the R programming language by Spencer Aiello.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/atomex-me/xeus-fift"&gt;xeus-fift&lt;/a&gt;, a kernel for the fift programming language by Michael Zaikin. The fift programming language was developed by Telegram to create TON blockchain contracts.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Slicer/SlicerJupyter"&gt;SlicerJupyter&lt;/a&gt;, a kernel for the Python programming language by Kitware which integrates into the Qt event loop of the Kitware “Slicer” project.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, the xeus-python kernel includes a first implementation of the Jupyter debugger protocol used by the &lt;a href="https://github.com/jupyterlab/debugger"&gt;Jupyter debugger&lt;/a&gt; project. xeus-python enables the &lt;a href="https://microsoft.github.io/debug-adapter-protocol/"&gt;Debug Adapter Protocol&lt;/a&gt; over the Control channel through new debug request/reply and debug event messages.&lt;/p&gt;
&lt;h2 id="why-moving-xeus-under-the-jupyter-governance"&gt;Why moving Xeus under the Jupyter governance?&lt;/h2&gt;
&lt;p&gt;While Xeus started as a side project for &lt;a href="https://twitter.com/QuantStack"&gt;QuantStack&lt;/a&gt; engineers, the project now has several stakeholders who depend on it. We think that moving the project to an open governance organization may be a better way to reflect this situation.&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="acknowledgements"&gt;Acknowledgements&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Xeus was started by the team of open-source developers at &lt;a href="https://twitter.com/QuantStack"&gt;QuantStack&lt;/a&gt; as a separate project, but with the full intent to incorporate it into Jupyter. The initial project development at QuantStack was funded by &lt;a href="https://twitter.com/techatbloomberg"&gt;Bloomberg&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Now, Xeus contributors work in many institutions, including &lt;a href="https://www.universite-paris-saclay.fr/"&gt;Université Paris-Saclay&lt;/a&gt; and &lt;a href="https://www.polytechnique.edu/"&gt;École Polytechnique&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="about-the-author"&gt;About the Author&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://twitter.com/johanmabille?lang=en"&gt;Johan Mabille&lt;/a&gt; is a Scientific Software Developer at &lt;a href="https://github.com/QuantStack/"&gt;QuantStack&lt;/a&gt;, specializing in high-performance computing in C++. He holds master’s degree in computer science from Centrale-Supelec.&lt;/p&gt;
&lt;p&gt;As an open source developer, Johan coauthored &lt;a href="https://quantstack.net/xtensor.html"&gt;&lt;strong&gt;xtensor&lt;/strong&gt;&lt;/a&gt;, &lt;a href="https://quantstack.net/xeus.html"&gt;&lt;strong&gt;xeus&lt;/strong&gt;&lt;/a&gt;, and &lt;a href="https://quantstack.net/xsimd.html"&gt;&lt;strong&gt;xsimd&lt;/strong&gt;&lt;/a&gt;. He also made major contributions to the JupyterLab debugger project and bqplot.&lt;/p&gt;
</content><category term="C++"/><category term="governance"/><category term="kernels"/><category term="xeus"/></entry><entry><title>Building a Calculator Jupyter Kernel</title><link href="https://blog.jupyter.org/posts/2019/building-a-calculator-jupyter-kernel/" rel="alternate"/><published>2019-07-16T08:36:00+00:00</published><updated>2019-07-16T09:14:00+00:00</updated><author><name>Vasavan Thiru</name></author><id>tag:blog.jupyter.org,2019-07-16:/posts/2019/building-a-calculator-jupyter-kernel/</id><summary type="html">&lt;p&gt;A step-by-step guide for authoring language kernels with Xeus&lt;/p&gt;
</summary><content type="html">&lt;figure&gt;
&lt;img alt="An early device for interactive computing" src="https://blog.jupyter.org/posts/2019/building-a-calculator-jupyter-kernel/images/001-0_h6rfGRuTgOkwonN9.jpg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;An early device for interactive computing&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;In order to provide a language-agnostic scientific development environment, the &lt;strong&gt;Jupyter project&lt;/strong&gt; is built upon a &lt;a href="https://jupyter-client.readthedocs.io/en/stable/messaging.html"&gt;&lt;em&gt;well-specified protocol&lt;/em&gt;&lt;/a&gt; to communicate with the &lt;em&gt;Kernel&lt;/em&gt;, the part of the infrastructure responsible for executing the code.&lt;/p&gt;
&lt;p&gt;For a programming language to leverage the potential of the Jupyter ecosystem, such as &lt;em&gt;JupyterHub&lt;/em&gt;, &lt;em&gt;JupyterLab&lt;/em&gt;, and &lt;em&gt;interactive widgets&lt;/em&gt;, all that is needed is a &lt;em&gt;Kernel&lt;/em&gt; to be created for that language that is, an executable implementing the specified inter-process communication. Dozens of kernels have already been implemented bringing Jupyter to many programming languages.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;We are completing our engineering degree and interning at QuantStack. We recently attended the &lt;a href="https://blog.jupyter.org/posts/2019/jupyter-community-workshop-building-upon-the-jupyter/"&gt;Jupyter Community Workshop&lt;/a&gt; on the kernel protocol that took place in Paris in late May. In this occasion, we set ourselves to write a new Jupyter kernel.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Today, we are proud to announce the first release of &lt;a href="https://github.com/QuantStack/xeus-calc"&gt;&lt;em&gt;&lt;strong&gt;xeus-calc&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;, a calculator kernel for Jupyter! xeus-calc is meant to serve as a &lt;em&gt;minimal,&lt;/em&gt; &lt;em&gt;self-contained&lt;/em&gt;example of Jupyter kernel. It is built upon the &lt;a href="https://github.com/QuantStack/xeus/"&gt;&lt;em&gt;&lt;strong&gt;xeus&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; project, a modern C++ implementation of the protocol. This article is a step-by-step description on how the kernel was implemented.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;You may find this post especially useful if you are creating a new programming language and you want it to work in Jupyter from the start.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="xeus"&gt;Xeus&lt;/h2&gt;
&lt;p&gt;Implementing the &lt;a href="https://jupyter-client.readthedocs.io/en/stable/messaging.html"&gt;&lt;strong&gt;Jupyter kernel protocol&lt;/strong&gt;&lt;/a&gt; from scratch may be a tedious and difficult task. One needs to deal with ZMQ sockets and complex concurrency issues, rely on third-party libraries for cryptographically signing messages or parsing JSON efficiently. This is where the &lt;a href="https://github.com/QuantStack/xeus/"&gt;&lt;em&gt;&lt;strong&gt;xeus&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; project comes into play: it takes all of that burden so that developers can focus on the parts that are specific to their use case.&lt;/p&gt;
&lt;p&gt;In the end, the kernel author only needs to implement a small number of virtual functions inherited from the &lt;code&gt;xinterpreter&lt;/code&gt; class.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;xeus/xinterpreter.hpp&amp;quot;&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;nlohmann/json.hpp&amp;quot;&lt;/span&gt;

&lt;span class="nx"&gt;using&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;xeus&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nx"&gt;xinterpreter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;namespace&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;nl&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;nlohmann&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;custom&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;custom_interpreter&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;public&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;xinterpreter&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;public&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nx"&gt;custom_interpreter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="kd"&gt;virtual&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="nx"&gt;custom_interpreter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="w"&gt;     &lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nx"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;configure&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;override&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nx"&gt;nl&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;execute_request_impl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;execution_counter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                      &lt;/span&gt;&lt;span class="nx"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;
&lt;span class="w"&gt;                                      &lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;silent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;
&lt;span class="w"&gt;                                      &lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;store_history&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                      &lt;/span&gt;&lt;span class="nx"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;nl&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nx"&gt;node_type&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;user_expressions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                      &lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;allow_stdin&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;override&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nx"&gt;nl&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;complete_request_impl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                       &lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;cursor_pos&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;override&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nx"&gt;nl&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;inspect_request_impl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                      &lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;cursor_pos&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                      &lt;/span&gt;&lt;span class="nx"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;detail_level&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;override&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nx"&gt;nl&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;is_complete_request_impl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;std&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;override&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="nx"&gt;nl&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;kernel_info_request_impl&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;override&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Typically, a kernel author will make use of the C or C++ API of the target programming language and embed the interpreter into the application.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This differs from the &lt;em&gt;wrapper kernel&lt;/em&gt; approach documented in the ipykernel package where kernel authors make use of the kernel protocol implementation of ipykernel, typically spawning a separate process for the interpreter and capturing its standard output.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Jupyter kernels based on xeus include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/QuantStack/xeus-cling"&gt;&lt;em&gt;&lt;strong&gt;xeus-cling&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;: a C++ kernel built upon the cling C++ interpreter from CERN&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/QuantStack/xeus-python"&gt;&lt;strong&gt;xeus-python&lt;/strong&gt;&lt;/a&gt;: a new Python kernel for Jupyter.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/JuniperKernel/JuniperKernel"&gt;&lt;em&gt;&lt;strong&gt;JuniperKernel&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;: a new R kernel for Jupyter based on xeus.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this post, instead of calling into the API of an external interpreter, we implement the internal logic of the calculator in the kernel itself.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Exposing the xeus calculator to Jupyter" src="https://blog.jupyter.org/posts/2019/building-a-calculator-jupyter-kernel/images/002-0_Q2jOwO75XQvNuqaR.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Exposing the xeus calculator to Jupyter&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="a-calculator-project"&gt;A calculator project&lt;/h2&gt;
&lt;p&gt;First, to implement your own Jupyter kernel, you should install Xeus. You can either download it with conda, or install it from sources as detailed in the &lt;a href="https://github.com/QuantStack/xeus"&gt;&lt;em&gt;&lt;strong&gt;readme&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now that the installation is out of the way, let’s focus on the implementation itself.&lt;/p&gt;
&lt;p&gt;Recall that the main class for the calculator kernel must inherit from the &lt;code&gt;xinterpreter&lt;/code&gt; class so that Xeus can correctly route the messages received from the front-end.&lt;/p&gt;
&lt;p&gt;This class defines the behavior of the kernel for each message type that is received from the front-end.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;kernel_info_request_impl&lt;/code&gt;: returns the information about the kernel, such as the name, the version or even a “banner”, that is a message that is prompted to console clients upon launch. This is a good place to be creative with ASCII art.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;complete_request_impl&lt;/code&gt;: checks if the code can be completed, by that we mean semantic completion, and makes a suggestion accordingly. This way the user can receive a proposition for an adequate completion to the code he is currently writing. We did not use it during our implementation as you will see later, it is safe to return a JSON with a status value only, if you do not want to handle completion.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;is_complete_request_impl&lt;/code&gt;: whether the submitted code is complete and ready for evaluation. For example, if brackets are not all closed, there is probably more to be typed. This message is not used by the notebook front-end but is required for the console, which shows a continuation prompt for further input if it is deemed incomplete. It also checks whether the code is valid or not. Since the calculator expects single-line inputs, it is safe to return an empty JSON object. This may be refined in the future.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;inspect_request_impl&lt;/code&gt;: concerns documentation. It inspects the code to show useful information to the user. We did not use it in our case and went with the default implementation (that is to return an empty JSON object).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;execute_request_impl&lt;/code&gt;: the main function. An &lt;code&gt;execute_request&lt;/code&gt; message is sent by the front-end to ask the kernel to execute the code on behalf of the user. In the case of the calculator, this means parsing the mathematical expression, evaluating it and returning the result, as described in the next section.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="implementation-of-the-calculator"&gt;Implementation of the calculator&lt;/h3&gt;
&lt;p&gt;First things first, we need to find a way to parse mathematical expressions. To do so, we turn the user input into &lt;em&gt;&lt;strong&gt;Reverse Polish Notation&lt;/strong&gt;&lt;/em&gt; (or RPN), a name full of meaning for the wisest among our readers (or at least the oldest) who used RPN calculators in high school.&lt;/p&gt;
&lt;p&gt;The RPN, also called &lt;em&gt;&lt;strong&gt;Postfix&lt;/strong&gt;&lt;/em&gt; notation, presents the mathematical expression in a specific way : the operands go first followed by the operator. The main advantage of this notation is how it implicitly displays the precedence of operators.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Reverse Polish Notation illustration" src="https://blog.jupyter.org/posts/2019/building-a-calculator-jupyter-kernel/images/003-0_7eozUxbipal_WV0c.webp" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Reverse Polish Notation illustration&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The main logic of the calculator is provided by two main functions dealing respectively with parsing and evaluating the user expression and a third one for handling spaces in the expression.&lt;/p&gt;
&lt;p&gt;First we have the parsing function (&lt;code&gt;parse_rpn&lt;/code&gt;) transforming the expression into this representation. For this purpose we implement the &lt;a href="https://en.wikipedia.org/wiki/Shunting-yard_algorithm"&gt;&lt;em&gt;&lt;strong&gt;Shunting-yard algorithm&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It is based on the use of a stack data structure to change the order of the elements in the expression, depending on their type : operator, operand or parenthesis.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="Transforming a user expression into RPN" src="https://blog.jupyter.org/posts/2019/building-a-calculator-jupyter-kernel/images/004-0_kJeaW70rAkyeYh5l.jpg" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;Transforming a user expression into RPN&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Now that we have the expression turned into RPN (with spaces delimiting operands and operators) we need to do the computation. For this purpose we have the function &lt;code&gt;compute_rpn&lt;/code&gt;. Its implementation is based on a loop through a stringstream (hence the need for space delimiters) which performs operations in the right order.&lt;/p&gt;
&lt;p&gt;Note that the result is not returned as an &lt;code&gt;execute_reply&lt;/code&gt; message but is sent on a broadcasting channel instead, so that other clients to the kernel can also see it. The function &lt;code&gt;execute_reply_impl&lt;/code&gt; actually returns the status of the execution only, as you may see in the code below.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;nl&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;execute_request_impl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb nb-Type"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;execution_counter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                           &lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                           &lt;/span&gt;&lt;span class="nb nb-Type"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/*&lt;/span&gt;&lt;span class="n"&gt;silent&lt;/span&gt;&lt;span class="o"&gt;*/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                           &lt;/span&gt;&lt;span class="nb nb-Type"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/*&lt;/span&gt;&lt;span class="n"&gt;store_history&lt;/span&gt;&lt;span class="o"&gt;*/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                           &lt;/span&gt;&lt;span class="n"&gt;nl&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/*&lt;/span&gt;&lt;span class="n"&gt;user_exprs&lt;/span&gt;&lt;span class="o"&gt;*/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                           &lt;/span&gt;&lt;span class="nb nb-Type"&gt;bool&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;/*&lt;/span&gt;&lt;span class="n"&gt;allow_stdin&lt;/span&gt;&lt;span class="o"&gt;*/&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;nl&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;pub_data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Result = &amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;auto&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;publish&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;this&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;
&lt;span class="w"&gt;                          &lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;publish_stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;try&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;spaced_code&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;formating_expr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;to_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;compute_rpn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;parse_rpn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;spaced_code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                                       &lt;/span&gt;&lt;span class="n"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="w"&gt;                                             &lt;/span&gt;&lt;span class="n"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;pub_data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;text/plain&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;publish_execution_result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;execution_counter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="w"&gt;                                 &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;move&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pub_data&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="w"&gt;                                 &lt;/span&gt;&lt;span class="n"&gt;nl&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;object&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;nl&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;jresult&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;jresult&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;status&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;ok&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;jresult&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;payload&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;nl&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;jresult&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;user_expressions&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;nl&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;object&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;jresult&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;catch&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;runtime_error&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;nl&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;jresult&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;publish_stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;stderr&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;what&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;jresult&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;status&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;error&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;jresult&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And that’s it for our calculator! It is as simple as that.&lt;/p&gt;
&lt;p&gt;Yet remember that Xeus is a library, not a kernel by itself. We still have to create an executable that gathers the interpreter and the library. This is done in a &lt;code&gt;main&lt;/code&gt; function whose implementation looks like:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nb nb-Type"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb nb-Type"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;argc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;char&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[])&lt;/span&gt;&lt;span class="w"&gt;                       &lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;                           &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Load&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="w"&gt;                           &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;file_name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;argc&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;connection.json&amp;quot;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;&lt;span class="w"&gt;                           &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;xeus&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;xconfiguration&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;xeus&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;load_configuration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;                                                   &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Create&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="w"&gt;                           &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;using&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;interpreter_ptr&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;unique_ptr&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;xeus_calc&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;                           &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;interpreter_ptr&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;make_unique&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;xeus_calc&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;                              &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Create&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ow"&gt;and&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="w"&gt;                           &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;xeus&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;xkernel&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;
&lt;span class="w"&gt;                         &lt;/span&gt;&lt;span class="n"&gt;xeus&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;get_user_name&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;
&lt;span class="w"&gt;                         &lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;move&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;interpreter&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="w"&gt;                           &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;kernel&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;                                                   &lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;First, we need to load the configuration file. To do so, we check if one was passed as an argument, otherwise, we look for the connection.json file.&lt;/p&gt;
&lt;p&gt;Then, we instantiate the interpreter that we previously set up. Finally, we can create the kernel with all that we defined beforehand. The kernel constructor accepts more parameters that allow customizing some predefined behaviors. You can find more details in the &lt;a href="https://xeus.readthedocs.io/en/latest/"&gt;&lt;em&gt;&lt;strong&gt;Xeus documentation&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;. Start the kernel and we are good to go!&lt;/p&gt;
&lt;p&gt;Now that everything is set, we can test out our homemade calculator kernel.&lt;/p&gt;
&lt;p&gt;As you can see in the demonstration below, the code displays step-by-step how the computation is done with RPN. This is done with &lt;code&gt;publish_stream&lt;/code&gt; statements, which is equivalent to &lt;code&gt;std::cout&lt;/code&gt; for the Jupyter notebook, very useful for debugging purposes.&lt;/p&gt;
&lt;figure&gt;
&lt;img alt="The final result, a functional calculator!" src="https://blog.jupyter.org/posts/2019/building-a-calculator-jupyter-kernel/images/005-0_o8XXbdwfzxiC8Nmj.mp4" loading="lazy" data-body-image=""&gt;
&lt;figcaption&gt;The final result, a functional calculator!&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;You should now have all the information you need to implement your own Jupyter kernel. As you noticed, the Xeus library makes this task quite simple. All that you have to do is to inherit from the &lt;code&gt;xinterpreter&lt;/code&gt; virtual class and implement the functions related to the messaging protocol. Nothing more is required.&lt;/p&gt;
&lt;p&gt;This project can be found on &lt;a href="https://github.com/QuantStack/xeus-calc"&gt;&lt;em&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;. Feel free to contribute to the project if you wish to improve it, keeping in mind that xeus-calc should remain lean and simple!&lt;/p&gt;
&lt;p&gt;Note that the current implementation only supports arithmetical operators. However it can be easily extended and we may add functional support in the near future.&lt;/p&gt;
&lt;div class="main-content-end" aria-hidden="true"&gt;&lt;/div&gt;
&lt;h2 id="acknowledgments"&gt;Acknowledgments&lt;/h2&gt;
&lt;p&gt;We would like to thank the whole &lt;a href="https://quantstack.net/the-team.html"&gt;&lt;strong&gt;QuantStack&lt;/strong&gt;&lt;/a&gt; team for their help throughout the process of making this blog post.&lt;/p&gt;
&lt;p&gt;We are also grateful to the organizers of the &lt;a href="https://blog.jupyter.org/posts/2019/jupyter-community-workshop-building-upon-the-jupyter/"&gt;&lt;em&gt;&lt;strong&gt;Jupyter community workshop on kernels&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; as we actually started to endeavor during the event.&lt;/p&gt;
&lt;h2 id="about-the-authors"&gt;About the authors&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Vasavan Thiru&lt;/strong&gt; is completing a master’s degree at &lt;em&gt;Sorbonne Université Pierre &amp;amp; Marie Curie&lt;/em&gt; in applied mathematics for mechanics. He is currently interning as a scientific software developer at QuantStack.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Thibault Lacharme&lt;/strong&gt; is finishing a master’s degree in Quantitative Finance at &lt;em&gt;Université Paris Dauphine&lt;/em&gt;. Thibault is currently on his internship as a scientific software developer at QuantStack.&lt;/p&gt;
</content><category term="C++"/><category term="kernels"/><category term="xeus"/></entry></feed>