skillfed

pytype

Python type inferencer

pytype v2024.10.11 1.0M downloads/30d#4,508 on PyPI5,029
Permissive license Apache 2.0 Active released

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 pytype

uv

uv add pytype

poetry

poetry add pytype

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: Implementation :: CPythonTopic :: Software Development

Tags

python type checking without annotationsstatic type inferencepython code linting and type analysisautomatic type annotation generationpython type error detection
type-inferencestatic-analysislinting

More Software Development packages