Extending mypy using plugins

Python is a highly dynamic language and has extensive metaprogrammingcapabilities. Many popular libraries use these to create APIs that maybe more flexible and/or natural for humans, but are hard to express usingstatic types. Extending the PEP 484 type system to accommodate all existingdynamic patterns is impractical and often just impossible.

Mypy supports a plugin system that lets you customize the way mypy type checkscode. This can be useful if you want to extend mypy so it can type check codethat uses a library that is difficult to express using just PEP 484 types.

The plugin system is focused on improving mypy’s understandingof semantics of third party frameworks. There is currently no way to definenew first class kinds of types.

Note

The plugin system is experimental and prone to change. If you want to writea mypy plugin, we recommend you start by contacting the mypy core developerson gitter. In particular, there areno guarantees about backwards compatibility.

Backwards incompatible changes may be made without a deprecation period,but we will announce them inthe plugin API changes announcement issue.