--- id: pytype version: "2024.10.11" license: Apache 2.0 license_treatment: permissive maintenance: active --- # pytype — Python type inferencer License: permissive · Maintenance: active · Downloads: 1.0M/mo ## 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 above — 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 pip install pytype uv add pytype 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_current - Install friction: medium - Maintenance: active - Downloads: 1.0M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags python type checking without annotations, static type inference, python code linting and type analysis, automatic type annotation generation, python type error detection, type-inference, static-analysis, linting [View on SkillFed](https://skillfed.io/packages/pytype) · [View on PyPI](https://pypi.org/project/pytype/)