Code Quality & Packaging

mypy

Lets Python catch a whole category of bugs before the program ever runs, not after it crashes.

Install it: pip install mypy

What does it do?

Mypy checks the optional type hints developers add to Python code, labels like this function expects a number, not text, and flags places where those labels don’t match up, all before the program actually runs. It’s similar to a proofreader catching a subject-verb disagreement in a sentence before it’s printed, rather than a reader stumbling over the mistake later. Python normally doesn’t enforce these labels at all; mypy is a separate check developers run specifically to catch mismatches that Python itself would otherwise ignore until something crashes. This class of bug, passing the wrong kind of data into a function, is one of the most common sources of real-world software errors.

See it in action

This is a Python file with labels saying what type of data each part expects; running the mypy command on it would catch that greet(123) wrongly passes a number instead of text.

def greet(name: str) -> str:
    return "Hello, " + name

greet(123)

Why would a non-developer care?

Catching wrong-type-of-data bugs before software ships is a meaningful chunk of what separates reliable apps from ones that crash unpredictably, and mypy is one of the main tools that lets Python-based products get some of the safety net that stricter languages have built in by default.

Real-world examples

Mypy was created with backing from Dropbox, which uses Python extensively and needed a way to add safety checks to a massive existing codebase without rewriting it. Other large engineering teams running Python at scale have written publicly about using type checking to catch bugs earlier in codebases serving huge numbers of users.

Who uses it

Teams working on large or long-lived Python codebases who want some of the bug-catching benefits of stricter languages without abandoning Python.

How it compares to alternatives

It’s the original and most established of Python’s type checkers, though it now competes with faster newer entrants like Microsoft’s Pyright and Astral’s own type checker; mypy remains the reference implementation most tools try to stay compatible with.

Fun fact

Mypy’s creator, Jukka Lehtosalo, began the project as part of his academic research before Dropbox hired him to keep developing it.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries