Python is a dynamically typed language, which makes it flexible for building applications, APIs, automation tools, and data-processing systems. However, dynamic typing can also make it difficult to identify certain errors before an application runs. Incorrect function arguments, unexpected return values, missing attributes, and incompatible data types can cause problems during execution.
Type checkers help developers identify these issues before running their applications. Tools such as mypy and Pyright have been widely used in Python projects for this purpose. Astral, the company behind uv and Ruff, has introduced another option called ty.
On December 1, 2026, Astral announced the stable 1.0 release of ty. It is a Python type checker and language server written in Rust. The stable release makes ty ready for production use and introduces improvements to type inference, generics, third-party library support, and development workflows.
This article explains how to install ty, configure it in a Python project, identify type errors, integrate it into development workflows, and use its features in real-world applications.
What Is ty?
ty is a Python type checker and language server developed by Astral. It analyzes Python source code to identify type-related problems without requiring the application to execute.
It is designed as an alternative to existing tools such as mypy, Pyright, and Pyrefly.
One of its main goals is performance. Because ty is written in Rust, it can analyze large Python projects quickly. Its architecture also supports incremental analysis, which means that after a code change, it can recheck affected parts of a project instead of repeatedly analyzing everything.
The stable 1.0 release includes improvements that make the tool more suitable for production development.
Some important capabilities include:
- Static type checking for Python applications.
- Type inference for variables, functions, and attributes.
- Advanced generic type analysis.
- Detailed diagnostic messages.
- Configurable rules and severity levels.
- Per-file configuration and error suppression.
- Incremental checking and watch mode.
- Language server support for modern code editors.
- Support for popular libraries such as Pydantic, Django, pytest, and attrs.
These capabilities make ty useful for both new Python projects and existing applications that are gradually adopting type annotations.
Installing ty in a Python Project
There are multiple ways to install ty. For projects using the Astral Python tooling ecosystem, uv provides a convenient installation option.
To install ty as a global command-line tool, run:
uv tool install ty@latest
Another option is to execute ty without installing it globally:
uvx ty check
The uvx command runs the tool in an isolated environment. This is useful when developers want to try ty before adding it to their regular development setup.
After installation, verify that the command is available:
ty --version
To check a Python project, navigate to its root directory and execute:
ty check
By default, ty checks Python files in the current project. If the project contains a pyproject.toml file, ty uses it to identify the project root and discover relevant configuration.
For a specific Python file, use:
ty check app.py
This is useful when working on a small script or investigating a particular module.
Creating a Python Project for Type Checking
Consider a Python application that manages customer information. The application contains a service that calculates the total value of an order.
Create a file named order_service.py:
def calculate_total(price: float, quantity: int) -> float:
return price * quantity
def create_order(customer: str, price: float, quantity: int):
total = calculate_total(price, quantity)
return {
"customer": customer,
"total": total,
"quantity": quantity
}
order = create_order("John", 250.50, 2)
print(order)
The code uses type annotations for the calculate_total() function. However, the create_order() function does not explicitly declare its return type.
Run the type checker:
ty check order_service.py
ty analyzes the function definitions, arguments, return values, and expressions. It can infer information about code even when every variable and function does not have an explicit annotation.
Now introduce an incorrect argument:
order = create_order("John", "250.50", 2)
The price parameter expects a float, but the application passes a string.
ty can identify this mismatch before the application executes. This helps developers catch problems during development rather than discovering them through production errors.
Understanding Type Inference
Type inference is an important capability of ty. It allows the checker to determine types from the surrounding code without requiring developers to annotate every variable.
For example:
def calculate_discount(price: float):
discount = price * 0.10
return discount
result = calculate_discount(500.0)
The variable discount receives a numeric value calculated from price. ty can infer the relevant type information from the expression.
The stable release also improves how ty infers types across function calls, collections, attributes, and generic operations.
Consider a class with an attribute initialized inside its constructor:
class RetryPolicy:
def __init__(self) -> None:
self.attempts = 3
policy = RetryPolicy()
policy.attempts = "three"
The constructor assigns an integer to attempts. ty can infer that the attribute is an integer and report the later assignment of a string as a type error.
This is useful in applications where developers do not explicitly annotate every class attribute.
Type inference reduces the amount of repetitive annotation while still helping identify incompatible assignments.
Working With Generics and Advanced Type Inference
Generics allow developers to create reusable functions and classes that work with different data types while preserving type information.
For example, consider a function that returns the first item from a list:
def get_first(items: list[int]) -> int:
return items[0]
numbers = [10, 20, 30]
result = get_first(numbers)
The function accepts a list of integers and returns an integer.
Generic functions make this approach reusable across different types:
def get_first[T](items: list[T]) -> T:
return items[0]
numbers = get_first([10, 20, 30])
names = get_first(["John", "Alice", "David"])
The function uses Python's modern generic function syntax. The type variable T represents the element type of the list.
When the function receives integers, the return type is inferred as an integer. When it receives strings, the return type is inferred as a string.
The stable release of ty includes improvements to its generic type solver and contextual type inference. These improvements help it understand relationships between types across function calls and complex expressions.
This is particularly useful in libraries and applications that use reusable generic functions, collections, and data-processing utilities.
Configuring ty With pyproject.toml
A Python project usually needs consistent type-checking rules across the development team. Instead of passing command-line options every time, developers can configure ty in pyproject.toml.
The following example defines basic configuration:
[tool.ty.environment]
python-version = "3.12"
[tool.ty.rules]
unused-ignore-comment = "warn"
The python-version setting specifies the Python version that ty should use when analyzing the application.
The rules section controls the severity of individual diagnostics. Supported severity levels include ignore, warn, and error.
For example, a project can configure a specific diagnostic as an error:
[tool.ty.rules]
possibly-unresolved-reference = "error"
It can also disable a diagnostic when the project has a valid reason to ignore it:
[tool.ty.rules]
division-by-zero = "ignore"
Developers should avoid disabling important checks simply to make the type-checking output disappear. Configuration should reflect the project's actual requirements.
The configuration file can also define analysis behavior, Python environment settings, source directories, and per-file overrides.
Checking Existing Python Projects
Introducing a type checker into an existing application can produce many diagnostics. This is common in projects that were originally developed without type annotations.
Trying to fix every existing issue immediately may delay adoption.
A better approach is to introduce ty gradually.
Start by running:
ty check
Review the diagnostics and identify the most important problems. Focus on areas where incorrect types can cause application failures, such as API request handling, database operations, authentication, and data processing.
Then add type annotations to important functions and modules.
For example:
def get_user(user_id: int) -> dict[str, object]:
return {
"id": user_id,
"name": "John",
"active": True
}
This makes the expected input and output types clearer.
Developers can also configure individual rules and file overrides to manage the migration without weakening checks across the entire application.
The goal should be to improve type safety incrementally while keeping development work manageable.
Using Watch Mode During Development
Running a type checker manually after every code change can interrupt the development workflow.
ty provides watch mode to automatically monitor changes and recheck affected files.
Run the following command:
ty check --watch
When a Python file changes, ty checks the affected code again.
Its incremental analysis is designed to make subsequent checks faster by reusing information from previous analysis runs.
This is especially useful in large applications containing multiple packages and modules.
Developers can keep watch mode running in a terminal while editing code in an IDE. This provides faster feedback without requiring a complete manual type-checking command after every change.
Integrating ty Into a Development Workflow
Type checking becomes more valuable when it is included in the normal development process.
For example, a development team can run ty before committing changes and during continuous integration.
A simple GitHub Actions workflow can execute the type checker after installing the project dependencies:
name: Python Type Check
on:
push:
pull_request:
jobs:
type-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install project dependencies
run: uv sync --locked
- name: Run ty
run: uv run ty check
This example assumes the project already manages its dependencies through uv and includes ty in its development dependencies.
When a pull request introduces a type error, the type-checking step can fail and prevent the change from passing the workflow.
This helps teams identify problems before merging code into the main branch.
Using ty With Popular Python Libraries
The stable 1.0 release includes built-in support for foundational Python libraries such as Pydantic, Django, pytest, and attrs.
This matters because third-party libraries often introduce complex types, decorators, model definitions, and dynamic behavior that can be difficult for a type checker to understand.
For example, consider a Pydantic model:
from pathlib import Path
from pydantic import BaseModel, Field
class ApplicationOptions(BaseModel):
output: Path
simulate: bool = Field(
default=False,
strict=True,
alias="dry_run"
)
The model defines an output path and a Boolean configuration option.
Pydantic performs runtime validation and conversion according to its model configuration. ty's library support helps it understand these model definitions and identify incompatible constructor arguments.
For example, passing a string to the strict Boolean field can be identified as a type error.
This improves the development experience when working with frameworks that rely on model definitions and validation.
ty Compared With mypy and Pyright
Python developers already have several established type-checking options. Choosing between them depends on project requirements, existing tooling, performance expectations, and compatibility needs.
ty focuses on fast type checking and incremental analysis. Its stable release also improves its support for modern Python typing features and popular third-party libraries.
mypy is a widely adopted Python type checker with an established ecosystem and extensive configuration options.
Pyright is another popular option that provides static type analysis and powers the Python type-checking experience in several editor integrations.
The tools have different architectures and may produce different diagnostics for the same code. Developers should evaluate them against their own applications rather than assuming that one tool will identify every possible problem.
For projects considering ty, a useful approach is to run it against representative application modules and compare its diagnostics, performance, and compatibility with existing development workflows.
Best Practices for Using ty
Start with important application modules
Begin with critical business logic, API services, database access, and shared utility functions. These areas often benefit most from early type checking.
Use meaningful type annotations
Add annotations to public functions, service interfaces, and complex data structures. Clear annotations make code easier to understand and help the type checker identify incorrect usage.
Configure the Python version
Set the target Python version in the project configuration. This helps ty identify language features and standard-library APIs that are incompatible with the application's supported Python version.
Review diagnostics instead of suppressing everything
Understand why a diagnostic appears before changing configuration or adding suppression comments. Disabling rules without investigation can hide genuine problems.
Include type checking in CI
Run ty during pull requests and automated builds. This helps prevent new type errors from entering the main development branch.
Keep dependencies and environments consistent
Make sure ty analyzes the same Python environment and dependencies used by the application. Incorrect environment discovery can result in unresolved imports or incomplete type information.
Use watch mode during active development
Watch mode provides faster feedback while editing files and helps developers identify problems before they become part of a larger change.
Common Mistakes to Avoid
Some common mistakes when introducing ty include:
- Assuming that installing ty automatically makes an application type-safe.
- Ignoring unresolved imports caused by an incorrectly selected Python environment.
- Using a Python target version that does not match the project requirements.
- Disabling diagnostics without understanding their meaning.
- Adding type annotations without checking whether they accurately represent runtime behavior.
- Introducing type checking only in local development and not in CI.
- Assuming that all diagnostics will match those produced by mypy or Pyright.
A successful type-checking strategy requires consistent configuration, accurate annotations, and regular review of diagnostic results.
Conclusion
The stable 1.0 release of ty gives Python developers another production-ready option for static type checking. Developed by Astral and written in Rust, it focuses on performance, incremental analysis, modern type inference, and support for popular Python libraries.
Developers can install it with uv, run it through the command line, configure it in pyproject.toml, and integrate it into automated development workflows.
Its improvements to generics, contextual inference, and third-party library support make it useful for both new applications and existing Python projects.
For teams looking to improve Python code quality, ty provides a practical way to identify type-related problems earlier and make development workflows more reliable.
Join the conversation! Your thoughts help the community grow.