In short: class attributes cannot have doc strings in the way that classes and functions have.

To avoid confusion, the term property has a specific meaning in python. What you're talking about is what we call class attributes. Since they are always acted upon through their class, I find that it makes sense to document them within the class' doc string. Something like this:

class Albatross(object):
    """A bird with a flight speed exceeding that of an unladen swallow.

    Attributes:
        flight_speed     The maximum speed that such a bird can attain.
        nesting_grounds  The locale where these birds congregate to reproduce.
    """
    flight_speed = 691
    nesting_grounds = "Throatwarbler Man Grove"

I think that's a lot easier on the eyes than the approach in your example. If I really wanted a copy of the attribute values to appear in the doc string, I would put them beside or below the description of each attribute.

Keep in mind that in Python, doc strings are actual members of the objects they document, not merely source code annotations. Since class attribute variables are not objects themselves but references to objects, they have no way of holding doc strings of their own. I guess you could make a case for doc strings on references, perhaps to describe "what should go here" instead of "what is actually here", but I find it easy enough to do that in the containing class doc string.

Answer from ʇsәɹoɈ on Stack Overflow
🌐
Python documentation
docs.python.org › 3 › tutorial › classes.html
9. Classes — Python 3.14.7 documentation
3.14.7 Documentation » · The Python Tutorial » · 9. Classes · | Theme · Auto · Light · Dark | Classes provide a means of bundling data and functionality together. Creating a new class creates a new type of object, allowing new instances ...
Top answer
1 of 6
135

In short: class attributes cannot have doc strings in the way that classes and functions have.

To avoid confusion, the term property has a specific meaning in python. What you're talking about is what we call class attributes. Since they are always acted upon through their class, I find that it makes sense to document them within the class' doc string. Something like this:

class Albatross(object):
    """A bird with a flight speed exceeding that of an unladen swallow.

    Attributes:
        flight_speed     The maximum speed that such a bird can attain.
        nesting_grounds  The locale where these birds congregate to reproduce.
    """
    flight_speed = 691
    nesting_grounds = "Throatwarbler Man Grove"

I think that's a lot easier on the eyes than the approach in your example. If I really wanted a copy of the attribute values to appear in the doc string, I would put them beside or below the description of each attribute.

Keep in mind that in Python, doc strings are actual members of the objects they document, not merely source code annotations. Since class attribute variables are not objects themselves but references to objects, they have no way of holding doc strings of their own. I guess you could make a case for doc strings on references, perhaps to describe "what should go here" instead of "what is actually here", but I find it easy enough to do that in the containing class doc string.

2 of 6
108

The other answers are very outdated. PEP-257 describes how you can use docstrings for attributes. They come after the attribute, weirdly:

String literals occurring elsewhere in Python code may also act as documentation. They are not recognized by the Python bytecode compiler and are not accessible as runtime object attributes (i.e. not assigned to __doc__), but two types of extra docstrings may be extracted by software tools:

  1. String literals occurring immediately after a simple assignment at the top level of a module, class, or __init__ method are called “attribute docstrings”.
class C:
    "class C doc-string"

    a = 1
    "attribute C.a doc-string (1)"

    b = 2
    "attribute C.b doc-string (2)"

It also works for type annotations like this:

class C:
    "class C doc-string"

    a: int
    "attribute C.a doc-string (1)"

    b: str
    "attribute C.b doc-string (2)"

VSCode supports showing these.

🌐
Real Python
realpython.com › documenting-python-code
Documenting Python Code: A Complete Guide – Real Python
July 17, 2026 - These are built-in strings that, when configured correctly, can help your users and yourself with your project’s documentation. Along with docstrings, Python also has the built-in function help() that prints out the objects docstring to the console. Here’s a quick example: ... >>> help(str) Help on class str in module builtins: class str(object) | str(object='') -> str | str(bytes_or_buffer[, encoding[, errors]]) -> str | | Create a new string object from the given object.
🌐
Lsst
developer.lsst.io › v › DM-7919 › docs › py_docs.html
Documenting Python APIs — LSST DM Developer Guide latest documentation
Note that the class docstring takes the place of a docstring for the __init__ method; __init__ has no docstring. We use reStructuredText to mark up and give semantic meaning to text in docstrings. ReStructuredText is lightweight enough to read in raw form, such as command line terminal printouts, but is also parsed and rendered with our Sphinx-based documentation build system.
🌐
Medium
medium.com › @syedar.sohail › docstring-and-why-is-it-important-python-classes-modules-and-functions-95fee5247ff5
Docstring and why is it important ? — Python Classes, Modules and Functions | by Sohail | Medium
October 30, 2022 - When the complexity of code increases, we are pushed to make our own classes that is okay but what if we wrote 1000 lines of code and we have given it to our colleague or shared the files privately or to a group in a organisation who wants to use our classes. Well, they may spend a lot of time figuring out what our class attributes might do, so to tackle this problem Python has something called ‘Docstrings’ to help us out.
🌐
Readthedocs
python-textbok.readthedocs.io › en › 1.0 › Classes.html
Classes — Object-Oriented Programming in Python 1 documentation
A class is a kind of data type, just like a string, integer or list. When we create an object of that data type, we call it an instance of a class. As we have already mentioned, in some other languages some entities are objects and some are not. In Python, everything is an object – everything ...
Find elsewhere
🌐
Lsst
developer.lsst.io › v › DM-5063 › docs › py_docs.html
Documenting Python Code — LSST DM Developer Guide latest documentation
When describing an argument in the description, enclose the name of the variable in single backticks (the default role in reST, which is Python-aware in docstrings). For the parameter types, be as precise as possible. Parameters ---------- filename : str Description of `filename`. copy : bool Description of `copy`. dtype : data-type Description of `dtype`. iterable : iterable object Description of `iterable`. shape : int or tuple of int Description of `shape`. files : list of str Description of `files`. For instances of classes, provide the full namespace to the class.
🌐
Sphinx
sphinx-doc.org › en › master › usage › domains › python.html
The Python Domain — Sphinx documentation
This is helpful in situations where documentation for things in a module is spread over multiple files or sections – one location has the py:module directive, the others only py:currentmodule. The following directives are provided for module and class contents: ... Describes a module-level function. The signature should include the parameters, together with optional type parameters, as given in the Python ...
🌐
Read the Docs
python-docx.readthedocs.io › en › latest › api › document.html
Document objects — python-docx 1.2.0 documentation
python-docx 1.2.0 documentation » · The main Document and related objects. docx.Document(docx: str | IO[bytes] | None = None) → DocumentObject[source]¶ · Return a Document object loaded from docx, where docx can be either a path to a .docx file (a string) or a file-like object. If docx is missing or None, the built-in default document “template” is loaded. class docx.document.Document[source]¶ ·
🌐
W3Schools
w3schools.com › python › python_classes.asp
Python Classes
Almost everything in Python is an object, with its properties and methods. A Class is like an object constructor, or a "blueprint" for creating objects.
🌐
Python
docs.python.org › 3 › builtins › functions.html
Built-in Functions — Python 3.14.7 documentation
If no argument is given, the interactive help system starts on the interpreter console. If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console.
🌐
Python
peps.python.org › pep-0008
PEP 8 – Style Guide for Python Code | peps.python.org
Class names should normally use the CapWords convention. The naming convention for functions may be used instead in cases where the interface is documented and used primarily as a callable.
Top answer
1 of 2
2

