Skip to content
Go to file

Latest commit

Want to test running
mypy protobuf: 3.8, 3.7, 3.6, 2.7 [looking to drop 2.7 here]
mypy target: 2.7, 3.5 [looking to expand in future]
unit tests: 2.7, 3.8  [Validating real runtime behavior of google.protobuf]

Chose 6 key matrix plans to cover these cases (instead of full 3x2x2 matrix)

In the future, hope to split out the mypy of itself
into a separate step - which only targets supported mypy protobuf versions,
allowing us to drop 2.7 as a mypy_protobuf runtime and simplify futher

Git stats


Failed to load latest commit information.

mypy-protobuf: Generate mypy stub files from protobuf specs CI


protoc 3.0.0 or greater python 2.7, 3.5, 3.6, 3.7 3.8 python-protobuf >= 3.13.0 mypy >= v0.780

Other configurations may work, but are not supported in testing currently. We would be open to expanding this list if a need arises - file an issue on the issue tracker.

Python Implementation

There is a python implementation of the plugin in python/protoc-gen-mypy. On windows you will have to use python/protoc_gen_mypy.bat for the executable.

The plugin can be installed with

pip install mypy-protobuf

On posix, ensure that the protoc-gen-mypy script installed onto your $PATH. Then run.

protoc --python_out=output/location --mypy_out=output/location

Alternately, you can explicitly provide the path:

protoc --plugin=protoc-gen-mypy=path/to/protoc-gen-mypy --python_out=output/location --mypy_out=output/location

On windows, provide the bat file:

protoc --plugin=protoc-gen-mypy=path/to/protoc_gen_mypy.bat --python_out=output/location --mypy_out=output/location

To suppress output, you can run

protoc --python_out=output/location --mypy_out=quiet:output/location

Go Implementation

There is a go implementation of the plugin in go/src/protoc-gen-mypy. The import sort order can be customized to split between stdlib and project protos by changing the project const at the top of the file (we use dropbox since our proto files are namespaced under dropbox/)

To build the plugin: go get

The plugin can be used by adding the built target to the command line when running protoc (in addition to the normal plugin for output languages).


Dropbox internally uses both implementations. We internally directly use the python implementation. However, the go implementation here is a code drop from the Dropbox internal implementation with periodic re-upstreams. As a result, the python implementation will get more timely support. We encourage community contribution to improve quality/testing to bring both implementations to parity.


Contributions to the implementations are welcome. Please run tests using ./ Ensure code is formatted using black.

pip3 install black
black python/ test/




Licence etc.

  1. License: Apache 2.0.
  2. Copyright attribution: Copyright (c) 2017 Dropbox, Inc.
  3. External contributions to the project should be subject to Dropbox's Contributor License Agreement (CLA):