Flake8 API

flake8.engine

flake8.engine.get_parser()

This returns an instance of optparse.OptionParser with all the extensions registered and options set. This wraps pep8.get_parser.

flake8.engine.get_style_guide(**kwargs)

Parse the options and configure the checker. This returns a sub-class of pep8.StyleGuide.

flake8.hooks

flake8.hooks.git_hook(complexity=-1, strict=False, ignore=None, lazy=False)

This is the function used by the git hook.

Parameters:
  • complexity (int) – (optional), any value > 0 enables complexity checking with mccabe
  • strict (bool) – (optional), if True, this returns the total number of errors which will cause the hook to fail
  • ignore (str) – (optional), a comma-separated list of errors and warnings to ignore
  • lazy (bool) – (optional), allows for the instances where you don’t add the files to the index before running a commit, e.g., git commit -a
Returns:

total number of errors if strict is True, otherwise 0

flake8.hooks.hg_hook(ui, repo, **kwargs)

This is the function executed directly by Mercurial as part of the hook. This is never called directly by the user, so the parameters are undocumented. If you would like to learn more about them, please feel free to read the official Mercurial documentation.

flake8.main

flake8.main.main()

Parse options and run checks on Python source.

flake8.main.check_file(path, ignore=(), complexity=-1)

Checks a file using pep8 and pyflakes by default and mccabe optionally.

Parameters:
  • path (str) – path to the file to be checked
  • ignore (tuple) – (optional), error and warning codes to be ignored
  • complexity (int) – (optional), enables the mccabe check for values > 0
flake8.main.check_code(code, ignore=(), complexity=-1)

Checks code using pep8 and pyflakes by default and mccabe optionally.

Parameters:
  • code (str) – code to be checked
  • ignore (tuple) – (optional), error and warning codes to be ignored
  • complexity (int) – (optional), enables the mccabe check for values > 0
class flake8.main.Flake8Command(dist, **kw)

The Flake8Command class is used by setuptools to perform checks on registered modules.

flake8.util

For AST checkers, this module has the iter_child_nodes function and handles compatibility for all versions of Python between 2.5 and 3.3. The function was added to the ast module in Python 2.6 but is redefined in the case where the user is running Python 2.5