Skip to main content

Python type inferencer

Project description


Pytype is a static analyzer for Python code.


Apache 2.0


pytype can statically analyze your Python code, and point out bugs and errors it finds. It works on any kind of code, and doesn’t need any special directives to be useful.

However, it can additionally verify (and leverage) type annotations.


Pytype’s sources can be found on github:


Install pytype from pip

$ pip install pytype


NOTE: pytype analyzes a single file. To analyze an entire project, use the included pytype-all tool.

For more detailed explanations of pytype’s error messages, see this doc

Usage: pytype [options]

Infer/check types in a Python module

Selected options:
  -h, --help            Show the full list of options
  -C, --check           Don't do type inference. Only check for type errors.
  -o OUTPUT, --output=OUTPUT
                        Output file. Use '-' for stdout.
                        Python version to emulate ("major.minor", e.g. "2.7")


Consider the following code, which uses the type annotation syntax from PEP 3107 and PEP 484 to declare the parameter and return types of the function f:

$ cat

def f(x: int, y: str = 'default') -> int:
  return "foo"

Note that the code above has a bug: The return type is declared to be an integer, but the function actually returns a string.

Now check it with pytype:

$ pytype -V 3.6

File "", line 2, in f: bad option in return type [bad-return-type]
  Expected: int
  Actually returned: str

Pytype can also infer type annotations if they are not explicitly provided.

$ cat

class A(object):
  def __init__(self):
    self.x = 10

p = A()
q = p.x

Run pytype in inference mode (using the -o or --output option):

$ pytype -o -

p = ...  # type: A
q = ...  # type: int

class A(object):
    x = ...  # type: int

Project details

Release history Release notifications

This version
History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pytype-2018.5.15.tar.gz (1.1 MB) Copy SHA256 hash SHA256 Source None May 15, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page