| Author: | Edward Loper |
|---|---|
| Version: | 3.0b1 |
Abstract
Epydoc is a tool for generating API documentation for Python modules, based on their docstrings. For an example of epydoc's output, see the API documentation for epydoc itself (html, pdf). A lightweight markup language called epytext can be used to format docstrings, and to add information about specific fields, such as parameters and instance variables. Epydoc also understands docstrings written in reStructuredText, Javadoc, and plaintext. For a more extensive example of epydoc's output, see the API documentation for Python 2.4.
Contents
Epydoc can be downloaded from the SourceForge download page. Epydoc is available in five formats:
If you are installing on RedHat, I recommend that you use the RPM file. If you are installing on Windows, I recommended that you use the windows installer. Otherwise, you should use one of the source install files.
If you wish to keep up on the latest developments, you can get the latest version of epydoc from the subversion repository:
[/home/edloper]$ svn co https://epydoc.svn.sourceforge.net/svnroot/epydoc/trunk/epydoc epydoc [/home/edloper]$ ls epydoc Makefile doc man sandbox src
This will create a directory named epydoc containing the latest version of epydoc. The epydoc package itself is in epydoc/src/epydoc (so adding epydoc/src to your PYTHONPATH will let you use it). You should periodically update your copy of the subversion repository, to make sure you have all the latest changes:
[/home/edloper/epydoc]$ svn up
You can browse the subversion repository here.
Download the RPM file to a directory of your choice.
Use rpm to install the new package.
[/tmp]$ su Password: [/tmp]# rpm -i epydoc-3.0.noarch.rpm
Once epydoc is installed, you can delete the RPM file.
[/tmp]# rm epydoc-3.0.rpm
Download an epydoc source distribution to a directory of your choice, and uncompress it.
[/tmp]$ wget -q http://prdownloads.sourceforge.net/epydoc/epydoc-3.0.tar.gz [/tmp]$ gunzip epydoc-3.0.tar.gz [/tmp]$ tar -xvf epydoc-3.0.tar
Use make install in the eydoc-3.0/ directory to install epydoc.
[/tmp]$ cd epydoc-3.0/ [/tmp/epydoc-3.0]$ su Password: [/tmp/epydoc-3.0]# make install running install running build [...] copying build/scripts/epydoc -> /usr/bin changing mode of /usr/bin/epydoc to 100775
If you'd like to keep a local copy of the documentation, then use make installdocs. By default, this will install the documentation to /usr/share/doc/ and the man pages to /usr/share/man/. If you would prefer to install documentation to different directories (such as /usr/lib/doc), then edit the MAN and DOC variables at the top of Makefile before running make installdocs.
[/tmp/epydoc-3.0]# make installdocs
Once epydoc is installed, you can delete the installation directory and the source distribution file.
[/tmp/epydoc-3.0]# cd .. [/tmp]# rm -r epydoc-3.0 [/tmp]# rm epydoc-3.0.tar
Download an epydoc source distribution to a directory of your choice, and uncompress it.
[/tmp]$ wget -q http://prdownloads.sourceforge.net/epydoc/epydoc-3.0.tar.gz [/tmp]$ gunzip epydoc-3.0.tar.gz [/tmp]$ tar -xvf epydoc-3.0.tar
Use the setup.py script in the eydoc-3.0/ directory to install epydoc.
[/tmp]$ cd epydoc-3.0/ [/tmp/epydoc-3.0]$ su Password: [/tmp/epydoc-3.0]# python setup.py install running install running build [...] copying build/scripts/epydoc -> /usr/bin changing mode of /usr/bin/epydoc to 100775 [/tmp/epydoc-3.0]# cd .. [/tmp]#
If you'd like to keep a local copy of the documentation, then copy it to a permanant location, such as /usr/share/doc/. You may also want to copy the man pages to a permanant location, such as /usr/share/man/.
[/tmp]# cp -r epydoc-3.0/doc/ /usr/share/doc/epydoc/ [/tmp]# cp epydoc-3.0/man/* /usr/share/man/
Once epydoc is installed, you can delete the installation directory and the source distribution file.
[/tmp]# rm -r epydoc-3.0 [/tmp]# rm epydoc-3.0.tar
Epydoc 2.1 is available as a testing debian package (python-epydoc). The epydoc documentation is also available as a package (epydoc-doc).
Epydoc provides two user interfaces:
Epydoc can also be accessed programmatically; see epydoc's API documentation for more information.
The epydoc script extracts API documentation for a set of Python objects, and writes it using a selected output format. Objects can be named using dotted names, module filenames, or package directory names. (On Windows, this script is named epydoc.py.)
epydoc [--html|--pdf] [-o DIR] [--parse-only|--introspect-only] [-v|-q]
[--name NAME] [--url URL] [--docformat NAME] [--graph GRAPHTYPE]
[--inheritance STYLE] [--config FILE] OBJECTS...
| --html | Generate HTML output. (default) |
| Generate Adobe Acrobat (PDF) output, using LaTeX. | |
| -o DIR, --output DIR, --target DIR | |
| The output directory. | |
| --parse-only, --introspect-only | |
| By default, epydoc will gather information about each Python object using two methods: parsing the object's source code; and importing the object and directly introspecting it. Epydoc combines the information obtained from these two methods to provide more complete and accurate documentation. However, if you wish, you can tell epydoc to use only one or the other of these methods. For example, if you are running epydoc on untrusted code, you should use the --parse-only option. | |
| -v, -q | Increase (-v) or decrease (-q) the verbosity of the output. These options may be repeated to further increase or decrease verbosity. Docstring markup warnings are supressed unless -v is used at least once. |
| --name NAME | The documented project's name. |
| --url URL | The documented project's URL. |
| --docformat NAME | |
| The markup language that should be used by default to process modules' docstrings. This is only used for modules that do not define the special __docformat__ variable; it is recommended that you explicitly specify __docformat__ in all your modules. | |
| --graph GRAPHTYPE | |
Include graphs of type GRAPHTYPE in the generated output. Graphs are generated using the Graphviz dot executable. If this executable is not on the path, then use --dotpath to specify its location. This option may be repeated to include multiple graph types in the output. To include all graphs, use --graph all. The available graph types are:
| |
| --inheritance STYLE | |
The format that should be used to display inherited methods, variables, and properties. Currently, three styles are supported. To see an example of each style, click on it: | |
| --config FILE | Read the given configuration file, which can contain both options and Python object names. This option may be used multiple times, if you wish to use multiple configuration files. See Configuration Files for more information. |
The complete list of command line options is available in the Command Line Usage section.
The following command will generate HTML documentation for the sys module, and write it to the directory sys_docs:
[epydoc]$ epydoc --html sys -o sys_docs
The following commands are used to produce the API documentation for epydoc itself. The first command writes html output to the directory html/api, using epydoc as the project name and http://epydoc.sourcforge.net as the project URL. The white CSS style is used; inheritance is displayed using the listed style; and all graphs are included in the output. The second command writes pdf output to the file api.pdf in the directory latex/api, using Epydoc as the project name.
[epydoc]$ epydoc -v -o html/api --name epydoc --css white \
--url http://epydoc.sourceforge.net \
--inheritance listed --graph all src/epydoc
[epydoc]$ epydoc -v -o latex/api --pdf --name "Epydoc" src/epydoc
Configuration files, specified using the --config option, may be used to specify both the list of objects to document, and the options that should be used to document them. Configuration files are read using the standard ConfigParser module. The following is a simple example of a configuration file.
[epydoc] # Epydoc section marker (required by ConfigParser) # Information about the project. name: My Cool Project url: http://cool.project/ # The list of modules to document. Modules can be named using # dotted names, module filenames, or package directory names. # This option may be repeated. modules: sys, os.path, re modules: my/project/driver.py # Write html output to the directory "apidocs" output: html target: apidocs/ # Include all automatically generated graphs. These graphs are # generated using Graphviz dot. graph: all dotpath: /usr/local/bin/dot
A more complete example, including all of the supported options, is also available.
Epydoc also includes a graphical interface, for systems where command line interfaces are not convenient (such as Windows). The graphical interface can be invoked with the epydocgui command, or with epydoc.pyw in the Scripts subdirectory of the Python installation directory under Windows. Currently, the graphical interface can only generate HTML output.

