How to show instance attributes in sphinx doc?

Your variables are instance variables, not class variables.

Without attaching a docstring (or a #: “doc comment”) to the variables, they won’t be documented. You could do as follows:

class MyClass(object):
    """    
    Description for class 

    """

    def __init__(self, par1, par2):
        self.var1 = par1 #: initial value: par1
        self.var2 = par2 #: initial value: par2

    def method(self):
        pass

But I would prefer to include variable documentation by using info fields:

class MyClass(object):
    """    
    Description for class

    :ivar var1: initial value: par1
    :ivar var2: initial value: par2
    """

    def __init__(self, par1, par2):
        self.var1 = par1 
        self.var2 = par2 

    def method(self):
        pass

See also:

  • http://www.sphinx-doc.org/ext/autodoc.html#directive-autoattribute
  • How can I make Python/Sphinx document object attributes only declared in __init__?
  • Problems with autodoc and explicitly specified instance attributes

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)