This extension can import the modules you are documenting, and pull in documentation from docstrings in a semi-automatic way.
For this to work, the docstrings must of course be written in correct reStructuredText. You can then use all of the usual Sphinx markup in the docstrings, and it will end up correctly in the documentation. Together with hand-written documentation, this technique eases the pain of having to maintain two locations for documentation, while at the same time avoiding auto-generated-looking pure API documentation.
autodoc provides several directives that are versions of the usual module, class and so forth. On parsing time, they import the corresponding module and extract the docstring of the given objects, inserting them into the page source under a suitable module, class etc. directive.
Note
Just as class respects the current module, autoclass will also do so, and likewise with method and class.
Document a module, class or exception. All three directives will by default only insert the docstring of the object itself:
.. autoclass:: Noodle
will produce source like this:
.. class:: Noodle Noodle's docstring.
If you want to automatically document members, there’s a members option:
.. autoclass:: Noodle :members:
will document all non-private member functions and properties (that is, those whose name doesn’t start with _), while
.. autoclass:: Noodle :members: eat, slurp
will document exactly the specified members.
Members without docstrings will be left out, unless you give the undoc-members flag option.
New in version 0.3: For classes and exceptions, members inherited from base classes will be left out, unless you give the inherited-members flag option.
The “auto” directives can also contain content of their own, it will be inserted into the resulting non-auto directive source after the docstring (but before any automatic member documentation).
Therefore, you can also mix automatic and non-automatic member documentation, like so:
.. autoclass:: Noodle :members: eat, slurp .. method:: boil(time=10) Boil the noodle *time* minutes.
Note
In an automodule directive with the members option set, only module members whose __module__ attribute is equal to the module name as given to automodule will be documented. This is to prevent documentation of imported classes or functions.
There are also new config values that you can set:
This value selects what content will be inserted into the main body of an autoclass directive. The possible values are:
New in version 0.3.