Mypy on Twitter is @mypyproject

Follow @mypyproject on Twitter

Why mypy?
Compile-time type checking
Static typing makes it easier to find bugs and with less debugging (and with less deciphering of long stack traces).
Easier maintenance
Type declarations act as machine-checked documentation. Static typing makes your code easier to understand and easier to modify without introducing bugs.
Grow your programs from dynamic to static typing
Develop programs with dynamic types and add static typing after your code has matured. This way you can benefit from the convenience of dynamic typing in initial development but also reap the benefits of static typing when the code grows in size and complexity.
Performance?
Static typing has the potential to improve runtime performance. However, the current development focus is on static type checking only.

mypy

Mypy is an experimental Python variant that aims to combine the benefits of dynamic (or "duck") typing and static typing. Our goal is to have the expressive power and convenience of Python combined with compile-time type checking. You can run mypy programs using a standard Python VM without translation or compilation and with minimal runtime overhead.

Mypy is still in development. A significant subset of Python features is supported.

What's new

Moving forward again!

24 Jul 2014: Mypy development is seeing progress, after a pause. Stay tuned for exciting news! And we're still looking for new contributors. Also updated the web site to reflect the current development focus: static type checking. -Jukka

Mypy switches to Python-compatible syntax!

2 Jul 2013: Mypy now has a Python-compatible syntax! The implementation is already self-hosting. Have a look at the rewritten Mypy Tutorial (formerly Mypy Overview), README and the code. Also updated the roadmap. Related blog post -Jukka

PyCon Update: Python-compatible syntax for mypy?

15 Apr 2013: I wrote a blog post about my PyCon visit and a new, Python-compatible syntax idea. The short summary is that mypy may get a 100% Python-compatible syntax in the future! Also Python 2.x support, structural subtyping and real multiple inheritance are being planned. -Jukka

Mypy at PyCon US 2013 (Santa Clara, CA)!

13 Mar 2013: I will present a poster about mypy at PyCon US this weekend. If you are coming to PyCon, you are welcome to come for a chat. -Jukka

Older news

Seamless dynamic and static typing

Dynamic typing
def fib(n):
    a, b = 0, 1
    while a < n:
        print(a)
        a, b = b, a+b
Static typing
def fib(n: int) -> None:
    a, b = 0, 1
    while a < n:
        print(a)
        a, b = b, a+b
<Add signature
for static
typing

You can freely mix static and dynamic typing within a program, within a source file or even within a single expression. No need to give up the flexibility of dynamic typing — use static typing when it gives you a benefit. Often the only changes in statically typed code are the addition of function type signatures. Mypy can infer the types of other variables. (The above example was adapted from the Python tutorial.)

Python syntax

Every mypy program is syntactically valid Python. Dynamically typed mypy is almost identical to normal Python; there's practically no learning curve if you know Python. The aim is to support most Python language constructs in mypy.

Powerful type system

Mypy has a powerful, modern type system with features such as bidirectional type inference, generics, function types, abstract base classes, multiple inheritance and tuple types.

Access to Python libs

Mypy will support accessing Python modules from mypy programs. Most commonly used libraries also have statically typed interface definitions that allow the type checker to check code that uses the libraries.

Learn more