Questions tagged [autodoc]

Extension for the Sphinx documentation generator that imports Python modules in order to extract docstrings in a semi-automatic way.

Python Sphinx extension that can import the modules being documented, and pull in documentation from docstrings in a semi-automatic way.

The sphix.ext.autodoc extension can be used in conjunction with the sphinx.ext.napoleon extension. This allows use of NumPy and Google style docstrings. The Napoleon prepocessor will initially convert your docstrings to ReStructured text, that afterwards is processed by autodoc.

Several commonly used directives are provided by autodoc, namely ..automodule:: and ..autoclass: For examples of use see the sphinx.ext.autodoc documentation.

See also:

456 questions
26
votes
1 answer

Unknown directive type "toctree". Error in Pycharm, but index.html works

When working in PyCharm, the preview mode of the document I am creating in Sphinx shows: System Message: ERROR/3 (, line 9) Unknown directive type "toctree". ..toctree:: :maxdepth: 2 file1 file2 I have included the autodoc extension in…
Wouter
  • 477
  • 2
  • 6
  • 8
26
votes
2 answers

How to specify different return types in python docstring

I'm currently writing documentation for my python package using Sphinx and the autodoc plugin. For a function return value I can e.g. write :returns: int: count which tells sphinx that there is a return value of type int, named count. I now got a…
Igl3
  • 4,900
  • 5
  • 35
  • 69
25
votes
5 answers

Include specific special-methods in sphinx

I have a bunch of classes which use "special-methods": class Foo(object): "Foo docstring" attr1 = "Attribute!" #: first attribute attr2 = "Another Attribute!" #: second attribute def __init__(self): self.x = 12 def…
mgilson
  • 300,191
  • 65
  • 633
  • 696
25
votes
1 answer

Using sphinx to auto-document a python class, module

I have installed Sphinx in order to document some Python modules and class I'm working on. While the markup language looks very nice, I haven't managed to auto-document a Python code. Basically, I have the following Python module: SegLib.py And A…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
24
votes
2 answers

Emit reStructuredText from sphinx autodoc?

CPython doesn't use autodoc for its documentation - we use hand-written prose. For PEP 3144 (the ipaddress module), I'd like to use sphinx-apidoc to generate the initial reference documentation. That means I want to run a two-pass operation: Use…
ncoghlan
  • 40,168
  • 10
  • 71
  • 80
23
votes
1 answer

Sphinx Autodoc and NumpyDoc

despite reading this tutorial, this question and the numpy docstring standard, I'm unable to get sphinx autodoc to play nicely with numpy docstrings. In my conf.py I have: extensions = ['sphinx.ext.autodoc', 'numpydoc'] and in my doc file I have: …
LondonRob
  • 73,083
  • 37
  • 144
  • 201
22
votes
2 answers

Overriding Sphinx autodoc "Alias of" for import of private class?

I have a Python package that I am attempting to document with sphinx-autodoc. My python package has an __init__.py file that imports a class out from a submodule to make it accessible at the package level. from a.b.c.d import _Foo as Foo __all__ =…
Saff
  • 501
  • 3
  • 13
22
votes
1 answer

Automatically create a toctree for autodoc classes in Sphinx

I'm looking to increase the documentation in one of my libraries. I've been using sphinx to help build the documentation and recently started exploring the autodoc extension. It seems like in most professional documentation, each class documentation…
Ben Hoff
  • 1,058
  • 1
  • 11
  • 24
22
votes
2 answers

Sphinx autodoc gives WARNING: py:class reference target not found: type warning

I've got some code that uses a metaclass in python. But when sphinx autodoc is run it is giving the error: WARNING: py:class reference target not found: type The error is occuring in a line of an auto generated .rst file: .. automodule::…
21
votes
1 answer

Make Read the Docs include autodoc documentation for special-members?

I have a module with two documented global special-members. Running Sphinx locally creates documentation that includes their docs, but Read the Docs doesn't. It uses the built-in type's documentation instead. I have tried both styles: #: and…
Márcio
  • 677
  • 8
  • 15
18
votes
4 answers

Make sphinx's autodoc show default values in parameters' description

I have the following docstring: def progress_bar(progress, length=20): ''' Returns a textual progress bar. >>> progress_bar(0.6) '[##########--------]' :param progress: Number between 0 and 1 describes the progress. :type…
iTayb
  • 12,373
  • 24
  • 81
  • 135
17
votes
1 answer

How to include automatically all classes, methods and functions in a sphinx documentation?

I try to create a html documentation for a project containing several thousand classes using sphinx and it's autodoc plugin. sphinx-apidoc creates wonderful rst-files, but lacks of an automatic creation of autoclasses and automethods. Is there a…
Jon
  • 11,356
  • 5
  • 40
  • 74
15
votes
1 answer

Get "flat" member output for sphinx automodule

I'm using the Sphinx autodoc extension to document a module, and I'd like to get a flat list of the module's members in the documentation output. I tried using the following: .. automodule:: modname :members: However, there are two problems with…
ncoghlan
  • 40,168
  • 10
  • 71
  • 80
15
votes
0 answers

List subclasses in Sphinx using autodoc

Is there an autodoc-directive that will list all subclasses of a given class? If I have the following Python-Code: class Base(object): pass class A(Base): pass class B(Base): pass Is there a way to generate an Output like: Classes…
milnet
  • 259
  • 2
  • 8
14
votes
5 answers

Sphinx values for attributes reported as None

When I use Sphinx autodoc to document a class, the values for the attributes are always reported, (as it says it should here, under #437) but always as "= None" Attribute = None Some Documentation I include it like .. autoclass::…
noio
  • 5,744
  • 7
  • 44
  • 61
1
2
3
30 31