<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Jupyter Blog - Anton Akhmerov</title><link href="https://jasongrout.github.io/medium-archive/pelican/" rel="alternate"/><link href="https://jasongrout.github.io/medium-archive/pelican/feeds/author-anton-akhmerov.atom.xml" rel="self"/><id>https://jasongrout.github.io/medium-archive/pelican/</id><updated>2019-05-30T18:22:00+00:00</updated><subtitle>The Project Jupyter blog: news, releases, and community stories, archived from blog.jupyter.org.</subtitle><entry><title>Integrating output in documentation with jupyter-sphinx</title><link href="https://jasongrout.github.io/medium-archive/pelican/posts/2019/integrating-output-in-documentation-with-jupyter-sphinx/" rel="alternate"/><published>2019-05-30T18:22:00+00:00</published><updated>2019-05-30T18:22:00+00:00</updated><author><name>Anton Akhmerov</name></author><id>tag:jasongrout.github.io,2019-05-30:/medium-archive/pelican/posts/2019/integrating-output-in-documentation-with-jupyter-sphinx/</id><summary type="html">&lt;p&gt;The problem&lt;/p&gt;
</summary><content type="html">&lt;p&gt;&lt;img src="https://jasongrout.github.io/medium-archive/pelican/posts/2019/integrating-output-in-documentation-with-jupyter-sphinx/images/001-1_XO_pZXORoGXPS1BX1Kd5Ig.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;h2 id="the-problem"&gt;The problem&lt;/h2&gt;
&lt;p&gt;We love Jupyter notebooks for accommodating a &lt;em&gt;computational narrative&lt;/em&gt; — a combination of explanation, code, and the output of this code.&lt;br&gt;
Unfortunately, some tasks cannot be accomplished well by notebooks.&lt;br&gt;
If you are writing documentation for your software project, chances are that you want to provide navigation across many tutorials and explanation pages.&lt;br&gt;
You will also want to automatically document the API, perhaps also maintain a bibliography, and you certainly will want all the classes and functions from your module to automatically link to their documentation pages.&lt;br&gt;
In short, your best bet is Sphinx.&lt;/p&gt;
&lt;p&gt;Sphinx does not provide a way to build a computational narrative: by itself, it cannot execute any code, nor does it know how to handle the output of that code. This limitation is well known and there are great tools offering a workaround; I’ll list the ones that I know about:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nbsphinx.readthedocs.io"&gt;&lt;code&gt;nbsphinx&lt;/code&gt;&lt;/a&gt; allows incorporating executed notebooks into a documentation website. Unfortunately, markdown used in notebooks is a much more limited markup language than restructured text.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://sphinx-gallery.github.io"&gt;&lt;code&gt;sphinx-gallery&lt;/code&gt;&lt;/a&gt; takes a collection of scripts, executes them, shows the code and the output in the documentation, and even automatically links object names occurring in a script to their documentation. It also parses rst-formatted comments and renders those.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="jupyter-sphinx"&gt;Jupyter-sphinx&lt;/h2&gt;
&lt;p&gt;We have just made an addition to this list, a freshly rewritten &lt;a href="https://jupyter-sphinx.readthedocs.io"&gt;&lt;code&gt;jupyter-sphinx&lt;/code&gt;&lt;/a&gt; extension, that was previously specialized to render Jupyter widgets.&lt;br&gt;
To embed arbitrary output in your documentation using &lt;code&gt;jupyter-sphinx&lt;/code&gt; you only need to use the &lt;code&gt;jupyter-execute&lt;/code&gt; directive:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="p"&gt;..&lt;/span&gt; &lt;span class="ow"&gt;jupyter-execute&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;
&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;  print(&amp;#39;Hello world!&amp;#39;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Under the hood, all such code chunks are converted to cells in a notebook and executed using &lt;code&gt;nbconvert&lt;/code&gt;. We then rely on the Jupyter format and protocol to interpret what to do with the results of executing the code. This means you already know how the output will be shown: we apply exactly the same logic as Jupyter notebook does.&lt;/p&gt;
&lt;p&gt;For example, here we make a plot:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jasongrout.github.io/medium-archive/pelican/posts/2019/integrating-output-in-documentation-with-jupyter-sphinx/images/002-1_rPi05lekdRaC4KuSYd4Zng.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;And here we are rendering some widgets:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://jasongrout.github.io/medium-archive/pelican/posts/2019/integrating-output-in-documentation-with-jupyter-sphinx/images/003-1_KqpHDFn7RehnmftNBwDPiQ.webp" alt="" loading="lazy" data-body-image=""&gt;&lt;/p&gt;
&lt;p&gt;If you want to see &lt;code&gt;jupyter-sphinx&lt;/code&gt; used to make package documentation, check out &lt;a href="https://adaptive.readthedocs.io"&gt;&lt;code&gt;adaptive&lt;/code&gt;&lt;/a&gt;, the first adopter (full disclosure—I am one of its authors).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;An important corollary: building upon the Jupyter kernel protocol makes &lt;code&gt;jupyter-sphinx&lt;/code&gt; language-agnostic; &lt;code&gt;jupyter-sphinx&lt;/code&gt; works with absolutely any language for which a kernel exists.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id="try-it"&gt;Try it&lt;/h2&gt;
&lt;p&gt;We have freshly published a release candidate, give it a go using &lt;code&gt;pip install jupyter-sphinx==0.2.0rc1 --pre&lt;/code&gt;. We would love to hear your feedback, especially if you are using other ways of embedding outputs in the documentation, or if you are using an older version of &lt;code&gt;jupyter-sphinx&lt;/code&gt;.&lt;/p&gt;
</content><category term="documentation"/></entry></feed>