Best VS Code Extensions for Python Development
Published: September 25, 2024 | Reading time: 10 minutes
Essential Python Extensions
Transform VS Code into a powerful Python IDE with these must-have extensions:
# Install these essential extensions:
- Python (Microsoft)
- Pylance
- Python Debugger
- autoDocstring
- Python Indent
- Python Test Explorer
- Jupyter
- Python Environment Manager
Core Python Development Extensions
1. Python (Microsoft)
The official Python extension by Microsoft provides IntelliSense, debugging, and more.
Python Extension Features:
- IntelliSense and auto-completion
- Linting with Pylint, Flake8, mypy
- Code formatting with Black, autopep8
- Debugging support
- Jupyter notebook support
- Environment management
- Refactoring tools
2. Pylance
Fast, feature-rich language server for Python with type checking and IntelliSense.
// settings.json
{
"python.analysis.typeCheckingMode": "basic",
"python.analysis.autoImportCompletions": true,
"python.analysis.diagnosticMode": "workspace",
"python.analysis.stubPath": "./typings"
}
3. Python Debugger
Debug Python applications with breakpoints, variable inspection, and call stack.
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": ["runserver"],
"django": true
}
]
}
Code Quality and Formatting
4. Black Formatter
Opinionated Python code formatter for consistent code style.
// settings.json
{
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["--line-length=88"],
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}
5. Flake8
Style guide enforcement and error detection for Python code.
# Install flake8
pip install flake8
# .flake8 configuration
[flake8]
max-line-length = 88
extend-ignore = E203, W503
exclude = .git,__pycache__,venv,env
6. mypy
Static type checker for Python that helps catch type-related errors.
# pyproject.toml
[tool.mypy]
python_version = "3.9"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
strict_optional = true
Documentation and Testing
7. autoDocstring
Generate Python docstrings automatically for functions, classes, and methods.
# Google style docstring
def calculate_total(items: List[Item]) -> float:
"""Calculate the total price of items.
Args:
items: List of items to calculate total for
Returns:
Total price as float
Raises:
ValueError: If items list is empty
"""
pass
8. Python Test Explorer
Run and debug Python tests with a visual test explorer interface.
// settings.json
{
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.autoTestDiscoverOnSaveEnabled": true
}
Data Science and Jupyter
9. Jupyter
Run Jupyter notebooks directly in VS Code with full IntelliSense support.
Jupyter Extension Features:
- Interactive notebook editing
- Variable inspector
- Plot viewer
- Kernel management
- Export to Python scripts
- IntelliSense in cells
10. Python Environment Manager
Manage Python virtual environments and interpreters easily.
# Create virtual environment
python -m venv myenv
# Activate environment
# Windows:
myenv\Scripts\activate
# macOS/Linux:
source myenv/bin/activate
# Install packages
pip install -r requirements.txt
Productivity Extensions
11. Python Indent
Correctly indent Python code according to PEP 8 standards.
12. Python Snippets
Quick code snippets for common Python patterns and structures.
# Type 'def' and press Tab
def function_name(self):
"""Docstring for the function."""
pass
# Type 'class' and press Tab
class ClassName:
"""Docstring for the class."""
def __init__(self):
pass
13. Python Type Hint
Add type hints to Python functions automatically.
Django and Flask Extensions
14. Django
Django-specific IntelliSense, snippets, and debugging support.
// settings.json
{
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--load-plugins=pylint_django"
],
"files.associations": {
"*.html": "django-html"
}
}
15. Flask Snippets
Code snippets and IntelliSense for Flask web development.
Advanced Features
16. Python Docstring Generator
Generate comprehensive docstrings with multiple formats.
17. Python Imports
Automatically organize and optimize Python imports.
# Before
import os
import sys
from django import forms
import requests
# After (organized)
import os
import sys
import requests
from django import forms
Recommended Settings
// settings.json
{
"python.defaultInterpreterPath": "./venv/bin/python",
"python.terminal.activateEnvironment": true,
"python.analysis.extraPaths": ["./src"],
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.provider": "black",
"python.testing.pytestEnabled": true,
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"files.exclude": {
"**/__pycache__": true,
"**/*.pyc": true
}
}
Summary
These VS Code extensions will transform your Python development experience:
- Core: Python, Pylance, Python Debugger
- Quality: Black, Flake8, mypy
- Documentation: autoDocstring, Python Docstring Generator
- Testing: Python Test Explorer
- Data Science: Jupyter
- Productivity: Python Indent, Snippets, Environment Manager
Need More Help?
Want to optimize your Python development workflow or need help with specific extensions? Our Python experts can help you set up the perfect development environment.
Get Python Help