mrkeyoor.com_
Sat 24 Oct 07:22 UTC
Open Source3 min read

How uv and ty check standalone Python scripts

uv and ty can check standalone Python scripts against their declared requirements. Automatic editor setup is experimental; untrusted workspaces disable the editor's uv integrations.

Astral's package manager uv and type checker ty have an experimental integration for checking standalone Python scripts against their declared requirements. A utility can use different dependencies or Python requirements from the application beside it, and ty can check it using a separate environment prepared by uv.

This explanation is for developers who maintain those scripts alongside a larger project. Astral specifies uv 0.12.3 or later and ty 0.0.76 or later. The supplied evidence contains documentation, not execution results: MrKeyoor has not tested the commands or verified editor output. Automatic editor setup remains experimental and opt-in.

How a script declares its requirements

PEP 723 describes metadata embedded in a Python comment block. Its dependencies field declares runtime dependencies, and requires-python specifies compatible Python versions. A script can carry these requirements without a separate project configuration. The PEP identifies itself as a historical document and directs readers to the PyPA specification for the current canonical standard.

Astral says ty uses this metadata and invokes uv to prepare each script's environment, including installing its declared dependencies. This gives scripts in one repository a way to be checked against different requirements. Before trying it, review whether each script's declarations match what it needs.

Choose what the editor may prepare

The ty editor reference documents three modes for experimental.useUv. The off mode does not use uv. The scripts mode creates and updates environments for standalone scripts with PEP 723 metadata. The on mode also uses uv for project discovery.

For a trial limited to script environments, install uv and the ty VS Code extension, then add this documented setting to VS Code's settings.json:

{
  "ty.experimental.useUv": "scripts"
}

Restart the editor after changing this initialization setting. This is an unexecuted documentation example, not a verified setup result.

Untrusted workspaces disable all uv integrations in the editor. The VS Code extension sets that status from Workspace Trust; there is no user-facing ty.untrustedWorkspace setting. Open the workspace in Restricted Mode to mark it as untrusted.

That choice matters because Astral warns that installing dependencies can require execution of third-party Python code. Developers who do not want the editor to prepare environments can select off or keep the workspace untrusted. These editor controls should not be treated as restrictions on commands invoked separately.

Check a standalone script separately

The Astral announcement says standalone PEP 723 scripts have independent environments and are checked separately. It documents this command:

uv check --script example.py

Replace example.py with the script to check against its declared requirements. This command is an unexecuted example from Astral's announcement. Running uv check enables the integration automatically without additional configuration, so switching off the editor integration does not switch off the command's integration.

Astral describes Ruff support in uv check and checks for unused dependencies as future work. Keep the linting steps your workflow needs. To evaluate this preview, start with one script whose requirements you have reviewed, try the documented checking command, and assess its diagnostics before enabling automatic editor setup more broadly.

Sources

  1. Bringing uv and ty together
  2. PEP 723: Inline script metadata
  3. ty editor settings