Skip to main content
Integrate uv into your GitHub Actions workflows for fast, reliable Python dependency management and CI/CD automation.

Installation

1

Install latest version

Use the official astral-sh/setup-uv action:
2

Pin to specific version (recommended)

Setting Up Python

Using uv python install

Install Python using uv (respects project’s pinned version):

Using actions/setup-python

Alternatively, use GitHub’s cached Python versions:
Or use pyproject.toml for the latest compatible version:

Matrix Builds

Test across multiple Python versions:

Using UV_PYTHON Environment Variable

Installing Dependencies

1

Sync project dependencies

2

Install without dev dependencies

3

Run tests

Caching

Built-in Caching with setup-uv

The easiest approach uses the action’s built-in caching:

Manual Caching with actions/cache

For more control, use the actions/cache action:
Use uv cache prune --ci to optimize cache size. If using uv pip, replace uv.lock with requirements.txt in the cache key.

Complete CI Workflow

Here’s a complete example combining best practices:

Using uv pip

If using the uv pip interface, enable system Python:
Or at the job level:
Or at the step level:

Private Repositories

Access private GitHub repositories using a Personal Access Token (PAT):
1

Create and store PAT

Create a PAT with repository read access and add it as a repository secret (e.g., MY_PAT).
2

Configure Git credential helper

Publishing to PyPI

Publish packages using trusted publishing (no credentials needed):
1

Create publish workflow

2

Configure PyPI environment

Create a pypi environment in your repository settings under Settings → Environments.
3

Add trusted publisher

Configure trusted publishing in your PyPI project settings, matching the workflow name, environment, and repository details.
4

Trigger release

See astral-sh/trusted-publishing-examples for a complete working example.