For years, type-checking a Python project meant two separate jobs: get the environment right, then point a type checker at it. If the checker could not see your installed packages, it flooded you with unresolved-import errors that had nothing to do with your code. Astral’s new uv check command joins the two steps. It syncs the project environment and runs the ty type checker against it in one command, and it can do the same for standalone PEP 723 scripts.
This guide walks through uv check on a real project and a single-file script, shows how to pin the ty version, and covers editor setup and CI. Every command and output below comes from a run on Linux with uv 0.13.7 and ty 0.0.96.
Quick fix: Upgrade uv (
uv self update), then runuv checkin your project root. For a single-file script with inline metadata, runuv check --script path/to/script.py. To pin the checker, add it as a dev dependency:uv add --dev ty.
What is uv check, and how is it different from ty check?
ty check is the type checker itself. It analyzes files and resolves imports from whatever Python environment it discovers. uv check is a wrapper in uv that first prepares the environment (creating the virtual environment, locking, and installing dependencies as uv sync would), then installs ty if needed and runs it against that environment.
| Command | Prepares the environment | Which ty version | Best for |
|---|---|---|---|
uv check | Yes, syncs the project first | The one in your lockfile, otherwise a version uv downloads | Projects managed by uv, CI, pre-commit |
uv check --script file.py | Yes, builds the script’s own environment from its inline metadata | Same rules | PEP 723 single-file scripts |
ty check / uvx ty check | No, uses whatever environment it finds | Whatever you installed | Quick checks, non-uv projects |
Note: Both
uv checkand ty are still experimental. uv printswarning: `uv check` is experimental and may change without warningon every run. Flags and output may change between releases, so pin versions in CI.
What do you need before you start?
Astral’s announcement lists uv 0.12.3 or newer and ty 0.0.76 or newer as the minimum versions for the integration. You do not need to install ty separately; uv check downloads it the first time you run it.
- Check or upgrade uv:
uv --version uv self updateYou should see a version of 0.12.3 or newer. If uv came from your distribution or pipx rather than the standalone installer, upgrade it through that tool instead, because
uv self updateonly works for standalone installs.
How do you type-check a project with uv check?
Here is a minimal project with one deliberate bug: a function that returns str is assigned to a variable annotated as int.
- Create the project and the file:
uv init demo --app cd demo# main.py def greet(name: str) -> str: return "Hello, " + name def main() -> None: count: int = greet("world") print(count) if __name__ == "__main__": main()You should see
pyproject.toml,README.md, and the source files in the new directory. - Run the check:
uv checkOn the first run, uv creates
.venv, installs the project, downloads ty, and then reports:warning: `uv check` is experimental and may change without warning. Pass `--preview-features check-command` to disable this warning. Using CPython 3.13.5 interpreter at: /usr/bin/python3.13 Creating virtual environment at: .venv Installed 1 package in 1ms Downloading ty v0.0.96 (15.5MiB) Downloaded ty v0.0.96 error[invalid-assignment]: Object of type `str` is not assignable to `int` --> main.py:5:18 | 5 | count: int = greet("world") | --- ^^^^^^^^^^^^^^ Incompatible value of type `str` | | | Declared type Found 1 diagnosticYou should see a non-zero exit status when diagnostics are found (it was
1in our run), which is what makes the command usable as a CI gate. - Fix the annotation and run it again:
uv check echo $?You should see
All checks passed!and exit status0.
To silence the experimental warning once you accept the risk, pass --preview-features check-command as the message suggests.
How does uv check work under the hood?
The diagram below shows the sequence. The important part is that ty runs against the exact environment uv just synced, so third-party imports resolve the same way they do at runtime.

