There's probably no such thing as "perfect", but there are programs like " black " that ensure the code is formatted "correctly". Answer from JamzTyson on reddit.com
Reddit
reddit.com › r/learnpython › is there something like prettier for python?
r/learnpython on Reddit: Is there something like prettier for python?
April 7, 2024 -
I just want to reformat everything so it's perfect. Is there anything like that in Python? What's the best?
JetBrains
jetbrains.com › help › pycharm › prettier.html
Prettier | PyCharm Documentation
With PyCharm, you can format selected code fragments as well as entire files or directories using the Reformat with Prettier action. PyCharm adds this action as soon as you install Prettier as a dependency in your project or globally on your computer. You can configure Prettier to reformat specific files every time such file is changed and the changes are saved automatically or manually, refer to Run Prettier automatically on save. Also, Prettier can be set as default formatter for specific files.
Videos
02:11
How to use Prettier in VS Code - Code Formatting - YouTube
00:33
Extension of the Week: Prettier - YouTube
05:44
Format Python code ON SAVE in Visual Studio Code - YouTube
01:18
Enhance Python Code Formatting: Get Prettier Extension in VS Code ...
06:36
How to Format Python Code on Save in Visual Studio Code | Auto-Format ...
Prettier
prettier.io
Prettier · Opinionated Code Formatter · Prettier
Try It OnlineInstall Prettier · Limited edition tshirts are now available to buy! $10 per tshirt goes to maintain the project. An opinionated code formatter · Supports many languages · Integrates with most editors · Has few options » · Your code is formatted on save ·
Prettier
prettier.io › docs
What is Prettier? · Prettier
Prettier enforces a consistent code style (i.e. code formatting that won’t affect the AST) across your entire codebase because it disregards the original styling* by parsing it away and re-printing the parsed AST with its own rules that take the maximum line length into account, wrapping code when necessary.
DEV Community
dev.to › eegli › quick-guide-to-python-formatting-in-vs-code-2040
Quick Guide to Python Formatting in VS Code (2025) - DEV Community
February 1, 2025 - If you find this config in your settings, you've found the reason why autopep8, black or yapf are not working - The above configuration will choose Prettier to format Python, which is not supported. In your settings, make sure you override the default formatter for python like so:
Formatter.org
formatter.org › python-formatter
Python Formatter Online – Beautify and Format Python Code
Beautify and format Python code online to improve readability, fix indentation, and keep formatting consistent.
Minifier
minifier.org › python-beautifier
Python Beautifier - Format & Beautify Python Code Online
Python beautifier is a free online tool that automatically formats messy, unindented, or hard-to-read Python code into a clean, consistent format. It follows PEP8, the official Python style guide, to ensure best practices in code readability.
Top answer 1 of 5
43
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!
2 of 5
14
Meaningful config snippet from @round_circle's answer:
"[python]": {
"editor.defaultFormatter": "ms-python.python"
}
After adding it, autopep8 worked for python files.
GitHub
github.com › psf › black
GitHub - psf/black: The uncompromising Python code formatter · GitHub
Formatting becomes transparent after a while and you can focus on the content instead. Black makes code review faster by producing the smallest diffs possible. Watch the PyCon 2019 talk to learn more. Read the documentation on ReadTheDocs! Black can be installed by running pip install black. It requires Python 3.10+ to run.
Starred by 41.4K users
Forked by 2.7K users
Languages Python
GitHub
github.com › life4 › awesome-python-code-formatters
GitHub - life4/awesome-python-code-formatters: A curated list of awesome Python code formatters · GitHub
Formatters that take care of all your code. autopep8: format Python code to conform to the PEP 8 style guide.
Starred by 378 users
Forked by 22 users
Languages Shell
Hostman
hostman.com › tutorials › how to format code with prettier in visual studio code
How to Format Code Using Prettier in Visual Studio Code
October 20, 2025 - This utility automatically formats Python code according to PEP 8, the official Python style guide, using pycodestyle to identify areas needing formatting. Autopep8 can fix most issues flagged by pycodestyle. To avoid the need for manual formatting each time, enable auto-formatting on save in Prettier...
Pyrfecter
pyrfecter.com › format-python-code
Format Python code online · Pyrfecter
June 26, 2025 - Pyrfecter is an easy and secure way to format, lint, and improve your Python code all from inside your browser. Even if your code is well written Pyrfecter can help. It can even make improvements to AI-generated code! Paste your code or drag-and-drop a file to get started!
TutorialsPoint
tutorialspoint.com › online_python_formatter.htm
Online Python Formatter | Tutorialspoint
Online Python Formatter and Beautifier - Try online Python Code formatter and beautifier and Editor to beautify and format Python code using jQuery Plug-in
DeepSource
deepsource.com › blog › python-code-formatters
Python code formatters • DeepSource
Automated Python code formatters make sure your codebase stays in a consistent style without any manual work on your end. If adhering to a specific style of coding is important to you, employing an automated to do that job is the obvious thing to do. This avoids bike-shedding on nitpicks during code reviews, saving you an enormous amount of time overall. Inspired by tools from other ecosystems like gofmt for Go and Prettier for JavaScript, Black has gradually become the de-facto code formatter for Python projects.
GitHub
github.com › prettier › prettier
GitHub - prettier/prettier: Prettier is an opinionated code formatter. · GitHub
Prettier is an opinionated code formatter. Contribute to prettier/prettier development by creating an account on GitHub.
Starred by 51.7K users
Forked by 4.7K users
Languages JavaScript 83.3% | TypeScript 6.2% | CSS 3.0% | HTML 3.0% | SCSS 1.5% | Less 1.0%
GitHub
github.com › prettier › plugin-python
GitHub - prettier/plugin-python: Prettier Python Plugin · GitHub
Starred by 520 users
Forked by 38 users
Languages JavaScript 72.2% | Python 27.8%