# WithUv

- Module: [Aspire.Hosting.Python](/reference/api/go/aspire.hosting.python.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: [`PythonAppResource`](/reference/api/go/aspire.hosting.python/pythonappresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/tree/bcfa151cdca6d0a573f22d5d9c23f9c727cb3b2f)

Adds a UV environment setup task to ensure the virtual environment exists before running the Python application.

## Remarks

This method creates a child resource that runs `uv sync` in the working directory of the Python application.
The Python application will wait for this resource to complete successfully before starting.
UV (https://github.com/astral-sh/uv) is a modern Python package manager written in Rust that can manage virtual environments
and dependencies with significantly faster performance than traditional tools. The `uv sync` command ensures that the virtual
environment exists, Python is installed if needed, and all dependencies specified in pyproject.toml are installed and synchronized.
Calling this method will replace any previously configured package manager (such as pip).

## Definition

```go
func (PythonAppResource) WithUv(options ...*WithUvOptions) PythonAppResource
```

## Parameters

- `options` (`...*WithUvOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*WithUvOptions` argument.

- `Install` (`*bool`) -- When true (default), automatically runs uv sync before the application starts. When false, only sets the package manager annotation without creating an installer resource.
- `Args` (`[]string`) -- Optional custom arguments to pass to the uv command. If not provided, defaults to ["sync"].

## Returns

[`PythonAppResource`](/reference/api/go/aspire.hosting.python/pythonappresource.md) -- The resource builder.

Returns a handle; failures surface later via `Err()`.

## Applies to

- [`PythonAppResource`](/reference/api/go/aspire.hosting.python/pythonappresource.md)
- [`UvicornAppResource`](/reference/api/go/aspire.hosting.python/uvicornappresource.md)
