uv Knowledge Patch
Use this guidance when changing uv-managed Python projects, environments,
dependency resolution, package indexes, publishing, or CI and container
workflows. Confirm the installed uv version and the repository's manifests,
lockfiles, configuration, and tests before applying compatibility advice.
Working Method
- Run
uv self version to identify uv itself. uv version reads or changes
the current project's version and errors outside a project.
- Inspect
pyproject.toml, uv.toml, .python-version, uv.lock, relevant
pylock*.toml inputs, requirements files, and container configuration.
- Identify which commands and settings are preview behavior. Avoid making a
durable workflow depend on preview behavior without pinning and testing it.
- Read the task-specific reference below before choosing flags or settings.
- Preserve lock intent: use
uv lock --check or --locked for verification;
reserve uv lock --refresh for deliberate canonical regeneration.
- Treat credentials, certificate overrides, publishing, archive validation,
environment replacement, and interpreter selection as state-sensitive.
- Prefer observed project behavior and tests when a newer installed uv
differs from this guidance.
Reference Index
| Reference |
Topics |
| projects-and-workspaces |
Initialization, project versions, builds, workspaces, path members, groups, and project checks |
| python-environments-and-platforms |
Interpreter discovery, managed Python, virtual environments, platform targets, containers, and tool Python pins |
| dependency-resolution-and-lockfiles |
Resolution controls, constraints, cutoffs, dependency inputs, lock checks, PEP 751, and hashes |
| indexes-auth-and-publishing |
Named indexes, authentication, credentials, certificates, archives, and publishing |
| tooling-and-operations |
Release boundaries, subprocesses, uvx, formatting, auditing, exports, cache output, and runtime controls |
Breaking Changes and Deprecations
Initialization now creates a packaged project
uv init <name> creates a src/ package, project script, and uv_build
configuration, then installs the project. Use --no-package when the former
unpackaged main.py layout is intended. The older uv init --project spelling
is deprecated; pass the target path positionally.
Pre-release resolution can fall back automatically
The default if-necessary policy tries stable candidates first and then
permits pre-releases when no stable candidate satisfies active constraints,
including constraints found transitively. Use --prerelease disallow,
allow, or explicit when the policy must be unambiguous. The
if-necessary-or-explicit name is deprecated.
Lock and requirements validation is stricter
uv lock --check and --locked reject non-canonically formatted
uv.lock; use uv lock --refresh for an intentional rewrite.
- A
--require-hashes directive inside a requirements file enables hash mode
for uv pip install and uv pip sync. Every requirement must then be
pinned and hashed, and MD5 alone is insufficient.
- PEP 751 files require a
packages array and a valid pylock.toml or
pylock.<name>.toml filename. Declared artifact sizes are checked.
- Nonexistent local extras, missing frozen groups, and unknown group object
specifiers are errors. Do not combine
--frozen with --no-sources.
Index and trust failures are fail-closed
With the default first-index strategy, a 401 or 403 stops lookup. Set
authenticate = "always" when credentials are mandatory, and add
ignore-error-codes only for an index whose unusual behavior requires
fallthrough. Explicit invalid SSL_CERT_FILE or SSL_CERT_DIR values no
longer fall back to default trust roots.
Archive handling rejects ambiguous or dangerous inputs
ZIP archives with duplicate or ambiguous entries are rejected. Source
distributions must use .tar.gz or the accepted legacy .zip form, and
wheels are rejected when entry points or data files could overwrite a Python
interpreter. Keep insecure ZIP validation bypasses temporary and exceptional.
Platform and image defaults moved
- The
linux platform alias means manylinux_2_28; request
x86_64-manylinux_2_17 explicitly for the older target.
- Floating container images use Debian 13 Trixie and Alpine 3.22. Removed tags
include Bookworm, Alpine 3.21, and Python 3.8.
- Derived images default
UV_TOOL_BIN_DIR to /usr/local/bin; override it for
an unprivileged user that cannot write there.
Environment replacement is guarded
Interactive uv venv prompts before removing an existing environment and
refuses to remove a directory that is not a virtual environment. Use
--clear for explicit replacement or --no-clear to prohibit it.
High-Value Workflows
Check lockfile and environment freshness
uv lock --check
uv sync --check
A stale lockfile or environment returns status 1; status 2 is an operational
error. Keep that distinction in CI. Isolated operations do not update
uv.lock.
Target workspace operations precisely
uv workspace list --paths
uv workspace dir
uv check --package my-package
uv check --all-packages
Workspace listing and directory discovery are stable scripting interfaces.
Package selection for uv check is preview behavior. Workspace metadata can
include best-effort active-environment information, so its output may depend
on the invoking environment.
Control dependency resolution
- Use
tool.uv.build-constraint-dependencies for build-time constraints,
including ephemeral uv run --with, tools, and inline scripts.
- Use
default-groups = "all", per-group requires-python, and
tool.uv.required-environments to control group inclusion and wheel
coverage.
- Prefer
exclude-dependencies, selective --no-sources-package, bounds,
and package-specific or relative exclude-newer cutoffs over broad global
workarounds.
- Marker-aware
uv upgrade can update multiple declarations of one package
when environment markers distinguish them.
Exchange standardized results
uv export -o pylock.toml
uv pip compile -o pylock.toml requirements.in
uv pip sync pylock.toml
uv pip install -r pylock.toml
uv can generate, export, install, and sync PEP 751 lockfiles. CycloneDX export
produces an SBOM and includes artifact URLs and hashes. Preview sync output can
report package changes as JSON.
Select Python deliberately
uv python install honors UV_PYTHON before .python-version.
- In
uv pip compile, -p means --python, not --python-version.
- Unversioned installation and automatic-download defaults favor Python 3.14.
Discovery may select a free-threaded 3.14+ interpreter without a
t
suffix, while installation still prefers a GIL-enabled build.
- Global Python pins can affect new tool environments, but an existing tool
retains its interpreter until reinstalled or explicitly changed.
Run tools and ephemeral requirements safely
uvx <name> verifies that the named package or one of its dependencies
provides the executable. Use uvx --from <package> <command> when package and
command intentionally differ. uv run --with executes in a fresh empty layer
over a cached requirement environment, so runtime inspection or mutation does
not target the cached layer itself.
Audit, format, and publish with explicit stability choices
uv audit, uv format, uv sync JSON output, relocatable environments,
package-level workspace conflicts, and several check, index, publishing,
and malware-screening features are preview behavior.
- Pin Ruff with
uv format --version when formatting reproducibility matters;
the formatter's default style can change.
- Publishing supports stored
uv auth credentials, PEP 740 attestations,
Trusted Publishing with pyx, S3 pre-signed URLs, and GCS signing. Verify the
stability and trust path selected by the workflow.
Final Checks
- Confirm stable versus preview status for every command added to automation.
- Re-run lock and environment checks after dependency or project-version
changes.
- Test the intended Python implementation, GIL mode, and target platform for
cross-platform artifacts.
- Verify index names, authentication policy, credential username, proxy,
timeout, and certificate settings before diagnosing resolution failures.
- Pin formatter behavior and container tags when reproducibility matters.
- Inspect archive and lockfile inputs before weakening validation.
1---2name: uv-knowledge-patch3description: uv4license: MIT5---678# uv Knowledge Patch910Use this guidance when changing uv-managed Python projects, environments,11dependency resolution, package indexes, publishing, or CI and container12workflows. Confirm the installed uv version and the repository's manifests,13lockfiles, configuration, and tests before applying compatibility advice.1415## Working Method16171. Run `uv self version` to identify uv itself. `uv version` reads or changes18 the current project's version and errors outside a project.192. Inspect `pyproject.toml`, `uv.toml`, `.python-version`, `uv.lock`, relevant20 `pylock*.toml` inputs, requirements files, and container configuration.213. Identify which commands and settings are preview behavior. Avoid making a22 durable workflow depend on preview behavior without pinning and testing it.234. Read the task-specific reference below before choosing flags or settings.245. Preserve lock intent: use `uv lock --check` or `--locked` for verification;25 reserve `uv lock --refresh` for deliberate canonical regeneration.266. Treat credentials, certificate overrides, publishing, archive validation,27 environment replacement, and interpreter selection as state-sensitive.287. Prefer observed project behavior and tests when a newer installed uv29 differs from this guidance.3031## Reference Index3233| Reference | Topics |34| --- | --- |35| [projects-and-workspaces](references/projects-and-workspaces.md) | Initialization, project versions, builds, workspaces, path members, groups, and project checks |36| [python-environments-and-platforms](references/python-environments-and-platforms.md) | Interpreter discovery, managed Python, virtual environments, platform targets, containers, and tool Python pins |37| [dependency-resolution-and-lockfiles](references/dependency-resolution-and-lockfiles.md) | Resolution controls, constraints, cutoffs, dependency inputs, lock checks, PEP 751, and hashes |38| [indexes-auth-and-publishing](references/indexes-auth-and-publishing.md) | Named indexes, authentication, credentials, certificates, archives, and publishing |39| [tooling-and-operations](references/tooling-and-operations.md) | Release boundaries, subprocesses, `uvx`, formatting, auditing, exports, cache output, and runtime controls |4041## Breaking Changes and Deprecations4243### Initialization now creates a packaged project4445`uv init <name>` creates a `src/` package, project script, and `uv_build`46configuration, then installs the project. Use `--no-package` when the former47unpackaged `main.py` layout is intended. The older `uv init --project` spelling48is deprecated; pass the target path positionally.4950### Pre-release resolution can fall back automatically5152The default `if-necessary` policy tries stable candidates first and then53permits pre-releases when no stable candidate satisfies active constraints,54including constraints found transitively. Use `--prerelease disallow`,55`allow`, or `explicit` when the policy must be unambiguous. The56`if-necessary-or-explicit` name is deprecated.5758### Lock and requirements validation is stricter5960- `uv lock --check` and `--locked` reject non-canonically formatted61 `uv.lock`; use `uv lock --refresh` for an intentional rewrite.62- A `--require-hashes` directive inside a requirements file enables hash mode63 for `uv pip install` and `uv pip sync`. Every requirement must then be64 pinned and hashed, and MD5 alone is insufficient.65- PEP 751 files require a `packages` array and a valid `pylock.toml` or66 `pylock.<name>.toml` filename. Declared artifact sizes are checked.67- Nonexistent local extras, missing frozen groups, and unknown group object68 specifiers are errors. Do not combine `--frozen` with `--no-sources`.6970### Index and trust failures are fail-closed7172With the default `first-index` strategy, a 401 or 403 stops lookup. Set73`authenticate = "always"` when credentials are mandatory, and add74`ignore-error-codes` only for an index whose unusual behavior requires75fallthrough. Explicit invalid `SSL_CERT_FILE` or `SSL_CERT_DIR` values no76longer fall back to default trust roots.7778### Archive handling rejects ambiguous or dangerous inputs7980ZIP archives with duplicate or ambiguous entries are rejected. Source81distributions must use `.tar.gz` or the accepted legacy `.zip` form, and82wheels are rejected when entry points or data files could overwrite a Python83interpreter. Keep insecure ZIP validation bypasses temporary and exceptional.8485### Platform and image defaults moved8687- The `linux` platform alias means `manylinux_2_28`; request88 `x86_64-manylinux_2_17` explicitly for the older target.89- Floating container images use Debian 13 Trixie and Alpine 3.22. Removed tags90 include Bookworm, Alpine 3.21, and Python 3.8.91- Derived images default `UV_TOOL_BIN_DIR` to `/usr/local/bin`; override it for92 an unprivileged user that cannot write there.9394### Environment replacement is guarded9596Interactive `uv venv` prompts before removing an existing environment and97refuses to remove a directory that is not a virtual environment. Use98`--clear` for explicit replacement or `--no-clear` to prohibit it.99100## High-Value Workflows101102### Check lockfile and environment freshness103104```console105uv lock --check106uv sync --check107```108109A stale lockfile or environment returns status 1; status 2 is an operational110error. Keep that distinction in CI. Isolated operations do not update111`uv.lock`.112113### Target workspace operations precisely114115```console116uv workspace list --paths117uv workspace dir118uv check --package my-package119uv check --all-packages120```121122Workspace listing and directory discovery are stable scripting interfaces.123Package selection for `uv check` is preview behavior. Workspace metadata can124include best-effort active-environment information, so its output may depend125on the invoking environment.126127### Control dependency resolution128129- Use `tool.uv.build-constraint-dependencies` for build-time constraints,130 including ephemeral `uv run --with`, tools, and inline scripts.131- Use `default-groups = "all"`, per-group `requires-python`, and132 `tool.uv.required-environments` to control group inclusion and wheel133 coverage.134- Prefer `exclude-dependencies`, selective `--no-sources-package`, bounds,135 and package-specific or relative `exclude-newer` cutoffs over broad global136 workarounds.137- Marker-aware `uv upgrade` can update multiple declarations of one package138 when environment markers distinguish them.139140### Exchange standardized results141142```console143uv export -o pylock.toml144uv pip compile -o pylock.toml requirements.in145uv pip sync pylock.toml146uv pip install -r pylock.toml147```148149uv can generate, export, install, and sync PEP 751 lockfiles. CycloneDX export150produces an SBOM and includes artifact URLs and hashes. Preview sync output can151report package changes as JSON.152153### Select Python deliberately154155- `uv python install` honors `UV_PYTHON` before `.python-version`.156- In `uv pip compile`, `-p` means `--python`, not `--python-version`.157- Unversioned installation and automatic-download defaults favor Python 3.14.158 Discovery may select a free-threaded 3.14+ interpreter without a `t`159 suffix, while installation still prefers a GIL-enabled build.160- Global Python pins can affect new tool environments, but an existing tool161 retains its interpreter until reinstalled or explicitly changed.162163### Run tools and ephemeral requirements safely164165`uvx <name>` verifies that the named package or one of its dependencies166provides the executable. Use `uvx --from <package> <command>` when package and167command intentionally differ. `uv run --with` executes in a fresh empty layer168over a cached requirement environment, so runtime inspection or mutation does169not target the cached layer itself.170171### Audit, format, and publish with explicit stability choices172173- `uv audit`, `uv format`, `uv sync` JSON output, relocatable environments,174 package-level workspace conflicts, and several check, index, publishing,175 and malware-screening features are preview behavior.176- Pin Ruff with `uv format --version` when formatting reproducibility matters;177 the formatter's default style can change.178- Publishing supports stored `uv auth` credentials, PEP 740 attestations,179 Trusted Publishing with pyx, S3 pre-signed URLs, and GCS signing. Verify the180 stability and trust path selected by the workflow.181182## Final Checks183184- Confirm stable versus preview status for every command added to automation.185- Re-run lock and environment checks after dependency or project-version186 changes.187- Test the intended Python implementation, GIL mode, and target platform for188 cross-platform artifacts.189- Verify index names, authentication policy, credential username, proxy,190 timeout, and certificate settings before diagnosing resolution failures.191- Pin formatter behavior and container tags when reproducibility matters.192- Inspect archive and lockfile inputs before weakening validation.