Whether you’re creating simple Python scripts or extensive Jupyter notebooks. As a Python Developer or Data Scientist, you need the right tools to create the best possible quality of code.
I’ve tested and reviewed more than hundreds of extensions for Python for this article and curated my findings to a list that contain the 10 best VS Code extensions for Python developers to save time writing code.
So let’s get to it! Here are 10 must-have essential Visual Studio Code extensions for Python:
Table of Contents
What are the best VS Code extensions for Python development?
1. Python by Microsoft
This VS Code extension published by Microsoft has rich support for Python. It contains the following features:
- Linting for your code with Pylint or Flake8 support
- Debugging your code within the VS Code editor
- IntelliSense support for auto-completion, code navigation, and formatting.
- Support for Jupyter Notebooks, Pytest, and Unittests
- Easily switch Python environments within the editor
Pylance is an incredibly fast static type checker and adds comprehensive feature-rich language support for Python. Basically, this is the official successor to the Pyright extension that got released back in 2019.
This extension includes the following features:
- Intelligent type completion of keywords, symbols, and import names
- Automatically insert import statements for type completions when necessary
- Show docstrings and type information when you hover over symbols
- Quickly find the location of the symbol’s definition when you click on the hover over the symbols.
- Quickly find or rename all references to a symbol within a codebase
- Automatically reorder imports in your code according to PEP8 rules.
- Third-party libraries have support for type stub generation
- As-you-type reporting of code errors and warnings (diagnostics)
- Code navigation
- Native multi-root workspace support
- IntelliCode compatibility
- Jupyter Notebooks compatibility
- Semantic highlighting
3. Visual Studio IntelliCode
This is a standalone extension that provides AI-assisted IntelliSense. As you might have noticed, the first extension on this list also contains IntelliSense.
But in my experience, I find that this extension works better because it scans your code using AI and then does a better job with autocomplete than the Python extension from Microsoft.
4. Sort lines
Like the name suggests it sorts lines of text. This can be handy if you import a lot of libraries in your scripts and don’t want to reorganize them manually. if you want to have them in alphabetical order for example.
You can sort your code in the following ways:
|Sort lines functionality
|Ascending, case-sensitive (default)
|Unique ascending, case-sensitive
|Line length ascending
|Line length descending
|Sorts alphabetically except groups with multi-digit numbers
|Regular character code keeping only unique items
|Removes duplicate lines
To invoke the Sort lines functionality type the following command
CMD + Shift + P -> Sort Lines
My most used sort function when I code in Python is
Natural which Sorts alphabetically but groups multi-digit numbers.
5. Black Formatter
Black Formatter allows you to format your code using one of the most used Python formatters “Black”. Having a formatter in place improves productivity when working on Python projects with multiple developers.
That’s because the formatter is PEP8 compliant and makes sure the code style stays consistent through the projects and saves you time by not having discussions in pull requests about how the code should be formatted.
In order to enable Black as the default formatter of your Python code, you should add the following values in your vscode settings:
6. Indent rainbow
Indent rainbow adds colors to your indents which makes readability even better, especially in a dark background like in VS Code.
Combine this with Indenticator to improve the reading fluency of your code.
You have the option to customize the indent colors to your liking by adding the following values in your vscode settings:
// Defining custom colors instead of default "Rainbow" for dark backgrounds.
// The indent color if the number of spaces is not a multiple of "tabSize".
// The indent color when there is a mix between spaces and tabs.
// To be disabled this coloring set this to an empty string.
7. Bracket Pair Colorizer 2
This VS Code extension allows you to colorize the brackets in your code so you can easily identify which brackets belong to each other.
Whenever I review JSON files for example (which contain a lot of brackets), this tool makes validating the file a lot quicker.
Update: Bracket Pair Colorizer has become a native VS Code feature. This means you don’t need to download a separate extension anymore.
To turn on the native bracket pair colorization, do the following:
- In VSCode, go under the File Menu -> Preferences -> Settings
- Search for the setting: bracketPair
- Click the checkbox to turn on the bracket pair colorization
Sourcery is an AI-powered coding assistant that helps you to write better Python code faster. It works by providing refactoring suggestions on the fly that you can instantly integrate into your code. This will tremendously improve code quality when it gets implemented into your python vscode project.
9. Python Docstring Generator
The Python Docstring Generator extension allows you to quickly generate docstrings for your python functions.
Essentially it is a template that you can use to add extensive comments to your code.
To initiate a new docstring in Python, start the line with triple quotes (
""") to generate the template.
This is absolutely a necessary extension when you need to refer to the official Python documentation while you’re coding.
This VS Code extension allows you to invoke Dash from the editor. So if you need to get more information about Classes, Functions, or Types you highlight the code and press
ctrl + h to access the official documentation offline.
If you compare this to going in the browser and visiting the official documentation website to search for the API, it goes a lot quicker doing it offline.
The benefit of having your docs offline is that you don’t need to have internet access in order to start coding and looking up references.
Finding pages that are stored locally can be accessed way quicker than trying to google and needing to find the specific thing you’re looking for.
These benefits boost your productivity and allow you to focus more on the coding part.
Additional python extension: Git Lens
If you’re developing Python projects or any project in general, then there’s a big chance you’re using git. The extension: GitLens improves the git functionality in VS Code. A couple of notable features that are worth mentioning are:
- git blame – shows who modified each line within a file
- git changes – highlights any local (unpublished) changes or lines changed by the most recent commit
- git revision navigation – shows the git history of a file and allows you to effortlessly navigate it
One of my favorite features is git blame. This feature shows author metadata attached to specific committed lines in a file.
This is helpful when you’re collaborating with other developers on the same project. Because it allows you to see who changed what within the code.
Their feature list is very comprehensive, if you want to see what it can do, please check out their readme on the VS Code marketplace.
To summarize, as a Python developer it can be a daunting task to find the right VS Code extensions to improve your workflow and productivity.
Therefore I created this list containing the 11 best VS Code extensions for Python including Python by Microsoft, Pylance, Visual Studio IntelliCode, Sort lines, Black Formatter, indent rainbow, bracket pair colorizer 2, Sourcery, Python docstring generator, Dash, and Git lens.
You’re daily productivity and focus will improve and next to that your code is less prone to bugs because of the guardrails and highlights that are present in these VS Code extensions.