Python

Ty: Astral's Blazing-Fast Python Type Checker Written in Rust

Ty is an extremely fast Python type checker and language server from Astral, 10-60x faster than mypy and pyright, written in Rust.

Keeping this site alive takes effort — your support means everything.
無程式碼也能輕鬆打造專業LINE官方帳號!一鍵導入模板,讓AI助你行銷加分! 無程式碼也能輕鬆打造專業LINE官方帳號!一鍵導入模板,讓AI助你行銷加分!
Ty: Astral's Blazing-Fast Python Type Checker Written in Rust

Python’s type checking ecosystem has long been dominated by mypy – the original type checker that pioneered gradual typing for Python. But mypy’s Python-based implementation has always struggled with performance on large codebases. Ty is Astral’s answer to this problem: a Python type checker and language server written entirely in Rust, designed to be 10 to 60 times faster than existing alternatives.

Astral, the company behind the incredibly popular Ruff linter, has applied the same Rust-powered performance philosophy to type checking. Ty builds on Astral’s deep experience with Python tooling in Rust, leveraging the same multi-threaded architecture and incremental computation patterns that made Ruff the industry standard for Python linting.

The numbers speak for themselves. On large monorepos with hundreds of thousands of lines of Python, Ty completes initial type checking in seconds rather than minutes. Incremental checks after file changes are effectively instant, making it feasible to run type checking on every file save in even the largest projects. For developers who have tolerated mypy’s multi-minute check times, Ty represents a transformative improvement in developer experience.


How Does Ty Achieve Such Dramatic Speed Improvements?

Ty’s performance advantage comes from a combination of architectural decisions and implementation choices, not from any single optimization.

graph LR
    A[Python Source Files] --> B[Parallel File Discovery]
    B --> C[AST Parsing in Rust]
    C --> D[Salsa Incremental Engine]
    D --> E{Cached Result?}
    E -->|Yes| F[Reuse Cached Type Info]
    E -->|No| G[Type Inference & Checking]
    G --> H[Store in Incremental DB]
    F --> I[Collect Diagnostics]
    H --> I
    I --> J[Emit Results]

The Salsa-based incremental computation engine is key to Ty’s performance. It tracks dependencies between files and type definitions at a granular level. When a file changes, only the computations that depend on the changed parts are re-executed, rather than re-checking the entire project. This is the same approach used by the Rust compiler’s incremental compilation system.


How Does Ty Compare to Other Python Type Checkers?

The Python type checking landscape has several established players, each with different performance characteristics and feature sets.

FeatureTymypypyrightpyrepytype
LanguageRustPythonTypeScriptOCamlPython
Speed10-60x fasterBaseline5-10x faster than mypyModerateSlow
LSP serverBuilt-inSeparateBuilt-inSeparateSeparate
PEP 695 supportYesPartialPartialNoNo
Plugin systemPlannedExtensiveLimitedMinimalMinimal
Monorepo supportNativeVia configVia configNativeBasic
Configurationpyproject.tomlmypy.ini, setup.cfgpyproject.tomlCustom configsetup.cfg

Ty’s clean-slate design in Rust allows it to adopt the latest Python type system features without the legacy compatibility constraints that slow down evolution in older tools. Its built-in LSP server eliminates the need for separate language server setup, providing a unified toolchain experience.


What Type System Features Does Ty Support?

Ty aims for comprehensive coverage of Python’s evolving type system, including both established and emerging features.

FeatureStatusPEP Reference
Basic type annotationsCompletePEP 484
Generic typesCompletePEP 484, PEP 695
Union types (X | Y)CompletePEP 604
Protocols (structural subtyping)CompletePEP 544
TypedDictCompletePEP 589
Literal typesCompletePEP 586
TypeVarTuple / ParamSpecCompletePEP 646, PEP 612
Type narrowingComplete
Overload decoratorCompletePEP 484
Self typeCompletePEP 673
TypeIs (type narrowing)CompletePEP 742
TypedDict alternativesCompletePEP 728
Python 3.14 type featuresPlannedLatest PEPs

Ty tracks the latest PEP developments closely, aiming to support new type features shortly after they are accepted. This rapid adoption cycle ensures that projects using the latest Python versions can benefit from modern type system features with full type checker support.


How Does Ty Integrate with Editor Workflows?

Ty’s built-in LSP server provides a seamless development experience across all major editors and IDEs.

Editor/IDEIntegration MethodKey LSP Features
VS CodeLSP extensionReal-time diagnostics, completions
Neovimbuilt-in LSP clientInline errors, hover, go-to-definition
JetBrainsLSP pluginFull IDE integration
HelixBuilt-in LSPAutomatic setup
Sublime TextLSP pluginDiagnostics, completions
Emacseglot/lsp-modeFull LSP support

The LSP server provides real-time diagnostics as you type, auto-completions that respect type constraints, go-to-definition and find references with type-aware navigation, hover information with inferred types, and inline error messages with suggested fixes.


FAQ

What is Ty? Ty is a Python type checker and language server written in Rust by Astral, designed to be 10-60x faster than existing tools like mypy and pyright. It provides real-time type checking with IDE integration.

How does Ty achieve its speed compared to mypy? Ty is written in Rust and uses a multi-threaded architecture with incremental compilation, AST caching, and parallel file analysis. It processes files independently using a Salsa-based incremental computation model.

Does Ty support Python type annotations fully? Ty aims for near-complete support of Python’s type system including generics, overloads, Protocols, TypedDicts, Literal types, and the latest PEP specifications. It tracks PEP 695 (type parameter syntax) and later standards.

Can Ty replace mypy in existing projects? Yes, Ty is designed as a drop-in replacement. It supports mypy-compatible configuration and can be integrated into existing CI/CD pipelines and editor workflows. Many projects can switch by simply changing their type checking command.

Does Ty include a language server protocol implementation? Yes, Ty includes a built-in LSP server that provides real-time type checking, auto-completions, go-to-definition, find references, hover information, and inline error diagnostics in any LSP-compatible editor.


Further Reading

TAG
CATEGORIES