DEV Community

Paramanantham Harrison
Paramanantham Harrison

Posted on

Is there any package to do auto-formatting in your python / Django project?

I need suggestions to use in my side project. I am a javascript dev, I use prettier + eslint along with git hook to do autoformatting and linting in my projects.

Is there any options similarly in python / Django?

Expected answer,

  • suggest packages to do such magic
  • share article reference to setup in VScode and also git hooks to auto format before pushing and throw lint issues before pushing to git.

Top comments (5)

Collapse
 
teckert profile image
Thomas Eckert

Yes! My favorite and the favorite of a good percentage of the Python community is black.

In VSCode, I use the Python extension. In settings, under the Python extension, set the formatting provider to Black:

Then, make sure format on save is set to true.

When you save a Python file, if you don't have Black installed in that environment, you will get a prompt to install it. It is pip install black to do so manually.

Collapse
 
rhymes profile image
rhymes

+1 for black

Collapse
 
teckert profile image
Thomas Eckert

As for git hooks, there should be some helpful info in this article, but I haven't implemented it before myself: ljvmiranda921.github.io/notebook/2...

Collapse
 
learnwithparam profile image
Paramanantham Harrison

Thanks Thomas, it’s really helpful

Collapse
 
zodman profile image
Andres 🐍 in πŸ‡¨πŸ‡¦

Yapf