Use the Add box to specify what objects you wish to document. Objects can be specified using dotted names (such as os.path), module filenames (such as epydoc/epytext.py), or package directory names (such as epydoc/). Packages are expanded to include all sub-modules and sub-packages. Once you have added all of the modules that you wish to document, press the Start button. Epydoc's progress will be displayed on the progress bar.
To customize the output, click on the Options arrow at the bottom of the window. This opens the options pane, which contains fields corresponding to each command line option.
The epydoc graphical interface can save and load project files, which record the set of modules and the options that you have selected. Select File->Save to save the current modules and options to a project file; and File->Open to open a previously saved project file. (These project files do not currently use the same format as the configuration files used by the command line interface.)
For more information, see the epydocgui(1) man page.
The epydoc script can be used to check the completeness of the reference documentation. In particular, it will check that every module, class, method, and function has a description; that every parameter has a description and a type; and that every variable has a type. If the -p option is used, then these checks are run on both public and private objects; otherwise, the checks are only run on public objects.
epydoc --check [-p] MODULES...
| -p | Run documentation completeness checks on private objects. |
For each object that fails a check, epydoc will print a warning. For example, some of the warnings generated when checking the completeness of the documentation for epydoc's private objects are:
epydoc.html.HTML_Doc._dom_link_to_html........No docs epydoc.html.HTML_Doc._module..................No type epydoc.html.HTML_Doc._link_to_html.link.......No descr epydoc.html.HTML_Doc._author.return...........No type epydoc.html.HTML_Doc._author.authors..........No descr, No type epydoc.html.HTML_Doc._author.container........No descr, No type epydoc.html.HTML_Doc._base_tree.uid...........No descr, No type epydoc.html.HTML_Doc._base_tree.width.........No descr, No type epydoc.html.HTML_Doc._base_tree.postfix.......No descr, No type
If you'd like more fine-grained control over what gets checked, or you would like to check other fields (such as the author or version), then you should use the DocChecker class directly.
Every Python module and class is documented in its own file. Index files, tree files, a help file, and a frames-based table of contents are also created. The following list describes each of the files generated by epydoc:
Epydoc creates a CSS stylesheet (epydoc.css) when it builds the API documentation for a project. You can specify which stylesheet should be used using the --css command-line option. If you do not specify a stylesheet, and one is already present, epydoc will use that stylesheet; otherwise, it will use the default stylesheet.
Python documentation strings (or docstrings) provide a convenient way of associating documentation with Python modules, functions, classes, and methods. An object's docsting is defined by including a string constant as the first statement in the object's definition. For example, the following function defines a docstring:
def x_intercept(m, b): """ Return the x intercept of the line y=m*x+b. The x intercept of a line is the point at which it crosses the x axis (y=0). """ return -b/m
Docstrings can be accessed from the interpreter and from Python programs using the "__doc__" attribute:
>>> print x_intercept.__doc__ Return the x intercept of the line y=m*x+b. The x intercept of a line is the point at which it crosses the x axis (y=0).
The pydoc module, which became part of the standard library in Python 2.1, can be used to display information about a Python object, including its docstring:
>>> from pydoc import help >>> help(x_intercept) Help on function x_intercept in module __main__: x_intercept(m, b) Return the x intercept of the line y=m*x+b. The x intercept of a line is the point at which it crosses the x axis (y=0).
For more information about Python docstrings, see the Python Tutorial or the O'Reilly Network article Python Documentation Tips and Tricks.
Python don't support directly docstrings on variables: there is no attribute that can be attached to variables and retrieved interactively like the __doc__ attribute on modules, classes and functions.
While the language doesn't directly provides for them, Epydoc supports variable docstrings: if a variable assignment statement is immediately followed by a bare string literal, then that assignment is treated as a docstring for that variable. In classes, variable assignments at the class definition level are considered class variables; and assignments to instance variables in the constructor (__init__) are considered instance variables:
class A: x = 22 """Docstring for class variable A.x""" def __init__(self, a): self.y = a """Docstring for instance variable A.y
Variables may also be documented using comment docstrings. If a variable assignment is immediately preceeded by a comment whose lines begin with the special marker '#:', or is followed on the same line by such a comment, then it is treated as a docstring for that variable:
#: docstring for x x = 22 x = 22 #: docstring for x
Notice that variable docstrings are only available for documentation when the source code is available for parsing: it is not possible to retrieve variable
Any Python object (modules, classes, functions, variables...) can be public or private. Usually the object name decides the object visibility: objects whose name starts with an underscore and doesn't end with an underscore are considered private. All the other objects (including the "magic functions" such as __add__) are public.
For each module and class, Epydoc generates pages with both public and private methods. A Javascript snippet allows you to toggle the visibility of private objects.
If a module wants to hide some of the objects it contains (either defined in the module itself or imported from other modules), it can explicitly list the names if its public names in the __all__ variable.
If a module defines the __all__ variable, Epydoc uses its content to decide if the module objects are public or private.
Epytext is a simple lightweight markup language that lets you add formatting and structue to docstrings. Epydoc uses that formatting and structure to produce nicely formatted API documentation. The following example (which has an unusually high ratio of documentaiton to code) illustrates some of the basic features of epytext:
def x_intercept(m, b): """ Return the x intercept of the line M{y=m*x+b}. The X{x intercept} of a line is the point at which it crosses the x axis (M{y=0}). This function can be used in conjuction with L{z_transform} to find an arbitrary function's zeros. @type m: number @param m: The slope of the line. @type b: number @param b: The y intercept of the line. The X{y intercept} of a line is the point at which it crosses the y axis (M{x=0}). @rtype: number @return: the x intercept of the line M{y=m*x+b}. """ return -b/m
You can compare this function definition with the API documentation generated by epydoc. Note that:
Epytext is intentionally very lightweight. If you wish to use a more expressive markup language, I recommend reStructuredText.
Epytext is a lightweight markup language for Python docstrings. The epytext markup language is used by epydoc to parse docstrings and create structured API documentation. Epytext markup is broken up into the following categories:
Block Structure divides the docstring into nested blocks of text, such as paragraphs and lists.
o Basic Blocks are the basic unit of block structure.
o Hierarchical blocks represent the nesting structure of the docstring.
Inline Markup marks regions of text within a basic block with properties, such as italics and hyperlinks.
Block structure is encoded using indentation, blank lines, and a handful of special character sequences.
The following sections describe how to use each type of block structure.
A paragraph is the simplest type of basic block. It consists of one or more lines of text. Paragraphs must be left justified (i.e., every line must have the same indentation). The following example illustrates how paragraphs can be used:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ This is a paragraph. Paragraphs can span multiple lines, and can contain I{inline markup}. This is another paragraph. Paragraphs are separated by blank lines. """ *[...]* |
This is a paragraph. Paragraphs can span multiple lines, and contain inline markup. This is another paragraph. Paragraphs are separated from each other by blank lines. |
Epytext supports both ordered and unordered lists. A list consists of one or more consecutive list items of the same type (ordered or unordered), with the same indentation. Each list item is marked by a bullet. The bullet for unordered list items is a single dash character (-). Bullets for ordered list items consist of a series of numbers followed by periods, such as 12. or 1.2.8..
List items typically consist of a bullet followed by a space and a single paragraph. The paragraph may be indented more than the list item's bullet; often, the paragraph is intended two or three characters, so that its left margin lines up with the right side of the bullet. The following example illustrates a simple ordered list.
| Docstring Input | Rendered Output |
|---|---|
def example(): """ 1. This is an ordered list item. 2. This is a another ordered list item. 3. This is a third list item. Note that the paragraph may be indented more than the bullet. """ *[...]* |
|
List items can contain more than one paragraph; and they can also contain sublists, literal blocks, and doctest blocks. All of the blocks contained by a list item must all have equal indentation, and that indentation must be greater than or equal to the indentation of the list item's bullet. If the first contained block is a paragraph, it may appear on the same line as the bullet, separated from the bullet by one or more spaces, as shown in the previous example. All other block types must follow on separate lines.
Every list must be separated from surrounding blocks by indentation:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ This is a paragraph. 1. This is a list item. 2. This a second list item. - This is a sublist """ [...] |
This is a paragraph.
|
Note that sublists must be separated from the blocks in their parent list item by indentation. In particular, the following docstring generates an error, since the sublist is not separated from the paragraph in its parent list item by indentation:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ 1. This is a list item. Its paragraph is indented 7 spaces. - This is a sublist. It is indented 7 spaces. """ #[...] |
L5: Error: Lists must be indented. |
The following example illustrates how lists can be used:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ This is a paragraph. 1. This is a list item. - This is a sublist. - The sublist contains two items. - The second item of the sublist has its own sublist. 2. This list item contains two paragraphs and a doctest block. >>> print 'This is a doctest block' This is a doctest block This is the second paragraph. """ #[...] |
This is a paragraph.
|
Epytext will treat any line that begins with a bullet as a list item. If you want to include bullet-like text in a paragraph, then you must either ensure that it is not at the beginning of the line, or use escaping to prevent epytext from treating it as markup:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ This sentence ends with the number 1. Epytext can't tell if the "1." is a bullet or part of the paragraph, so it generates an error. """ #[...] |
L4: Error: Lists must be indented. |
def example(): """ This sentence ends with the number 1. This sentence ends with the number E{1}. """ #[...] |
This sentence ends with the number 1. This sentence ends with the number 1. |
A section consists of a heading followed by one or more child blocks.
The following example illustrates how sections can be used:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ This paragraph is not in any section. Section 1 ========= This is a paragraph in section 1. Section 1.1 ----------- This is a paragraph in section 1.1. Section 2 ========= This is a paragraph in section 2. """ #[...] |
Section 1 This is a paragraph in section 1. Section 1.1 This is a paragraph in section 1.1. Section 2 This is a paragraph in section 2. |
Literal blocks are used to represent "preformatted" text. Everything within a literal block should be displayed exactly as it appears in plaintext. In particular:
Literal blocks are introduced by paragraphs ending in the special sequence "::". Literal blocks end at the first line whose indentation is equal to or less than that of the paragraph that introduces them. The following example shows how literal blocks can be used:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ The following is a literal block:: Literal / / Block This is a paragraph following the literal block. """ #[...] |
The following is a literal block:
Literal /
/ Block
This is a paragraph following the literal block. |
Literal blocks are indented relative to the paragraphs that introduce them; for example, in the previous example, the word "Literal" is displayed with four leading spaces, not eight. Also, note that the double colon ("::") that introduces the literal block is rendered as a single colon.
Doctest blocks contain examples consisting of Python expressions and their output. Doctest blocks can be used by the doctest module to test the documented object. Doctest blocks begin with the special sequence ">>>". Doctest blocks are delimited from surrounding blocks by blank lines. Doctest blocks may not contain blank lines. The following example shows how doctest blocks can be used:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ The following is a doctest block: >>> print (1+3, ... 3+5) (4, 8) >>> 'a-b-c-d-e'.split('-') ['a', 'b', 'c', 'd', 'e'] This is a paragraph following the doctest block. """ #[...] |
The following is a doctest block: >>> print (1+3, ... 3+5) (4, 8) >>> 'a-b-c-d-e'.split('-') ['a', 'b', 'c', 'd', 'e'] This is a paragraph following the doctest block. |
Fields are used to describe specific properties of a documented object. For example, fields can be used to define the parameters and return value of a function; the instance variables of a class; and the author of a module. Each field is marked by a field tag, which consist of an at sign ('@') followed by a field name, optionally followed by a space and a field argument, followed by a colon (':'). For example, '@return:' and '@param x:' are field tags.
Fields can contain paragraphs, lists, literal blocks, and doctest blocks. All of the blocks contained by a field must all have equal indentation, and that indentation must be greater than or equal to the indentation of the field's tag. If the first contained block is a paragraph, it may appear on the same line as the field tag, separated from the field tag by one or more spaces. All other block types must follow on separate lines.
Fields must be placed at the end of the docstring, after the description of the object. Fields may be included in any order.
Fields do not need to be separated from other blocks by a blank line. Any line that begins with a field tag followed by a space or newline is considered a field.
The following example illustrates how fields can be used:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ @param x: This is a description of the parameter x to a function. Note that the description is indented four spaces. @type x: This is a description of x's type. @return: This is a description of the function's return value. It contains two paragraphs. """ #[...] |
|
For a list of the fields that are supported by epydoc, see the epydoc fields chapter.
Inline markup has the form 'x{...}', where x is a single capital letter that specifies how the text between the braces should be rendered. Inline markup is recognized within paragraphs and section headings. It is not recognized within literal and doctest blocks. Inline markup can contain multiple words, and can span multiple lines. Inline markup may be nested.
A matching pair of curly braces is only interpreted as inline markup if the left brace is immediately preceeded by a capital letter. So in most cases, you can use curly braces in your text without any form of escaping. However, you do need to escape curly braces when:
Note that there is no valid Python expression where a pair of matched curly braces is immediately preceeded by a capital letter (except within string literals). In particular, you never need to escape braces when writing Python dictionaries. See also escaping.
Epytext defines four types of inline markup that specify how text should be displayed:
By default, source code is rendered in a fixed width font; and mathematical expressions are rendered in italics. But those defaults may be changed by modifying the CSS stylesheet. The following example illustrates how the four basic markup types can be used:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ I{B{Inline markup} may be nested; and it may span} multiple lines. - I{Italicized text} - B{Bold-faced text} - C{Source code} - M{Math} Without the capital letter, matching braces are not interpreted as markup: C{my_dict={1:2, 3:4}}. """ #[...] |
Inline markup may be nested; and it may span multiple lines.
Without the capital letter, matching braces are not interpreted as markup: my_dict={1:2, 3:4}. |
The inline markup construct U{text<url>} is used to create links to external URLs and URIs. 'text' is the text that should be displayed for the link, and 'url' is the target of the link. If you wish to use the URL as the text for the link, you can simply write "U{url}". Whitespace within URL targets is ignored. In particular, URL targets may be split over multiple lines. The following example illustrates how URLs can be used:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ - U{www.python.org} - U{http://www.python.org} - U{The epydoc homepage<http:// epydoc.sourceforge.net>} - U{The B{Python} homepage <www.python.org>} - U{Edward Loper<mailto:edloper@ gradient.cis.upenn.edu>} """ #[...] |
The inline markup construct 'L{text<object>}' is used to create links to the documentation for other Python objects. 'text' is the text that should be displayed for the link, and 'object' is the name of the Python object that should be linked to. If you wish to use the name of the Python object as the text for the link, you can simply write L{object}``. Whitespace within object names is ignored. In particular, object names may be split over multiple lines. The following example illustrates how documentation crossreference links can be used:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ - L{x_transform} - L{search<re.search>} - L{The I{x-transform} function <x_transform>} """ #[...] |
In order to find the object that corresponds to a given name, epydoc checks the following locations, in order:
If no object is found that corresponds with the given name, then epydoc issues a warning.
Epydoc automatically creates an index of term definitions for the API documentation. The inline markup construct 'X{...}' is used to mark terms for inclusion in the index. The term itself will be italicized; and a link will be created from the index page to the location of the term in the text. The following example illustrates how index terms can be used:
| Docstring Input | Rendered Output | ||||||||
|---|---|---|---|---|---|---|---|---|---|
def example(): """ An X{index term} is a term that should be included in the index. """ #[...] |
An index term is a term that should be included in the index.
|
||||||||
Symbols are used to insert special characters in your documentation. A symbol has the form 'S{code}', where code is a symbol code that specifies what character should be produced. The following example illustrates how symbols can be used to generate special characters:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ Symbols can be used in equations: - S{sum}S{alpha}/x S{<=} S{beta} S{<-} and S{larr} both give left arrows. Some other arrows are S{rarr}, S{uarr}, and S{darr}. """ #[...] |
Symbols can be used in equations:
← and ← both give left arrows. Some other arrows are →, ↑, and ↓. |
Although symbols can be quite useful, you should keep in mind that they can make it harder to read your docstring in plaintext. In general, symbols should be used sparingly. For a complete list of the symbols that are currently supported, see the reference documentation for epytext.SYMBOLS.
Escaping is used to write text that would otherwise be interpreted as epytext markup. Epytext was carefully constructed to minimize the need for this type of escaping; but sometimes, it is unavoidable. Escaped text has the form 'E{code}', where code is an escape code that specifies what character should be produced. If the escape code is a single character (other than '{' or '}'), then that character is produced. For example, to begin a paragraph with a dash (which would normally signal a list item), write 'E{-}'. In addition, two special escape codes are defined: 'E{lb}' produces a left curly brace ('{'); and 'E{rb}' produces a right curly brace ('}'). The following example illustrates how escaping can be used:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ This paragraph ends with two colons, but does not introduce a literal blockE{:}E{:} E{-} This is not a list item. Escapes can be used to write unmatched curly braces: E{rb}E{lb} """ #[...] |
This paragraph ends with two colons, but does not introduce a literal block:: - This is not a list item. Escapes can be used to write unmatched curly braces: }{ |
The inline markup construct 'G{graphtype args...}' is used to insert automatically generated graphs. The following graphs generation constructions are currently defines:
| Markup | Description |
|---|---|
| G{classtree classes...} | Display a class hierarchy for the given class or classes (including all superclasses & subclasses). If no class is specified, and the directive is used in a class's docstring, then that class's class hierarchy will be displayed. |
| G{packagetree modules...} | Display a package hierarchy for the given module or modules (including all subpackages and submodules). If no module is specified, and the directive is used in a module's docstring, then that module's package hierarchy will be displayed. |
| G{importgraph modules...} | Display an import graph for the given module or modules. If no module is specified, and the directive is used in a module's docstring, then that module's import graph will be displayed. |
| G{callgraph functions...} | Display a call graph for the given function or functions. If no function is specified, and the directive is used in a function's docstring, then that function's call graph will be displayed. |
Valid characters for an epytext docstring are space (\040); newline (\012); and any letter, digit, or punctuation, as defined by the current locale. Control characters (\000-\010` and ``\013-\037) are not valid content characters. Tabs (\011) are expanded to spaces, using the same algorithm used by the Python parser. Carridge-return/newline pairs (\015\012) are converted to newlines.
Characters in a docstring that are not involved in markup are called content characters. Content characters are always displayed as-is. In particular, HTML codes are not passed through. For example, consider the following example:
| Docstring Input | Rendered Output |
|---|---|
def example(): """ <B>test</B> """ #[...] |
<B>test</B> |
The docstring is rendered as <B>test</B>, and not as the word "test" in bold face.
In general, spaces and newlines within docstrings are treated as soft spaces. In other words, sequences of spaces and newlines (that do not contain a blank line) are rendered as a single space, and words may wrapped at spaces. However, within literal blocks and doctest blocks, spaces and newlines are preserved, and no word-wrapping occurs; and within URL targets and documentation link targets, whitespace is ignored.
Fields are used to describe specific properties of a documented object. For example, fields can be used to define the parameters and return value of a function; the instance variables of a class; and the author of a module. Each field consists of a tag, an optional argument, and a body.
Each docstring markup langauge marks fields differently. The following table shows the basic fields syntax for each markup language. For more information, see the definition of field syntax for each markup language.
| Epytext | reStructuredText | Javadoc |
|---|---|---|
@tag: body... @tag arg: body... |
:tag: body... :tag arg: body... |
@tag body... @tag arg body... |
| Definition of epytext fields | Definition of ReStructuredText fields | Definition of Javadoc fields |
The following table lists the fields that epydoc currently recognizes. Field tags are written using epytext markup; if you are using a different markup language, then you should adjust the markup accordingly.
These tags can be used to specify attributes of parameters and return value of function and methods. These tags are usually put in the the docstring of the function to be documented.
Note
constructor parameters
In C extension modules, extension classes cannot have a docstring attached to the __init__ function; consequently it is not possible to document parameters and exceptions raised by the class constructor. To overcome this shortcoming, the tags @param, @keyword, @type, @exception are also allowed to appear in the class docstring. In this case they refer to constructor parameters.
@param fields should be used to document any explicit parameter (including the keyword parameter). @keyword fields should only be used for non-explicit keyword parameters:
def plant(seed, *tools, **options): """ @param seed: The seed that should be planted. @param tools: Tools that should be used to plant the seed. @param options: Any extra options for the planting. @keyword dig_deep: Plant the seed deep under ground. @keyword soak: Soak the seed before planting it. """ #[...]
Since the @type field allows for arbitrary text, it does not automatically create a crossreference link to the specified type, and is not written in fixed-width font by default. If you want to create a crossreference link to the type, or to write the type in a fixed-width font, then you must use inline markup:
def ponder(person, time): """ @param person: Who should think. @type person: L{Person} or L{Animal} @param time: How long they should think. @type time: C{int} or C{float} """ #[...]
These tags are usually put in a module or class docstring. If the sources can be parsed by Epydoc it is also possible to document the variable in their own docstrings: see variable docstrings
Epydoc considers class variables the ones defined directly defined in the class body. A common Python idiom is to create instance variables settings their default value in the class instead of the constructor (hopefully if the default is immutable...).
If you want to force Epydoc to classify as instance variable one whose default value is set at class level, you can describe it using the tag @ivar in the context of a variable docstring:
class B: y = 42 """@ivar: This is an instance variable."""
The @type tag can be attached toa property docstring to specify its type.
These tags can be used to present groups of related items in a logical way. They apply to modules and classes docstrings.
For the @group and @sort tags, asterisks (*) can be used to specify multiple children at once. An asterisk in a child name will match any substring:
class widget(size, weight, age): """ @group Tools: zip, zap, *_tool @group Accessors: get_* @sort: get_*, set_*, unpack_*, cut """ #[...]
Note
group markers
It is also possible to group set of related items enclosing them into special comment starting with the group markers '#{' and '#}' The group title can be specified after the opening group marker. Example:
#{ Database access functions def read(id): #[...] def store(item): #[...] def delete(id): #[...] # groups can't be nested, so a closing marker is not required here. #{ Web publish functions def get(request): #[...] def post(request): #[...] #}
A description of a bug in an object. Multiple bug fields may be used to report separate bugs.
Note
If any @bug field is used, the HTML writer will generate a the page bug-index.html, containing links to all the items tagged with the field.
A planned change to an object. If the optional argument ver is given, then it specifies the version for which the change will be made. Multiple todo fields may be used if multiple changes are planned.
Note
If any @todo field is used, the HTML writer will generate a the page todo-index.html, containing links to all the items tagged with the field.
Several fields have synonyms, or alternate tags. The following table lists all field synonyms. Field tags are written using epytext markup; if you are using a different markup language, then you should adjust the markup accordingly.
| Name | Synonims |
|---|---|
| @param p: ... | @parameter p: ...
@arg p: ...
@argument p: ...
|
| @return: ... | @returns: ... |
| @rtype: ... | @returntype: ... |
| @raise e: ... | @raises e: ...
@except e: ...
@exception e: ...
|
| @keyword p: ... | @kwarg p: ...
@kwparam p: ...
|
| @ivar v: ... | @ivariable v: ... |
| @cvar v: ... | @cvariable v: ... |
| @var v: ... | @variable v: ... |
| @see: ... | @seealso: ... |
| @warning: ... | @warn: ... |
| @requires: ... | @require: ...
@requirement: ...
|
| @precondition: ... | @precond: ... |
| @postcondition: ... | @postcond: ... |
| @organization: ... | @org: ... |
| @copyright: ... | @(c): ... |
| @change: ... | @changed: ... |
Some module variables are commonly used as module metadata. Epydoc can use the value provided by these variables as alternate form for tags. The following table lists the recognized variables and the tag they replace. Customized metadata variables can be added using the method described in Adding New Fields.
| Tag | Variable |
|---|---|
| @author | __author__ |
| @authors | __authors__ |
| @contact | __contact__ |
| @copyright | __copyright__ |
| @license | __license__ |
| @deprecated | __deprecated__ |
| @date | __date__ |
| @version | __version__ |
New fields can be defined for the docstrings in a module using the special @newfield tag (or its synonym, @deffield). This tag has the following syntax:
@newfield tag: label [, plural ]
Where tag is the new tag that's being defined; label is a string that will be used to mark this field in the generated output; and plural is the plural form of label, if different.
New fields can be defined in any Python module. If they are defined in a package, it will be possible to use the newly defined tag from every package submodule.
Each new field will also define a metadata variable which can be used to set the field value instead of the tag. For example, if a revision tag has been defined with:
@newfield revision: Revision
then it will be possible to set a value for the field using a module variable:
__revision__ = "1234"
The following example illustrates how the @newfield can be used: Docstring Input Rendered Output
| Docstring Input | Rendered Output |
|---|---|
""" @newfield corpus: Corpus, Corpora """ def example(): """ @corpus: Bob's wordlist. @corpus: The British National Corpus. """ [...] |
Corpora:
|
Note
The module-level variable __extra_epydoc_fields__ is deprecated; use @newfield instead.
Epydoc's default markup language is epytext, a lightweight markup language that's easy to write and to understand. But if epytext is not powerful enough for you, or doesn't suit your needs, epydoc also supports three alternate markup languages:
To specify the markup language for a module, you should define a module-level string variable __docformat__, containing the name of the module's markup language. The name of the markup language may optionally be followed by a language code (such as en for English). Conventionally, the definition of the __docformat__ variable immediately follows the module's docstring:
# widget.py """ Graphical support for `gizmos` and `widgets`. """ __docformat__ = "restructuredtext en" #[...]
To change the default markup language from the command line, use the --docformat option. For example, the following command generates API documentation for the existing regular expression package re, which uses plaintext markup:
[epydoc]$ epydoc --docformat plaintext re
reStructuredText is a markup language that was developed in conjunction with Docutils. In order to parse reStructuredText docstrings, Docutils 0.3 or higher must be installed. If Docutils is not installed, then reStructuredText docstrings will be rendered as plaintext. Docutils can be downloaded from the Docutils SourceForge page.
Epydoc replaces the Docutils' default interpreted text role with the creation of documentation crossreference links. If you want to create a crossreference link to the somemod.Example class, you can put backquotes around your test, typing:
`somemod.Example`
In addition to the standard set of fields, the reStructruedText parser also supports consolidated fields, which combine the documentation for several objects into a single field. For example, a single :Parameters: field is often used to describe all of the parameters for a function or method:
def fox_speed(size, weight, age): """ Return the maximum speed for a fox. :Parameters: - `size`: The size of the fox (in meters)