This extension utilizes the pre-trained model CodeBERT, which can handle programming languages and natural language, to quickly generate Python docstrings.
Visual Studio Code (VS Code) is a free code editor developed by Microsoft that supports operating systems such as Windows, Linux, and macOS. It supports testing and has built-in Git version control capabilities, along with development environment features like code completion, snippets, and refactoring. VS Code is one of the commonly used code editors among programmers and is an open-source, extensible, and lightweight editor that works across all platforms. These qualities have made Microsoft’s VS Code very popular and an excellent platform for Python development.
Additionally, VS Code has a large number of extensions that can help improve development efficiency and enhance developer satisfaction. Today, we will introduce a VS Code extension that can generate Python docstrings.
This extension uses AI (NLP) technology to quickly generate docstrings for Python functions. Originally, the description of Python functions had to be written by the user, but with this extension, AI can review the code and summarize it.
Specifically, this extension uses the pre-trained model CodeBERT proposed by Microsoft and others, which can handle bimodal data: natural language and programming language.
During the training process, this extension used the CodeSearchNet corpus created by the GitHub team as training data and employed the Code2NL (code to natural language) fine-tuning task within CodeBERT. The inference benchmarks for this extension are shown below:

This VS Code extension has the following features:
-
AI quickly generates docstrings;
-
Supports multiple different types of docstring formats;
-
Infers parameter types through pep484 type hints, default values, and variable names;
-
Supports args, kwargs, decorators, errors, and parameter types.
Supported docstring formats include: Google (default), docBlockr, Numpy, Sphinx, and the project homepage indicates that this extension will soon support PEP0257.
The use of this VS Code extension is relatively simple. Users only need to run the model inference server from a container and install the extension in VS Code to use it.
The specific steps are as follows:
1. Run the model inference server from a container
-
If you have a GPU machine: After installing nvidia-docker, run docker run -it -d –gpus 0 -p 5000:5000 graykode/ai-docstring:gpu;
-
If you only have a CPU: Use Google Colab and ngrok to run a Flask server (recommended) or use the docker CPU image: docker run -it -d -p 5000:5000 graykode/ai-docstring:cpu.
2. Install the extension in VS Code and use it
The cursor must be below the definition to generate a fully auto-filled docstring.
-
Open the docstring with triple quotes (“”” or ”’), then press Enter;
-
Keyboard shortcut: ctrl+shift+2, for Mac the shortcut is cmd+shift+2;
-
Command: Generate Docstring;
-
Right-click menu: Generate Docstring.

The author of this project is Tae-Hwan Jung, an undergraduate in Computer Engineering from Kyung Hee University in South Korea. He is interested in open-source culture and believes that a good project can give rise to new industries and technologies.
Personal Homepage: https://libraries.io/github/graykode
Amazon SageMaker 1000 YuanGift Package
ML training costs reduced by 90%, used by tens of thousands of companies worldwide, Amazon SageMaker is a fully managed machine learning platform that supports most machine learning frameworks and algorithms, allowing you to write code, visualize, and debug seamlessly with an IDE.
Now, we have prepared a free quota of 1000 Yuan for developers to experience hands-on, making it easier to develop high-quality models.
Click to read the original text, fill out the form, and we will contact you to complete the gift package recharge.

© THE END
For reprints, please contact this public account for authorization
Submissions or inquiries: [email protected]