<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <id>https://blog.readthedocs.com</id>
  <title>Read the Docs Blog - Posts tagged api</title>
  <updated>2023-07-08T10:50:30.028379+00:00</updated>
  <link href="https://blog.readthedocs.com"/>
  <link href="https://blog.readthedocs.com/archive/tag/api/atom.xml" rel="self"/>
  <generator uri="https://ablog.readthedocs.org/" version="0.10.26">ABlog</generator>
  <entry>
    <id>https://blog.readthedocs.com/embed-api-v3/</id>
    <title>Announcing Embed API v3 and sphinx-hoverxref 1.0</title>
    <updated>2021-12-07T00:00:00+00:00</updated>
    <author>
      <name>Juan Luis Cano Rodríguez</name>
    </author>
    <content type="html">&lt;section id="announcing-embed-api-v3-and-sphinx-hoverxref-1-0"&gt;

&lt;p&gt;We are thrilled to announce the availability of Read the Docs Embed API v3,
along with its official client, sphinx-hoverxref 1.0.
This work has been possible in part thanks to the
&lt;a class="reference internal" href="../../../czi-grant-announcement/"&gt;&lt;span class="doc"&gt;the CZI grant we received&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;section id="the-value-of-content-embedding"&gt;
&lt;h2&gt;The value of content embedding&lt;/h2&gt;
&lt;p&gt;As we wrote in
&lt;a class="reference internal" href="../../../hoverxref-intersphinx/"&gt;&lt;span class="doc"&gt;our first blog post about sphinx-hoverxref&lt;/span&gt;&lt;/a&gt;,
one of the most powerful features of Sphinx
is the possibility of creating cross references
to other documentation projects.
However, a reader finding several links in a technical documentation
might need to open several browser tabs to fully understand the context,
resulting in a lot of friction in the form of context switching.&lt;/p&gt;
&lt;p&gt;One way of mitigating the problem is to show a small preview
in the form of tooltip or modal with the contents of the link.
This is where the Embed API and sphinx-hoverxref come in.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="https://sphinx-hoverxref.readthedocs.io/"&gt;sphinx-hoverxref&lt;/a&gt; is a Sphinx extension that addresses this problem
by adding tooltips on the cross references of the HTML documentation
with the content of the linked section.
To do so, it inserts a small JavaScript file that
calls the Read the Docs Embed API when the user hovers any link.
&lt;a class="reference internal" href="../../../hoverxref-intersphinx/"&gt;&lt;span class="doc"&gt;Back in June&lt;/span&gt;&lt;/a&gt; we announced
intersphinx support in &lt;a class="reference external" href="https://sphinx-hoverxref.readthedocs.io/"&gt;sphinx-hoverxref&lt;/a&gt; 0.6b1,
which allowed users to include modals and tooltips
also for cross references to other projects.&lt;/p&gt;
&lt;figure class="align-center" id="id2"&gt;
&lt;a class="reference external image-reference" href="/_images/sphinx-hoverxref-showcase.gif"&gt;&lt;img alt="sphinx-hoverxref displaying tooltips for cross references" src="../../../_images/sphinx-hoverxref-showcase.gif" style="width: 60%;" /&gt;&lt;/a&gt;
&lt;figcaption&gt;
&lt;p&gt;&lt;span class="caption-text"&gt;sphinx-hoverxref displaying a tooltip including an equation&lt;/span&gt;&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Some big projects already using it include &lt;a class="reference external" href="https://docs.tweepy.org/"&gt;Tweepy&lt;/a&gt;,
a Python client for Twitter, and &lt;a class="reference external" href="https://docs.scrapy.org/"&gt;Scrapy&lt;/a&gt;,
a framework for crawling websites.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="embed-api-v3-and-sphinx-hoverxref-1-0"&gt;
&lt;h2&gt;Embed API v3 and sphinx-hoverxref 1.0&lt;/h2&gt;
&lt;p&gt;After some months of work, &lt;strong&gt;we are excited to publish v3 of our Embed API,
and with it, version 1.0 of sphinx-hoverxref&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Among other things,
the new versions allow you to
&lt;a class="reference external" href="https://docs.readthedocs.io/en/stable/guides/embedding-content.html" title="(in Read the Docs user documentation v9.15.0)"&gt;&lt;span class="xref std std-doc"&gt;embed content from pages hosted outside Read the Docs&lt;/span&gt;&lt;/a&gt;.
For security reasons, we have an allowlist of such external domains
that currently includes Python, NumPy, SciPy, SymPy,
and we would like to
&lt;a class="reference external" href="https://github.com/readthedocs/readthedocs.org/issues"&gt;invite the community to suggest more domains to add&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Other additions and fixes include:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;Support for JS and CSS assets in Sphinx 4.1+.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Support for &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;glossary&lt;/span&gt;&lt;/code&gt; / &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;term&lt;/span&gt;&lt;/code&gt; and sphinxcontrib-bibtex.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoid showing the browser built-in tooltip for links that have the extension enabled.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, version 3 of the Embed API
paves the way for supporting non-Sphinx projects in the future.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="embedding-content-with-sphinx-hoverxref"&gt;
&lt;h2&gt;Embedding content with sphinx-hoverxref&lt;/h2&gt;
&lt;p&gt;To use sphinx-hoverxref in your Read the Docs project,
&lt;a class="reference external" href="https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html" title="(in Read the Docs user documentation v9.15.0)"&gt;&lt;span class="xref std std-doc"&gt;declare it as part of your dependencies&lt;/span&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class="literal-block-wrapper docutils container" id="id3"&gt;
&lt;div class="code-block-caption"&gt;&lt;span class="caption-text"&gt;requirements.txt&lt;/span&gt;&lt;/div&gt;
&lt;div class="highlight-default notranslate"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;sphinx&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="mf"&gt;4.3.1&lt;/span&gt;
&lt;span class="n"&gt;sphinx_rtd_theme&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="mf"&gt;1.0.0&lt;/span&gt;
&lt;span class="hll"&gt;&lt;span class="n"&gt;sphinx&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hoverxref&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="mf"&gt;1.0.0&lt;/span&gt;
&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And add it to your list of Sphinx extensions:&lt;/p&gt;
&lt;div class="literal-block-wrapper docutils container" id="id4"&gt;
&lt;div class="code-block-caption"&gt;&lt;span class="caption-text"&gt;conf.py&lt;/span&gt;&lt;/div&gt;
&lt;div class="highlight-default notranslate"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;extensions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="c1"&gt;# ...other extensions&lt;/span&gt;
&lt;span class="hll"&gt;    &lt;span class="s2"&gt;&amp;quot;hoverxref.extension&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To enable the extension on all &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;:ref:&lt;/span&gt;&lt;/code&gt; of your documentation,
set the &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;hoverxref_auto_ref&lt;/span&gt;&lt;/code&gt; to &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;True&lt;/span&gt;&lt;/code&gt;:&lt;/p&gt;
&lt;div class="literal-block-wrapper docutils container" id="id5"&gt;
&lt;div class="code-block-caption"&gt;&lt;span class="caption-text"&gt;conf.py&lt;/span&gt;&lt;/div&gt;
&lt;div class="highlight-default notranslate"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;hoverxref_auto_ref&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;And you will start seeing tooltips on your internal references.
Apart from &lt;code class="docutils literal notranslate"&gt;&lt;span class="pre"&gt;:ref:&lt;/span&gt;&lt;/code&gt; roles, you can also enable tooltips on:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://sphinx-hoverxref.readthedocs.io/en/stable/usage.html#tooltip-on-sphinx-domains" title="(in sphinx-hoverxref)"&gt;&lt;span class="xref std std-ref"&gt;Code objects from any Sphinx domain&lt;/span&gt;&lt;/a&gt;,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://sphinx-hoverxref.readthedocs.io/en/stable/usage.html#tooltip-on-glossary-terms" title="(in sphinx-hoverxref)"&gt;&lt;span class="xref std std-ref"&gt;Glossary terms&lt;/span&gt;&lt;/a&gt;,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://sphinx-hoverxref.readthedocs.io/en/stable/usage.html#tooltip-on-sphinxcontrib-bibtex-cites" title="(in sphinx-hoverxref)"&gt;&lt;span class="xref std std-ref"&gt;BibTeX citations&lt;/span&gt;&lt;/a&gt;,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://sphinx-hoverxref.readthedocs.io/en/stable/usage.html#tooltip-with-content-that-needs-extra-rendering-steps" title="(in sphinx-hoverxref)"&gt;&lt;span class="xref std std-ref"&gt;Pages containing extra JavaScript like sphinx-tabs and
MathJax&lt;/span&gt;&lt;/a&gt;,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://sphinx-hoverxref.readthedocs.io/en/stable/usage.html#tooltip-on-intersphinx-content" title="(in sphinx-hoverxref)"&gt;&lt;span class="xref std std-ref"&gt;Intersphinx references&lt;/span&gt;&lt;/a&gt;,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://sphinx-hoverxref.readthedocs.io/en/stable/usage.html#tooltip-on-custom-object" title="(in sphinx-hoverxref)"&gt;&lt;span class="xref std std-ref"&gt;And custom objects!&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="admonition note"&gt;
&lt;p class="admonition-title"&gt;Note&lt;/p&gt;
&lt;p&gt;sphinx-hoverxref includes the JavaScript embed client in the HTML assets,
but it is not yet available as a standalone library that can be reused
with standard frontend packaging tools.
If you would like to see this happening,
&lt;a class="reference external" href="https://github.com/readthedocs/sphinx-hoverxref/issues/"&gt;let us know&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;section id="calling-the-embed-api-directly"&gt;
&lt;h2&gt;Calling the Embed API directly&lt;/h2&gt;
&lt;p&gt;As explained in &lt;a class="reference external" href="https://docs.readthedocs.io/en/stable/guides/embedding-content.html#calling-the-embed-api-directly" title="(in Read the Docs user documentation v9.15.0)"&gt;&lt;span class="xref std std-ref"&gt;our embedding
guide&lt;/span&gt;&lt;/a&gt;,
you can call the API directly from any HTTP client:&lt;/p&gt;
&lt;div class="highlight-console notranslate"&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;curl&lt;span class="w"&gt; &lt;/span&gt;-s&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;https://readthedocs.org/api/v3/embed/\&lt;/span&gt;
&lt;span class="gp"&gt;&amp;gt; &lt;/span&gt;&lt;span class="s2"&gt;?url=https://docs.readthedocs.io/en/latest/features.html\&lt;/span&gt;
&lt;span class="gp"&gt;&amp;gt; &lt;/span&gt;&lt;span class="s2"&gt;%23read-the-docs-features&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;python&lt;span class="w"&gt; &lt;/span&gt;-m&lt;span class="w"&gt; &lt;/span&gt;json.tool
&lt;span class="go"&gt;{&lt;/span&gt;
&lt;span class="go"&gt;  &amp;quot;url&amp;quot;: &amp;quot;https://docs.readthedocs.io/en/latest/features.html#read-the-docs-features&amp;quot;,&lt;/span&gt;
&lt;span class="go"&gt;  &amp;quot;fragment&amp;quot;: &amp;quot;read-the-docs-features&amp;quot;,&lt;/span&gt;
&lt;span class="go"&gt;  &amp;quot;content&amp;quot;: &amp;quot;&amp;lt;div class=\&amp;quot;section\&amp;quot; id=\&amp;quot;read-the-docs-features\&amp;quot;&amp;gt;\n&amp;lt;h1&amp;gt;Read the Docs ...&amp;quot;,&lt;/span&gt;
&lt;span class="go"&gt;  &amp;quot;external&amp;quot;: false&lt;/span&gt;
&lt;span class="go"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Or visually explore the query in the &lt;a class="reference external" href="https://readthedocs.org/api/v3/embed/?url=https://docs.readthedocs.io/en/latest/features.html%23read-the-docs-features"&gt;web interface&lt;/a&gt; instead.&lt;/p&gt;
&lt;p&gt;The &lt;a class="reference external" href="https://docs.readthedocs.io/en/stable/api/v3.html#embed" title="(in Read the Docs user documentation v9.15.0)"&gt;&lt;span class="xref std std-ref"&gt;reference documentation&lt;/span&gt;&lt;/a&gt;
includes more detail about the parameters and return values of the API.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="try-it-out"&gt;
&lt;h2&gt;Try it out!&lt;/h2&gt;
&lt;p&gt;We would like to invite the community to try out these features and
send us feedback. With the help of our users, we will keep moving towards
a more cohesive documentation ecosystem of interlinked Python projects.&lt;/p&gt;
&lt;hr class="docutils" /&gt;
&lt;p&gt;Considering using Read the Docs for your next Sphinx or MkDocs project?
Check out &lt;a class="reference external" href="https://docs.readthedocs.io/"&gt;our documentation&lt;/a&gt; to get started!&lt;/p&gt;
&lt;/section&gt;
&lt;/section&gt;
</content>
    <link href="https://blog.readthedocs.com/embed-api-v3/" rel="alternate"/>
    <summary>We are thrilled to announce the availability of Read the Docs Embed API v3,
along with its official client, sphinx-hoverxref 1.0.
This work has been possible in part thanks to the
the CZI grant we received.As we wrote in
our first blog post about sphinx-hoverxref,
one of the most powerful features of Sphinx
is the possibility of creating cross references
to other documentation projects.
However, a reader finding several links in a technical documentation
might need to open several browser tabs to fully understand the context,
resulting in a lot of friction in the form of context switching.</summary>
    <category term="api" label="api"/>
    <category term="feature" label="feature"/>
    <category term="grant" label="grant"/>
    <published>2021-12-07T00:00:00+00:00</published>
  </entry>
</feed>
