pytype
Python type inferencer
What it is and what it does
Pytype is a static type analyzer that infers types across your Python codebase without requiring type annotations. Unlike gradual type checkers, it detects type errors in unannotated code by analyzing control flow and operations, catching issues like passing an integer to a function expecting a string. It can also enforce user-provided type annotations where present and generate standalone .pyi stub files with inferred type information.
The tool is designed to be lenient—it allows operations that succeed at runtime and don't contradict annotations, rather than assigning fixed types at initialization. It runs on Python 3.10-3.12 and can analyze code targeting Python 3.8-3.12. Pytype is used at scale within Google and ships with helper tools like merge-pyi for integrating inferred types back into source files, plus configuration via pyproject.toml or setup.cfg.
Use it for:
- Type-check plain Python codebases that lack annotations to catch attribute errors and type mismatches early
- Generate .pyi stub files for unannotated libraries to document inferred types and enable downstream type checking
- Enforce type annotations where present while remaining permissive on unannotated code in mixed-annotation projects
- Integrate type checking into CI/CD pipelines via GitHub Actions or similar to catch type errors before deployment
- Migrate legacy Python code toward type safety by inferring types and gradually adding annotations
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pytype is a static type checker that infers types in Python code without requiring annotations, flagging common mistakes like misspelled attributes and incorrect function calls across file boundaries.
Yes, if you need type checking on unannotated Python code or want to infer types without strict gradual typing. The active maintenance, permissive license, and lack of known vulnerabilities support adoption. Medium install friction (13 dependencies, compiled packages) and platform constraints (Linux primary, macOS supported, Windows via WSL) are the main tradeoffs; evaluate whether your target Python versions (3.10+) and platform match your needs.
Install
pytype on PyPI
pip
pip install pytypeuv
uv add pytypepoetry
poetry add pytypeInstalling pytype
Before you install
Medium install friction due to 13 runtime dependencies including compiled packages like ninja and libcst. Actively maintained with recent commits; last release 2024-10-11. Requires Python 3.10+ to run and a matching interpreter in $PATH for the code being analyzed.
License in practice
Apache 2.0 permissive license allows use in commercial and proprietary projects with minimal restrictions; you must include a copy of the license and note significant changes.
Quickstart
pip install pytype
pytype file_or_directory
# Or configure in pyproject.toml:
# [tool.pytype]
# inputs = ['package_name']
# Then run: pytype
Requires a Python 3.10+ interpreter to run pytype, plus a matching Python 3.8-3.12 interpreter in $PATH for the code being analyzed. On macOS, requires OSX 10.7+ and Xcode v8+. Windows requires WSL.
Verify before relying
- Performance characteristics and analysis time for large codebases
- How inference accuracy compares to gradual typing on real-world projects
- Integration maturity with common IDEs and editor plugins
Package facts
| License | Apache 2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 13 — attrs, importlab, immutabledict, jinja2, libcst, msgspec, networkx, ninja, pycnite, pydot, tabulate, toml, typing-extensions |
| Maintenance | actively maintained — 672 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,013,417/month — #4,508 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytype-2024.10.11-cp310-cp310-macosx_12_0_x86_64.whl; pytype-2024.10.11-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; pytype-2024.10.11-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; pytype-2024.10.11-cp311-cp311-macosx_10_14_universal2.whl; pytype-2024.10.11-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; pytype-2024.10.11-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; pytype-2024.10.11-cp312-cp312-macosx_10_14_universal2.whl; pytype-2024.10.11-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; pytype-2024.10.11-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
types-typed-astProvides type stubs for the typed-ast package,…
permissive · top 15,000 on PyPI
types-contextvarsProvides type stubs for Python's contextvars…
permissive · top 15,000 on PyPI
types-chardetProvides type stubs for character encoding…
permissive · top 5,000 on PyPI
types-dataclassesProvides type stubs for Python's dataclasses…
permissive · top 15,000 on PyPI
types-PillowProvides type stubs for Pillow, enabling static…
permissive · top 5,000 on PyPI
types-PyJWTProvides type stubs for PyJWT to enable static…
permissive · top 15,000 on PyPI
types-attrsProvides PEP 561 type stubs for the attrs…
permissive · top 15,000 on PyPI
types-emojiProvides type stubs for the emoji package,…
permissive · top 15,000 on PyPI
beartypeBeartype is a runtime type checker that…
permissive · top 1,000 on PyPI
types-DateTimeRangeProvides type stubs for the DateTimeRange…
permissive · top 15,000 on PyPI