Introduction
Pyre is a static type checker for Python that analyzes type annotations to catch bugs before runtime. Built by Meta for internal use on millions of lines of Python code, it prioritizes speed and incremental analysis so developers get fast feedback without disrupting their workflow.
What Pyre Does
- Checks Python type annotations against PEP 484, 526, 544, and later typing PEPs
- Runs in incremental watch mode with sub-second feedback on file saves
- Infers return types and variable types where annotations are missing
- Integrates with editors via the Language Server Protocol
- Includes Pysa, a taint analysis tool for finding security vulnerabilities
Architecture Overview
Pyre is implemented in OCaml for performance. It parses Python source files into an internal AST, resolves imports and builds a module dependency graph, then runs constraint-based type inference and checking in parallel. In watch mode, it uses a file-system watcher to re-analyze only changed files and their dependents, keeping incremental checks fast even in large repos.
Self-Hosting & Configuration
- Install via pip:
pip install pyre-check - Initialize with
pyre initto create a.pyre_configurationfile - Set
source_directoriesandsearch_pathto control what gets checked - Use
strictmode for stricter checking orunsafeto suppress specific errors - Configure per-file overrides with inline
# pyre-strictor# pyre-ignorecomments
Key Features
- Sub-second incremental checks in watch mode for instant feedback
- OCaml implementation delivers multi-threaded parallel analysis
- Pysa security analyzer detects taint flows (SQL injection, XSS, etc.) using the same type infrastructure
- LSP support provides hover types, go-to-definition, and autocomplete in editors
- Gradual typing lets teams adopt type checking incrementally, file by file
Comparison with Similar Tools
- mypy — The reference Python type checker; Pyre is faster on large codebases but mypy has broader community plugin support
- Pyright — Microsoft TypeScript-based checker powering Pylance; fast and well-integrated with VS Code
- Pytype — Google type checker with cross-function inference; slower but infers more without annotations
- Ruff — Linter and formatter, not a type checker; complementary to Pyre
FAQ
Q: Can I use Pyre alongside mypy? A: Yes. Both read the same PEP 484 type annotations. You can run both and compare results during migration.
Q: What is Pysa? A: Pysa is Pyre's taint analysis engine that tracks untrusted data through function calls to detect security vulnerabilities like SQL injection.
Q: Does Pyre support Python 3.12+ syntax? A: Pyre tracks CPython releases. Check the changelog for the latest supported Python version.
Q: How does Pyre handle third-party libraries without type stubs?
A: Pyre uses typeshed stubs and can fall back to Any for untyped libraries. You can also add custom stubs.