According to Astral, uv passes ty the workspace layout through a new uv workspace metadata command, which is how ty learns about workspace members and their environments.
How do you check PEP 723 scripts?
PEP 723 lets a single .py file declare its own dependencies in a comment block. These scripts usually live outside the project’s dependency list, so a plain type checker cannot resolve their imports.
- Create a script with inline metadata and a deliberate bug:
# scripts/fetch.py # /// script # requires-python = ">=3.12" # dependencies = ["httpx"] # /// import httpx def status(url: str) -> int: r = httpx.get(url, timeout=10) return r.status_code code: str = status("https://example.org") print(code)You should see the
# /// scriptblock at the very top of the file. - Check it with its own environment:
uv check --script scripts/fetch.pyInstalled 7 packages in 4ms error[invalid-assignment]: Object of type `int` is not assignable to `str` --> fetch.py:11:13 | 11 | code: str = status("https://example.org") | --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Incompatible value of type `int` Found 1 diagnosticYou should see that
httpxresolves (uv installed it into the script’s environment) and only the real type error remains.
For comparison, running plain uvx ty check from the project root in the same directory reported an extra error[unresolved-import]: Cannot resolve imported module `httpx`, because ty had no environment containing httpx. In our run, project-level uv check reported only main.py, so treat scripts as a separate step and check them with --script.
Tip: ty itself can also set up script environments through uv. Running
TY_UV=scripts ty checkin the same project resolved httpx and reported both real errors. Astral describes this automatic setup as opt-in because building an environment can mean downloading and building third-party packages.
How do you pin the ty version?
Without a pin, uv check downloads a current ty release. Type checkers change their rules often, and an unpinned version can make CI fail on a Monday for code nobody touched. Pinning fixes that:
- Add ty as a dev dependency:
uv add --dev "ty==0.0.90" grep -A2 'name = "ty"' uv.lockname = "ty" version = "0.0.90" source = { registry = "https://pypi.org/simple" }You should see ty recorded in
uv.lock. - Confirm
uv checkuses it:uv check -v 2>&1 | grep "ty=="You should see
Requirement already installed: ty==0.0.90, meaning the locked version ran rather than a fresh download. For a one-off run with a different version,uv check --ty-version <version>is also available.
Which uv check options matter most?
| Option | What it does |
|---|---|
--script FILE | Check a PEP 723 script using its inline dependencies |
--package NAME / --all-packages | Check one workspace member or all of them |
--locked / --frozen | Fail if uv.lock would change, or use it without updating |
--no-sync | Skip syncing and check the existing environment |
--isolated | Run without mutating project state |
--fix | Apply safe fixes for type-checking errors |
--group, --extra, --all-extras | Include optional dependencies so their imports resolve |
These come from uv check --help in uv 0.13.7. If an option is missing in your version, upgrade uv.
How do you run uv check in CI and pre-commit?
In CI, use --locked so a stale lockfile fails loudly instead of being silently rewritten:
uv check --locked --preview-features check-command
for s in scripts/*.py; do uv check --script "$s" || exit 1; done
You should see the job fail on the first diagnostic and pass with All checks passed! otherwise. Astral notes that ty’s pre-commit hook now uses uv check as well, so hook and CI results line up.
Warning: Running
uv checkon untrusted code installs that code’s dependencies, and building packages from source can execute their build scripts. Review unfamiliar projects and scripts before checking them, the same way you would before runninguv run.
How do you get the same results in VS Code?
The ty language server can use uv to discover environments. Astral’s announcement gives this setting for the ty VS Code extension:
{
"ty.experimental.useUv": "on"
}
You should see imports in PEP 723 scripts resolve in the editor once the extension reloads. The setting is experimental, so check the ty editor docs if it is renamed. If the editor still picks the wrong interpreter, our guide to fixing the VS Code Python interpreter covers the usual causes.
What problems might you hit?
| Symptom | Likely cause | Fix |
|---|---|---|
error: unrecognized subcommand 'check' | uv is too old | Upgrade to 0.12.3 or newer |
unresolved-import for a script’s dependency | Script checked as part of the project | Use uv check --script |
| Different results locally and in CI | Unpinned ty | uv add --dev ty==X and commit uv.lock |
| Imports from optional extras unresolved | Extras not installed | Add --all-extras or --extra NAME |
| Lockfile changes in CI | Dependencies edited without relocking | Run uv lock locally, use --locked in CI |
FAQ
Does uv check replace mypy or Pyright?
Not automatically. ty is a different checker with its own rules, and it is still pre-1.0. Try it alongside your current checker before switching a large codebase.
Does uv check run Ruff too?
Not yet. Astral says Ruff support and a check for unused dependencies are planned, so today it runs ty only.
Do I need ty installed globally?
No. uv check downloads ty on first use or uses the version in your lockfile.
Conclusion
uv check removes the most common type-checking failure, a checker that cannot see your environment, by syncing first and checking second. Pin ty in your lockfile, check scripts with --script, and use --locked in CI. Because both tools are experimental, keep an eye on uv’s release notes before upgrading.
Related guides
- uv vs pip vs Poetry: Which Python Package Manager Should You Use on Linux?
- Python “externally-managed-environment” Error on Ubuntu and Debian: Safe Fixes
- VS Code Python Interpreter Not Working? 7 Fixes
- Python ModuleNotFoundError: 7 Fixes That Work


Leave a Reply