Prettier does not support Python formatting. It is designed for languages like JavaScript, TypeScript, CSS, HTML, JSON, and others, but not Python.
For Python code formatting, use dedicated tools instead:
Black: The most popular and widely adopted Python formatter. It enforces a consistent, opinionated style with minimal configuration. Install via
pip install black. It supports Jupyter notebooks withpip install "black[jupyter]".Ruff: A modern, ultra-fast replacement for
flake8,pylint, andblack. It combines linting and formatting, supports Jupyter notebooks, and is significantly faster than older tools. Install viapip install ruffand configure in VS Code using thecharliermarsh.ruffextension.autopep8 or yapf: Alternative formatters that follow PEP 8 guidelines, offering more configurability than Black.
Setting Up Formatting in VS Code:
To avoid conflicts when using Prettier for web languages and Python formatters:
Disable Prettier as the default formatter for Python in
settings.json:"[python]": { "editor.defaultFormatter": null }Set your preferred Python formatter:
For Black:
"python.formatting.provider": "black", "python.formatting.blackArgs": ["--line-length=120"]For Ruff (recommended):
"editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.organizeImports": "explicit" }
✅ Tip: Ruff is the fastest and most modern choice for Python formatting and linting in 2026. It’s recommended over older tools like Black for new projects.
I just want to reformat everything so it's perfect. Is there anything like that in Python? What's the best?
Making a prettier GUI on Python program
automatic prettier for python code? (as in javascript) - Emacs Stack Exchange
Is there something like prettier for python? : learnpython
Which code formatter do you use?
Videos
If I disabled Prettier as the default formatter, it would not format on save anymore, but my Python would be formatted by autopep8 on save. With this in mind, the following solution worked for me to have both Prettier working for other languages and autopep8 for Python:
{
"workbench.iconTheme": "vscode-icons",
"workbench.editorAssociations": [
{
"viewType": "jupyter.notebook.ipynb",
"filenamePattern": "*.ipynb"
}
],
"git.confirmSync": false,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"python.formatting.provider": "autopep8",
"explorer.confirmDelete": false,
"python.showStartPage": false,
"explorer.confirmDragAndDrop": false,
"python.linting.pylintArgs": ["--load-plugins=pylint_django"],
"javascript.updateImportsOnFileMove.enabled": "always",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[python]": {
"editor.defaultFormatter": "ms-python.python"
}
}
Let me know if somebody finds a better solution!
Meaningful config snippet from @round_circle's answer:
"[python]": {
"editor.defaultFormatter": "ms-python.python"
}
After adding it, autopep8 worked for python files.
» npm install prettier