Module pdoc

Module pdoc provides types and functions for accessing the public documentation of a Python module. This includes module level variables, modules (and sub-modules), functions, classes and class and instance variables. Docstrings are taken from modules, functions, and classes using special __doc__ attribute. Docstrings for any of the variables are extracted by examining the module's abstract syntax tree.

The public interface of a module is determined through one of two ways. If __all__ is defined in the module, then all identifiers in that list will be considered public. No other identifiers will be considered as public. Conversely, if __all__ is not defined, then pdoc will heuristically determine the public interface. There are two simple rules that are applied to each identifier in the module:

  1. If the name starts with an underscore, it is not public.

  2. If the name is defined in a different module, it is not public.

  3. If the name is a direct sub-module, then it is public.

Once documentation for a module is created, it can be outputted in either HTML or plain text using the covenience functions html and text, or the corresponding methods html and text.

Index

Module variables

var html_module_suffix

The suffix to use for module HTML files. By default, this is set to .m.html, where the extra .m is used to differentiate a package's index.html from a submodule called index.

var html_package_name

The file name to use for a package's __init__.py module.

var import_path

A list of paths to restrict imports to. Any module that cannot be found in import_path will not be imported. By default, it is set to a copy of sys.path at initialization.

var template_path

A list of paths to search for Mako templates used to produce the plain text and HTML output. Each path is tried until a template is found.

Functions

def html(module_name, docfilter=None, allsubmodules=False, external_links=False, link_prefix='')

Returns the documentation for the module module_name in HTML format. The module must be importable.

docfilter is an optional predicate that controls which documentation objects are shown in the output. It is a single argument function that takes a documentation object and returns True or False. If False, that object will not be included in the output.

If allsubmodules is True, then every submodule of this module that can be found will be included in the documentation, regardless of whether __all__ contains it.

If external_links is True, then identifiers to external modules are always turned into links.

If link_prefix is True, then all links will have that prefix. Otherwise, links are always relative.

def import_module(module_name)

A single point of truth for importing modules to be documented by pdoc. In particular, it makes sure that the top module in module_name can be imported by using only the paths in import_path.

If a module has already been imported, then its corresponding entry in sys.modules is returned. This means that modules that have changed on disk cannot be re-imported in the same process and have its documentation updated.

def text(module_name, docfilter=None, allsubmodules=False)

Returns the documentation for the module module_name in plain text format. The module must be importable.

docfilter is an optional predicate that controls which documentation objects are shown in the output. It is a single argument function that takes a documentation object and returns True of False. If False, that object will not be included in the output.

If allsubmodules is True, then every submodule of this module that can be found will be included in the documentation, regardless of whether __all__ contains it.

Classes

class Class

Representation of a class's documentation.

Ancestors (in MRO)

Instance variables

var cls

The class object.

var doc

A mapping from identifier name to a documentation object.

var doc_init

A special version of self.doc that contains documentation for instance variables found in the __init__ method.

var docstring

Inheritance: Doc.docstring

The docstring for this object. It has already been cleaned by inspect.cleandoc.

var module

Inheritance: Doc.module

The module documentation object that this object was defined in.

var name

Inheritance: Doc.name

The identifier name for this object.

var refname

Inheritance: Doc.refname

Returns an appropriate reference name for this documentation object. Usually this is its fully qualified path. Every documentation object must provide this property.

e.g., The refname for this property is pdoc.Doc.refname.

Methods

def __init__(self, name, module, class_obj)

Inheritance: Doc.__init__

 
def class_variables(self)

Returns all documented class variables in the class, sorted alphabetically as a list of Variable.

def functions(self)

Returns all documented static functions as Function objects in the class, sorted alphabetically.

def instance_variables(self)

Returns all instance variables in the class, sorted alphabetically as a list of Variable. Instance variables are attributes of self defined in a class's __init__ method.

def is_empty(self)

Inheritance: Doc.is_empty

Returns true if the docstring for this object is empty.

def methods(self)

Returns all documented methods as Function objects in the class, sorted alphabetically with __new__ and __init__ always coming first.

class Doc

A base class for all documentation objects.

A documentation object corresponds to something in a Python module that has a docstring associated with it. Typically, this only includes modules, classes, functions and methods. However, pdoc adds support for extracting docstrings from the abstract syntax tree, which means that variables (module, class or instance) are supported too.

