Mypy on Twitter is @mypyproject

Follow @mypyproject on Twitter

Why mypy?
Performance
Static typing will enable high, scalable and predictable efficiency, without the slow warm-up seen in many JIT compilers. These are important for interactive applications and games, for example.
Compile-time and runtime type checking
Static typing makes it easier to find bugs and with less debugging (and with less staring at long stack traces).
Stress-free code maintenance
Type declarations act both as machine-checked documentation and as convenient runtime assertions. Static types can make your code easier to understand and modify, for yourself and other programmers.
Grow your programs from dynamic to static typing
You can develop programs with dynamic types and only add static typing after your code has matured. This way you do not have maintain type declarations in initial development when the code is still changing rapidly.
IDE goodness
The type system makes it easy to support Eclipse/Visual Studio style IDE convenience for mypy programs, including precise and reliable code completion.

mypy

The mypy programming language 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, and also compile-time type checking and efficient compilation to native code, without the need of a heavy-weight VM.

Mypy is still in development. The current prototype supports type checking and translation to Python, i.e. there is no performance boost yet (development roadmap). A significant subset of Python features is supported.

What's new

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

Mypy Development Update #2

13 Mar 2013: A lot has happened in the mypy project in the last few months. I've written a blog post about the most interesting recent developments. -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
void fib(int n):
    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 examples were adapted from the Python tutorial.)

Python syntax

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

Access to Python libs

Mypy will support accessing Python modules from mypy programs, running in the stock CPython virtual machine for the best compatibility. You can also access your existing Python code. Batteries borrowed from Python! We will also port popular Python libraries (including modules in the Python standard library) to our new virtual machine and add static types to them.

Improved concurrency (no GIL)

Mypy will get rid of the Global Interpreter Lock (GIL) that is used in CPython and allow parallel programs to take advantage of multicore processors within a single process (more about the approach). We plan to support a low-level programming model based on threads and other, more programmer-friendly models built on top of that. One is likely to be based on lightweight processes with disjoint heaps and message passing, inspired by Erlang. The concurrency model will also allow Java threads to be used on future JVM targets efficiently (but the main implementation will compile directly to native code).

Learn more