mypy
mypy is a static type checker for Python that validates code against type hints and supports gradual typing.
Installation and Setup
Install it from the Python Package Index (PyPI) into a virtual environment:
Configuration can live in mypy.ini, setup.cfg, or pyproject.toml. Here’s an example:
pyproject.toml
[tool.mypy]
python_version = "3.14"
disallow_untyped_defs = true
warn_unused_ignores = true
warn_return_any = true
Key Features
- Checks code against type hints to catch type errors before runtime.
- Offers strictness flags and presets that encourage full annotation and tighter checks.
- Caches results in
.mypy_cachefor fast incremental re-runs, using a SQLite database by default. Pass--no-sqlite-cacheto write individual cache files instead. - Supports plugins and built-in knowledge for common libraries and patterns, such as data classes.
- Supports experimental parallel type checking with
--num-workers N(or-nN) to spread the work across multiple worker processes. - Uses standard-library and third-party type stubs and recognizes
# type: ignoredirectives with optional error codes.
Usage
Run a check on a package, or path:
$ python -m mypy src/ tests/
Enable a stricter policy for a one time run:
$ python -m mypy --strict src/
Target a specific Python version when checking:
$ python -m mypy --python-version 3.14 .
Related Resources
Tutorial
Python Type Checking (Guide)
In this guide, you'll look at Python type checking. Traditionally, types have been handled by the Python interpreter in a flexible but implicit way. Recent versions of Python allow you to specify explicit type hints that can be used by different tools to help you develop your code more efficiently.
For additional information on related topics, take a look at the following resources:
- Python Protocols: Leveraging Structural Subtyping (Tutorial)
- Python Type Checking (Course)
- How to Use Type Hints for Multiple Return Types in Python (Tutorial)
- Python 3.14: Lazy Annotations (Tutorial)
- Python's Self Type: How to Annotate Methods That Return self (Tutorial)
- Python Code Quality: Best Practices and Tools (Tutorial)
- Duck Typing in Python: Writing Flexible and Decoupled Code (Tutorial)
- Ruff: A Modern Python Linter for Error-Free and Maintainable Code (Tutorial)
- Python Type Checking (Quiz)
- Exploring Protocols in Python (Course)
- Python Protocols: Leveraging Structural Subtyping (Quiz)
- Using Type Hints for Multiple Return Types in Python (Course)
- How to Use Type Hints for Multiple Return Types in Python (Quiz)
- Python Annotations (Quiz)
- Managing and Measuring Python Code Quality (Course)
- Python Code Quality: Best Practices and Tools (Quiz)
- Getting to Know Duck Typing in Python (Course)
- Duck Typing in Python: Writing Flexible and Decoupled Code (Quiz)
- Modern Python Linting With Ruff (Course)
- Ruff: A Modern Python Linter (Quiz)
By Leodanis Pozo Ramos • Updated Sept. 7, 2026