I know there are tools which validate whether your Python code is compliant with PEP8, for example there is both an online service and a python module.
However, I c
There are many.
IDEs usually have some formatting capability built in. IntelliJ Idea / PyCharm does, same goes for the Python plugin for Eclipse, and so on.
There are formatters/linters that can target multiple languages. https://coala.io is a good example of those.
Then there are the single purpose tools, of which many are mentioned in other answers.
One specific method of automatic reformatting is to parse the file into AST tree (without dropping comments) and then dump it back to text (meaning nothing of the original formatting is preserved). Example of that would be https://github.com/python/black.