Package: autodocstrings
autodocstringsSource Code:https://github.com/cdesarmeaux/autodocstringsAutodocstrings is a command-line tool with the following key features:Updates the docstrings in Python files using the OpenAI API.Can process a single file or a directory of files, including all subdirectories.Autodocstrings uses the OpenAI api to generate docstrings, so these are not guaranteed to be perfect. However, they are a good starting point for writing your own docstrings.The code-davinci-002 model is used to generate the docstrings. This model is trained on a large corpus of Python code, including docstrings. The model is able to generate docstrings that are similar to those found in the corpus.Autodocstrings will work best for code that already has good type hints. Without type hints, the OpenAI API will have to guess input and return types, which may not be accurate.RequirementsPython 3.6+A valid openai api key. You can get onehere. This is currently free.Installation$pipinstallautodocstringsInstallationTo install the dependencies for this tool, run the following command:pip install autodocstringsUsageTo use this tool, run the following commands:$exportOPENAI_API_KEY=1234567890$pythonupdate_docstrings.pyINPUT`[--replace-existing-docstrings] `[--skip-constructor-docstrings] `[--exclude-directories EXCLUDE_DIRECTORIES] `[--exclude-files EXCLUDE_FILES]Where INPUT is a Python file or directory containing Python files to update the docstrings in, API_KEY is your OpenAI API key, and the optional flags --replace-existing-docstrings and --skip-constructor-docstrings can be used to skip updating docstrings for constructors (initmethods) and replacing existing docstirngs. EXCLUDE_DIRECTORIES and EXCLUDE_FILES are comma-separated lists of directories and files to exclude from the update.ExamplesUpdate the docstrings in all Python files in the my_code directory:$pythonupdate_docstrings.pymy_code/Update the docstrings in the my_file.py file:$pythonupdate_docstrings.pymy_file.pyUpdate the docstrings in all Python files in the my_code directory and replace existing ones:$pythonupdate_docstrings.pymy_code/--replace-existing-docstringsUpdate the docstrings in all Python files in the my_code directory, but skip updating docstrings for class constructors (initmethods):$pythonupdate_docstrings.pymy_code/--skip-constructor-docstringsUpdate the docstrings in all Python files in the my_code directory, but exlcude the exclude_dir directory and the exclude_file_1.py and exclude_file_2.py files:$pythonupdate_docstrings.pymy_code/--exclude-directoriesexclude_dir--exclude-filesexclude_file_1.py,exclude_file_2.pyLicenseThis project is licensed under the MIT License. See the LICENSE file for details.LimitationsThe python functions are being passed to the OpenAI API as independent code blocks. This means that the docstrings are not aware of the context of the function. If functions are written independently of each other, then this should not be a problem.The format of the docstring is not always consistent, so you may need to manually fix some of the docstrings. You shouldn't use this in a ci/cd pipeline.Input length is limited to the maximum input length of the OpenAI API. This is currently 2048 characters. If your function is larger than this then the docstring will not be updated.OpenAI API can be slow.