Mypy: Optional Static Typing for Python

1.19.1 · active · verified Sat Mar 28

Mypy is a static type checker for Python, enabling optional static typing to improve code quality and maintainability. As of version 1.19.1, it supports Python 3.9 and later, with regular updates and a stable release cadence.

Warnings

Install

Imports

Quickstart

Integrate Mypy into your Python application by importing 'mypy.api' and calling the 'run' function with command-line arguments. This allows programmatic access to Mypy's type checking capabilities.

import sys
from mypy import api

result = api.run(sys.argv[1:])

if result[0]:
    print('\nType checking report:\n')
    print(result[0])  # stdout

if result[1]:
    print('\nError report:\n')
    print(result[1])  # stderr

sys.exit(result[2])  # exit status

view raw JSON →