This post can be found also on my personal blog here: https://www.kevinpeters.net/auto-formatters-for-python
- You do not need a style guide for low-level problems since the auto formatter deals with those problems
- This directly reduces the number of discussions about unnecessary things and let the developers focus on writing actual code
- It will also help with onboarding developers on the code base because the style of the code is consistent
- Less merge conflicts since the style will almost always be the same
Those reasons are really good arguments for using auto formatters. It will save engineers time and company time because developers will be more productive.
For Python there are three solutions out there:
autopep8 — GitHub
autopep8 is an auto formatter built and open-sourced and made by several developers. It is maybe the most used right now since it is one of the oldest tools out there. It uses pycodestyle to analyze which parts of your code do not fit to the pep-guidelines and will try to fix them. There is a list of features listed in the README of the repository on which pep guidelines are supported. You can find this list here. The tool will also do small additional checks. As of the time of writing the repository had around 2200 stars (June 2018).
yapf — GitHub
Yet another Python formatter is another tool which is produced and maintained by none other than…