Python Tools To Write Better Code

  • Published: November 7, 2017


Python community maintains a set of tools that are helpful in every project. They provide quick feedback of your code health and how much it sticks to standards and better practices.

These tools are:

style checker
checks source code for errors
complexity checker
code checker (pep8, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code)
Checks for coding standards, errors and duplicated code.
measure effectiveness of tests


Python code style (Pep8)

It was formerly called pep8 and it checks Python coding style conventions defined in PEP8.

Project homepage:

It is based in PEP8 style conventions (

The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code. As PEP 20 says, "Readability counts". A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is the most important.


McCabe is a complexity checker for Python.

Project homepage:

It is based in the Cyclomatic complexity concept.

Cyclomatic complexity is a software metric (measurement), used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code. It was developed by Thomas J. McCabe, Sr. in 1976.

It is useful for:

  • Measuring how much a program is structured
  • Determining the number of test cases that are necessary to achieve thorough test coverage of a particular module
  • Limiting complexity during development
    • Functions and methods that have the highest complexity tend to also contain the most defects.
  • Measure modules cohesion through the analysis of its complexity.

Error checks: Pyflakes

It checks Python source files for errors by parsing source code.

Project homepage:

All together: Flake8

Project Homepage:

Flake8 runs all the above tools with the flake8 command.


Project Homepage:

Code Coverage

It measures code coverage of Python projects.

Project Homepage:

It monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not.

Coverage measurement is typically used to gauge the effectiveness of tests. It can show which parts of your code are being exercised by tests, and which are not.


Marcelo Canina
I'm Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.
comments powered by Disqus
Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 ·