Docly: Generate Comments Automatically for Python Code | by Satyam Kumar | Towards Data Science

Artificial Intelligence is extensively used for developing models to help developers write better source code. Various AI models are used to accelerate the work of developers, such as code autocompletion, autosuggestions, unit test assistance, bug detection, code summarization, etc.
Documentation of code is essential while delivering the project. For large code snippets having thousands of lines of code, it's very difficult to understand the code functionality for the next set of developers, testers, or clients, and hence code documentation of comments is essential. Most of the developers find it difficult or forget to write documentation or comments.
It is a big challenge for the developers to cope up with writing code, testing the code, and keeping up with its documentation. Docly comes to the rescue, as it automatically generates documentation for python code using state-of-the-art natural language processing.
Docly is a python package by Codist.AI that can automatically generate documentation for your python code. It extensively used natural language processing to go through all the functions in the code snippet and generate docstring or comments automatically and can also update any missing or outdated docstring.
Docly is provided in the command-line interface and can review or complete the documentation in one-line command in few seconds.
Pypl installation for the required packages.
pip install -U PyYAMLpip install docly
To generate documentation of a given python code snippet, use a single line of the command-line statement:
docly-gen <name_of_python_file.py>
After the docly engine is loaded and the docstring is generated, it will seek permission to show the suggestions.
Taking input as ‘y’, it generates all the function names in the code snippets along with the generated docstring for each function.
If you want to edit and add these suggested docstrings to the original python file, return input with ‘y’. It adds the suggested docstring to each of the functions with the arguments in the first line of each function.
In the modified python script, the generated docstring is edited and added inside each function.
Format of docstring (Inside ‘‘‘ --- ’’’):
Each of the docstring contains a comment that signifies what that function holistically.
It also specifies the input arguments (parameters) for their respective functions.
In the last, it generates its credit statement: (Generated by docly)\
To revert back to the applied changes then below-mentioned command line statement:
docly-restore
As of December 2020, Docly library is currently in the beta stage and free to use. Docly uses natural language processing to understand what each of the functions is doing and generates docstring accordingly.
It is currently in the initial stage but still, it does amazing work in analyzing and providing great insights by documentation the functions. There are a lot of drawbacks to generating the comments for function arguments. Still, it's a great package to generate insights and saves a lot of developers time.
[1] Codist.AI website: https://codist-ai.com/
[2] PyPl documentation for docly: https://pypi.org/project/docly/
Thank You for Reading