How to generate a documentation using Python?
Documentation improves the readability of the code. There are many tools that help us to create documentations. One such tool is pdoc to write documentation for python projects.
Installation: Run the following pip command on the terminal.
pip3 install pdoc3
Now navigate (through command line) to the folder where our Python program is kept. Let’s say the name of our program is Numbers.py. It is a simple class that has 2 functions, one to find the factorial of the number and another to check whether the number is a prime number or not.
Adding docstrings in classes and methods provide a convenient way of associating documentation with Python modules, functions, classes, and methods. Docstrings are an important part of the documentation.
After navigating to the folder(through command line) where our code (Numbers.py) is kept. We have to type this command in the terminal:
pdoc --html Numbers.py
After firing the –html command shown above, an HTML folder will be created in the directory where Numbers.py is kept. Inside that HTML folder, a file called Numbers.html will be created. Navigate to HTML folder and open Numbers.html.
Numbers.html should be looking like this. We just created proper documentation of our class Numbers. In the left column(Index) of Number.html, classes and it’s methods are seen. Remember the docstrings which we wrote, they are available below their respective classes and methods.