Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to document a python package

I know what's the standard way to document functions, classes and modules, but how do I document packages - do I put a docstring in __init__.py, or something else?

like image 958
olamundo Avatar asked Mar 07 '10 11:03

olamundo


People also ask

How do you declare a package in Python?

To tell Python that a particular directory is a package, we create a file named __init__.py inside it and then it is considered as a package and we may create other modules and sub-packages within it. This __init__.py file can be left blank or can be coded with the initialization code for the package.

How do I get the package of a document in Python?

You can use help() function to display the documentation. or you can choose method. __doc__ descriptor. Eg: help(input) will give the documentation on input() method.

What is the best documentation for Python?

Sphinx is far and away the most popular Python documentation tool. Use it. It converts reStructuredText markup language into a range of output formats including HTML, LaTeX (for printable PDF versions), manual pages, and plain text. There is also great, free hosting for your Sphinx docs: Read The Docs.


2 Answers

Yes, just like for a function or class comment, the first item in the __init__.py file should be a comment string:

"""
This is the xyz package.
"""

Now if you import the package, and use help(package), you will see your docstring. See more here: http://www.python.org/dev/peps/pep-0257/

like image 112
BrainCore Avatar answered Sep 28 '22 02:09

BrainCore


See PEP257

A package may be documented in the module docstring of the __ init __.py file in the package directory.

like image 31
Alexander Gessler Avatar answered Sep 28 '22 02:09

Alexander Gessler