API

The main entrypoint for running PythonTA’s code analysis is the check_all function.

python_ta.check_all(module_name: list[str] | str = '', config: dict[str, Any] | str = '', output: str | IO | None = None, load_default_config: bool = True, autoformat: bool | None = False, on_verify_fail: Literal['log', 'raise'] = 'log') PythonTaReporter

Analyse one or more Python modules for code issues and display the results.

Parameters:
  • module_name – If an empty string (default), the module where this function is called is checked. If a non-empty string, it is interpreted as a path to a single Python module or a directory containing Python modules. If the latter, all Python modules in the directory are checked. If a list of strings, each string is interpreted as a path to a module or directory, and all modules across all paths are checked.

  • config – If a string, a path to a configuration file to use. If a dictionary, a map of configuration options (each key is the name of an option).

  • output – If a string, a path to a file to which the PythonTA report is written. If a typing.IO object, the report is written to this stream. If None, the report is written to standard out or automatically displayed in a web browser, depending on which reporter is used.

  • load_default_config – If True (default), additional configuration passed with the config option is merged with the default PythonTA configuration file. If False, the default PythonTA configuration is not used.

  • autoformat – If True, autoformat all modules using the black formatting tool before analyzing code.

  • on_verify_fail – Determines how to handle files that cannot be checked. If set to “log” (default), an error message is logged and execution continues. If set to “raise”, an error is raised immediately to stop execution.

Returns:

The PythonTaReporter object that generated the report.

Notes:

  • For information on using the config argument, see Configuration.

  • If using the ColorReporter, writing to a file using the output argument is not recommended. This reporter uses terminal-specific characters to colourize text displayed on your screen, and these characters will look strange when opening the output file in a text editor.

The doc function can be used to open the PythonTA Checks webpage to look up a specific error.

python_ta.doc(msg_id: str) None

Open the PythonTA documentation page for the given error message id.

Parameters:

msg_id – The five-character error code, e.g. "E0401".