A special type of documentation object External is used to represent identifiers that are not part of the public interface of a module. (The name "External" is a bit of a misnomer, since it can also correspond to unexported members of the module, particularly in a class's ancestor list.)

Ancestors (in MRO)

  • Doc
  • __builtin__.object

Instance variables

var docstring

The docstring for this object. It has already been cleaned by inspect.cleandoc.

var module

The module documentation object that this object was defined in.

var name

The identifier name for this object.

var refname

Returns an appropriate reference name for this documentation object. Usually this is its fully qualified path. Every documentation object must provide this property.

e.g., The refname for this property is pdoc.Doc.refname.

Methods

def __init__(self, name, module, docstring)
 
def is_empty(self)

Returns true if the docstring for this object is empty.

class External

A representation of an external identifier. The textual representation is the same as an internal identifier, but the HTML version will lack a link while the internal identifier will link to its documentation.

Ancestors (in MRO)

Instance variables

var docstring

Inheritance: Doc.docstring

The docstring for this object. It has already been cleaned by inspect.cleandoc.

var module

Inheritance: Doc.module

The module documentation object that this object was defined in.

var name

Inheritance: Doc.name

The identifier name for this object.

var refname

Inheritance: Doc.refname

Returns an appropriate reference name for this documentation object. Usually this is its fully qualified path. Every documentation object must provide this property.

e.g., The refname for this property is pdoc.Doc.refname.

Methods

def __init__(self, name)

Inheritance: Doc.__init__

 
def is_empty(self)

Inheritance: Doc.is_empty

Returns true if the docstring for this object is empty.

class Function

Representation of a function's documentation.

Ancestors (in MRO)

Instance variables

var cls

The Class documentation object if this is a method. If not, this is None.

var docstring

Inheritance: Doc.docstring

The docstring for this object. It has already been cleaned by inspect.cleandoc.

var func

The function object.

var method

Whether this function is a method or not.

Static class methods have this set to False.

var module

Inheritance: Doc.module

The module documentation object that this object was defined in.

var name

Inheritance: Doc.name

The identifier name for this object.

var refname

Inheritance: Doc.refname

Returns an appropriate reference name for this documentation object. Usually this is its fully qualified path. Every documentation object must provide this property.

e.g., The refname for this property is pdoc.Doc.refname.

Methods

def __init__(self, name, module, func_obj, cls=None, method=False)

Inheritance: Doc.__init__

 
def is_empty(self)

Inheritance: Doc.is_empty

Returns true if the docstring for this object is empty.

def params(self)

Returns a nicely formatted list of parameters to this function. This includes argument lists, keyword arguments and default values.

def spec(self)

Returns a nicely formatted spec of the function's parameter list. This includes argument lists, keyword arguments and default values.

class Module

Representation of a module's documentation.

Ancestors (in MRO)

Instance variables

var doc

A mapping from identifier name to a documentation object.

var docstring

Inheritance: Doc.docstring

The docstring for this object. It has already been cleaned by inspect.cleandoc.

var module

Inheritance: Doc.module

The module documentation object that this object was defined in.

var name

Inheritance: Doc.name

The identifier name for this object.

var refdoc

The same as doc, but maps fully qualified identifier names to documentation objects.

var refname

Inheritance: Doc.refname

Returns an appropriate reference name for this documentation object. Usually this is its fully qualified path. Every documentation object must provide this property.

e.g., The refname for this property is pdoc.Doc.refname.

Methods

def __init__(self, module, docfilter=None, allsubmodules=False)

Inheritance: Doc.__init__

Creates a Module documentation object given the actual module Python object.

docfilter is an optional predicate that controls which documentation objects are returned in the following methods: classes, functions, variables and submodules. The filter is propagated to the analogous methods on a Class object.

If allsubmodules is True, then every submodule of this module that can be found will be included in the documentation, regardless of whether __all__ contains it.

def classes(self)

Returns all documented module level classes in the module sorted alphabetically as a list of Class.

def descendents(self, cls)

Returns a descendent list of documentation objects for cls, which must be a documentation object.

The list will contain objects belonging to Class or External. Objects belonging to the former are exported classes either in this module or in one of its sub-modules.

def find_class(self, cls)

Given a Python cls object, try to find it in this module or in any of the exported identifiers of the submodules.

def find_ident(self, name)

Searches this module and all of its sub-modules for an identifier with name name in its list of exported identifiers according to pdoc. Note that unexported sub-modules are searched.

A bare identifier (without . separators) will only be checked for in this module.

The documentation object corresponding to the identifier is returned. If one cannot be found, then an instance of External is returned populated with the given identifier.

def functions(self)

Returns all documented module level functions in the module sorted alphabetically as a list of Function.

def html(self, external_links=False, link_prefix='', **kwargs)

Returns the documentation for this module as self-contained HTML.

If external_links is True, then identifiers to external modules are always turned into links.

If link_prefix is True, then all links will have that prefix. Otherwise, links are always relative.

kwargs is passed to the mako render function.

def is_empty(self)

Inheritance: Doc.is_empty

Returns true if the docstring for this object is empty.

def is_package(self)

Returns True if this module is a package.

Works by checking if __package__ is not None and whether it has the __path__ attribute.

def is_public(self, name)

Returns True if and only if an identifier with name name is part of the public interface of this module. While the names of sub-modules are included, identifiers only exported by sub-modules are not checked.

name should be a fully qualified name, e.g., pdoc.Module.is_public.

def is_submodule(self, name)

Returns True if and only if name starts with the full import path of self and has length at least one greater than len(self.name).

def mro(self, cls)

Returns a method resolution list of documentation objects for cls, which must be a documentation object.

The list will contain objects belonging to Class or External. Objects belonging to the former are exported classes either in this module or in one of its sub-modules.

def submodules(self)

Returns all documented sub-modules in the module sorted alphabetically as a list of Module.

def text(self)

Returns the documentation for this module as plain text.

def variables(self)

Returns all documented module level variables in the module sorted alphabetically as a list of Variable.

class Variable

Representation of a variable's documentation. This includes module, class and instance variables.

Ancestors (in MRO)

Instance variables

var cls

The Class documentation object if this is a method. If not, this is None.

var docstring

Inheritance: Doc.docstring

The docstring for this object. It has already been cleaned by inspect.cleandoc.

var module

Inheritance: Doc.module

The module documentation object that this object was defined in.

var name

Inheritance: Doc.name

The identifier name for this object.

var refname

Inheritance: Doc.refname

Returns an appropriate reference name for this documentation object. Usually this is its fully qualified path. Every documentation object must provide this property.

e.g., The refname for this property is pdoc.Doc.refname.

Methods

def __init__(self, name, module, docstring, cls=None)

Inheritance: Doc.__init__

 
def is_empty(self)

Inheritance: Doc.is_empty

Returns true if the docstring for this object is empty.


Documentation generated by pdoc with the UNLICENSE.