sphinx-codeautolink makes code examples clickable by inserting links
from individual code elements to the corresponding reference documentation.
We aim for a minimal setup assuming your examples are already valid Python.
Click any names in the example below for a demonstration:
A directive to create a table of references from code examples to a single
definition is also provided, which can also be integrated with autodoc entries.
.. autolink-examples:: lib.Knight produces:
Integration with intersphinx is seamless:
$ pip install sphinx-codeautolink
To enable sphinx-codeautolink, modify the extension list in
Note that the extension name uses an underscore rather than a hyphen.
extensions = [
That’s it! Now your code examples are linked.
For ways of concatenating multiple examples
and setting default import statements among other things,
have a look at the Reference documentation.
For a more thorough explanation, see About.
Only works with HTML documentation
Only processes literal blocks, not inline code
Doesn’t run example code
Parsing and type hint resolving is incomplete
The inspiration for sphinx-codeautolink came from seeing similar awesome docs
generated by Sphinx-Gallery!
Their source was also immensely helpful to read
when I was stumbling through Sphinx and docutils.
If you have a folder full of example Python scripts you’d like to include in
your documentation, you’ll not be disappointed in their offer.