Skip to content

ty - Fast Python Type Checker Cheatsheet

ty - Fast Python Type Checker Cheatsheet

ty is an extremely fast Python type checker and language server, written in Rust by Astral (the team behind Ruff and uv). It applies the same performance philosophy to type checking: where mypy can take minutes on a large codebase, ty targets near-instant feedback, making type checking practical to run on every save rather than only in CI. It completes the modern Astral Python toolchain — uv for packaging, Ruff for lint/format, ty for types.

ty is newer than mypy and still maturing. Validate it against your codebase before making it a hard CI gate.

Installation

MethodCommand
uv (recommended)uv tool install ty
uvx (no install)uvx ty check
pippip install ty
Verifyty --version

Checking Code

CommandDescription
ty checkCheck the current project
ty check src/Check a specific path
ty check --watchRe-check on file changes
ty check --output-format conciseCompact output
ty check --error-on-warningTreat warnings as errors
ty --helpFull option list

Configuration

ty reads pyproject.toml:

[tool.ty]
# Paths to check
src = ["src", "tests"]

[tool.ty.environment]
python-version = "3.12"
# Where to find dependencies
python = ".venv"

[tool.ty.rules]
# Tune individual diagnostics
possibly-unbound-attribute = "warn"
unused-ignore-comment = "ignore"
SectionPurpose
[tool.ty]Project layout / included paths
[tool.ty.environment]Python version, venv, search paths
[tool.ty.rules]Set each rule to error, warn, or ignore

Suppressing Diagnostics

FormEffect
# ty: ignoreSuppress all diagnostics on the line
# ty: ignore[rule-name]Suppress a specific rule
# type: ignoreAlso respected (mypy-compatible)

Language Server (Editor Integration)

EditorHow
VS CodeInstall the Astral ty extension
NeovimConfigure ty server as an LSP
Any LSP clientRun ty server

The language server gives inline type errors, hover types, and go-to-definition with the same speed as the CLI.

Typical Diagnostics

DiagnosticMeans
invalid-argument-typeArgument doesn’t match the parameter type
unresolved-attributeAttribute doesn’t exist on the type
possibly-unbound-variableVariable may be used before assignment
invalid-return-typeReturn doesn’t match the annotation
unresolved-importImport cannot be resolved

The Astral Toolchain

# A complete modern Python quality gate
uv sync                 # deps, locked and fast
uv run ruff format .    # format
uv run ruff check .     # lint
uv run ty check         # types
uv run pytest           # tests
ToolReplaces
uvpip, pip-tools, virtualenv, pyenv, poetry
Ruffblack, flake8, isort, pyupgrade, + more
tymypy (type checking)

CI Integration

# Fail the build on type errors
uvx ty check --error-on-warning

# Only check changed files (with git)
git diff --name-only origin/main -- '*.py' | xargs uvx ty check

ty vs Other Type Checkers

AspecttymypyPyright
LanguageRustPythonTypeScript/Node
SpeedVery fastSlowerFast
MaturityNewerMost matureMature
Editor LSPBuilt-inVia pluginsBuilt-in (Pylance)
Best forSpeed + Astral stackEcosystem compatibilityVS Code users

Resources