uv check Tutorial: Type-Check Python Projects with ty on Linux

,
uv check Tutorial: Type-Check Python Projects with ty on Linux

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 run uv check in your project root. For a single-file script with inline metadata, run uv 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.

CommandPrepares the environmentWhich ty versionBest for
uv checkYes, syncs the project firstThe one in your lockfile, otherwise a version uv downloadsProjects managed by uv, CI, pre-commit
uv check --script file.pyYes, builds the script’s own environment from its inline metadataSame rulesPEP 723 single-file scripts
ty check / uvx ty checkNo, uses whatever environment it findsWhatever you installedQuick checks, non-uv projects

Note: Both uv check and ty are still experimental. uv prints warning: `uv check` is experimental and may change without warning on 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.

  1. Check or upgrade uv:
    uv --version
    uv self update

    You 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 update only 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.

  1. 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.

  2. Run the check:
    uv check

    On 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 diagnostic

    You should see a non-zero exit status when diagnostics are found (it was 1 in our run), which is what makes the command usable as a CI gate.

  3. Fix the annotation and run it again:
    uv check
    echo $?

    You should see All checks passed! and exit status 0.

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.

Flowchart of uv check: choose a script or project environment, lock and sync, use the locked or downloaded ty version, then exit 1 on diagnostics or 0 when clean
How uv check picks an environment and a ty version before type checking.

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.

  1. 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 # /// script block at the very top of the file.

  2. Check it with its own environment:
    uv check --script scripts/fetch.py
    Installed 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 diagnostic

    You should see that httpx resolves (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 check in 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:

  1. Add ty as a dev dependency:
    uv add --dev "ty==0.0.90"
    grep -A2 'name = "ty"' uv.lock
    name = "ty"
    version = "0.0.90"
    source = { registry = "https://pypi.org/simple" }

    You should see ty recorded in uv.lock.

  2. Confirm uv check uses 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?

OptionWhat it does
--script FILECheck a PEP 723 script using its inline dependencies
--package NAME / --all-packagesCheck one workspace member or all of them
--locked / --frozenFail if uv.lock would change, or use it without updating
--no-syncSkip syncing and check the existing environment
--isolatedRun without mutating project state
--fixApply safe fixes for type-checking errors
--group, --extra, --all-extrasInclude 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 check on 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 running uv 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?

SymptomLikely causeFix
error: unrecognized subcommand 'check'uv is too oldUpgrade to 0.12.3 or newer
unresolved-import for a script’s dependencyScript checked as part of the projectUse uv check --script
Different results locally and in CIUnpinned tyuv add --dev ty==X and commit uv.lock
Imports from optional extras unresolvedExtras not installedAdd --all-extras or --extra NAME
Lockfile changes in CIDependencies edited without relockingRun 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

Official references

Leave a Reply