Google switches to Pyrefly for faster Python type checking
Google has adopted Pyrefly, an open-source type checker developed by Meta, as its primary Python type-checking tool. Python is a cornerstone of Google’s infrastructure, powering everything from machine learning to data pipelines. Pyrefly replaces Pytype, an internally developed type checker that Google used for over a decade. The switch to Pyrefly was driven by the need for faster performance and better alignment with modern Python typing standards.
Pytype faced significant challenges due to its reliance on analyzing compiled bytecode rather than source code, which made maintaining it difficult as Python’s typing system evolved. Google decided that Python 3.12 would be the final supported version for Pytype, prompting the search for a modern alternative. Pyrefly stood out for its performance, typing spec conformance, and actionable error diagnostics.
Pyrefly, written in Rust, offers high throughput and parallel evaluation, making it up to 98% faster than Pytype in incremental rebuilds. It also boasts strong conformance with the Python typing system, scoring roughly 97% on the official test suite. The tool provides clear, Rust-style compiler diagnostics that help developers quickly identify and fix type mismatches. The adoption of Pyrefly has led to significant improvements, including a 90% reduction in the critical path of clean builds and an 80% reduction in compute hardware usage.
Engineers at Google have praised Pyrefly for its speed and clarity. For instance, Peter Hawkins, JAX Tech Lead, noted that type checking is now faster than running tests. Yotam Doron from Gemini Large Scale Pretraining appreciated the tool’s clear error messages, while Tom Ward from GDM Science highlighted its role in catching bugs early. Google plans to continue collaborating with the Pyrefly team and contributing to the Python open-source community.