Command Line Interface

The command line interface of Flake8 is modeled as an application via Application. When a user runs flake8 at their command line, main() is run which handles management of the application.

User input is parsed twice to accommodate logging and verbosity options passed by the user as early as possible. This is so as much logging can be produced as possible.

The default Flake8 options are registered by register_default_options(). Trying to register these options in plugins will result in errors.

API Documentation


Execute the main bit of the application.

This handles the creation of an instance of Application, runs it, and then exits the application.

Parameters:argv (list) – The arguments to be passed to the application for parsing.
class flake8.main.application.Application(program='flake8', version='3.4.1')[source]

Abstract our application into a class.

args = None

The left over arguments that were not parsed by option_manager

catastrophic_failure = None

Whether or not something catastrophic happened and we should exit with a non-zero status code

check_plugins = None

The instance of flake8.plugins.manager.Checkers

end_time = None

The timestamp when the Application finished reported errors.


Handle finalization and exiting the program.

This should be the last thing called on the application instance. It will check certain options and exit appropriately.

file_checker_manager = None

The flake8.checker.Manager that will handle running all of the checks selected by the user.


Find and load the plugins for this application.

If check_plugins, listening_plugins, or formatting_plugins are None then this method will update them with the appropriate plugin manager instance. Given the expense of finding plugins (via pkg_resources) we want this to be idempotent and so only update those attributes if they are None.

formatter = None

The user-selected formatter from formatting_plugins


Retrieve the formatter class by plugin name.

formatting_plugins = None

The instance of flake8.plugins.manager.ReportFormatters

guide = None

The flake8.style_guide.StyleGuide built from the user’s options


Initialize the application to be run.

This finds the plugins, registers their options, and parses the command-line arguments.

listener_trie = None

The flake8.plugins.notifier.Notifier for listening plugins

listening_plugins = None

The instance of flake8.plugins.manager.Listeners


Initialize our FileChecker Manager.


Initialize a formatter based on the parsed options.


Initialize our StyleGuide.


Initialize our listener Notifier.

option_manager = None

The instance of flake8.options.manager.OptionManager used to parse and handle the options and arguments passed by the user

options = None

The user-supplied options parsed into an instance of optparse.Values


Parse configuration files and the CLI options.

Parameters:argv (list) – Command-line arguments passed in directly.
parsed_diff = None

The parsed diff information

program = None

The name of the program being run


Register options provided by plugins to our option manager.


Report errors, statistics, and benchmarks.


Aggregate, calculate, and report benchmarks for this run.


Report all the errors found by flake8 3.0.

This also updates the result_count attribute with the total number of errors, warnings, and other messages found.


Aggregate and report statistics from this run.

result_count = None

The number of errors, warnings, and other messages after running flake8 and taking into account ignored errors and lines.


Run our application.

This method will also handle KeyboardInterrupt exceptions for the entirety of the flake8 application. If it sees a KeyboardInterrupt it will forcibly clean up the Manager.


Run the actual checks with the FileChecker Manager.

This method encapsulates the logic to make a Manger instance run the checks it is managing.

Parameters:files (list) – List of filenames to process
running_against_diff = None

Whether the program is processing a diff or not

start_time = None

The timestamp when the Application instance was instantiated.

total_result_count = None

The total number of errors before accounting for ignored errors and lines.

version = None

The version of the program being run


Register the default options on our OptionManager.

The default options include:

  • -v/--verbose
  • -q/--quiet
  • --count
  • --diff
  • --exclude
  • --filename
  • --format
  • --hang-closing
  • --ignore
  • --max-line-length
  • --select
  • --disable-noqa
  • --show-source
  • --statistics
  • --enable-extensions
  • --exit-zero
  • -j/--jobs
  • --output-file
  • --tee
  • --append-config
  • --config
  • --isolated
  • --benchmark
  • --bug-report