When authoring OOP code, it is very common to have a file that only contains one class, and nothing else.

This is common in some languages, and may be enforced, like in Java. However, it has very little to do with OOP and more to do with the fact that Java is a popular OOP language. I write/modify several classes in a single file every day (I'm a Python dev), it's a pretty common practice.

PEP8 says that all modules and all classes should have docstrings outlining what they do. But in this case, the module is simply a container for the class. If you put a description of the class, then the information is duplicated

Yes it would be duplicated if you're following a one class per file rule. You have some choices:

  1. Stop following the rule and allow multiple classes per file (especially if you're only following it because it is a perceived best practice)

  2. Just put the docstring in the class and forget the module level docstring. If it's only one class per module (and you strictly follow OOP), then everything will be in the class, so the module docstring will be fairly meaningless. It's perfectly okay to not follow PEP8 to the letter, and in general, it's better to just do what's best for your particular situation than blindly/dogmatically following a standard or best practice.

HTH.

P.S. If a linter is complaining, and this in turn is ruining your builds, there's usually options to turn off certain PEP8 requirements. For example, ignoring E501 (line length greater than 80 chars) is a common one I see that teams choose to ignore (if the pep8 module is your linter, you can do pep8 --ignore=E501, for instance)

2 of 2
2

Style guides like PEP-8 are not absolute laws that must be followed, but only guides:

However, know when to be inconsistent -- sometimes style guide recommendations just aren't applicable. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask!

— PEP 8

Where a module only contains one class, a module-level docstring is not helpful and you should probably leave it out. If you use a linter that requires this superfluous docstring, disable that linter policy for the current file.

If we read PEP-8 more closely, it recommends “docstrings for all public modules”. A module that only contains one class is usually not part of the public interface, you would instead re-export the class through an __init__.py file. Nevertheless, one class per module layouts are fairly rare in Python. You will likely have non-public helper functions or other closely related classes in the same file.

🌐
SourceForge
epydoc.sourceforge.net › manual-docstring.html
Python Docstrings
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.
🌐
Python How Tos
campbell-muscle-lab.github.io › howtos_Python › pages › documentation › best_practices › best_practices.html
Documentation Best Practices - Python How Tos
The Raises section is for documenting any errors the function might raise if any problems are encountered during its executation. If the function doesn’t raise any errors, don’t add the Raises section. ... class ClassName(BaseClassName): """[one line summary] [multiple line summary if needed] """ def __init__(self, first_param, second_param): """[one line summary] [multiple line summary if needed] Parameters ---------- [first param name] : [type] [description] [second param name] : [type] [description] [repeat for all parameters in the init function] Raises ------ [EXCEPTION THIS FUNCTION RAISES] [Why this function raises the exception] """
🌐
Python
docs.python.org › 3 › builtins › stdtypes.html
Built-in Types — Python 3.14.7 documentation
The following sections describe the standard types that are built into the interpreter. The principal built-in types are numerics, sequences, mappings, classes, instances and exceptions. Some colle...
🌐
Krython
krython.com › tutorial › python › class-documentation-docstrings-and-help
📘 Class Documentation: Docstrings and Help - Tutorial | Krython
July 4, 2025 - Parameters ---------- param1 : str The first parameter description param2 : int The second parameter description Returns ------- bool Description of return value Raises ------ ValueError If param2 is negative Notes ----- This style is common in scientific Python libraries. """ pass def sphinx_style(self, param1: str, param2: int) -> bool: """ Sphinx style docstring example. :param param1: The first parameter description :type param1: str :param param2: The second parameter description :type param2: int :returns: Description of return value :rtype: bool :raises ValueError: If param2 is negative
🌐
Mimo
mimo.org › glossary › python › docstrings
Mimo: The coding platform you need to learn Web Development, Python, and more.
Use Python docstrings to document functions, classes, and modules. Access them with help(), generate documentation, and improve code readability.