Installation
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:pyproject.toml for the latest compatible version:
Matrix Builds
Test across multiple Python versions:Using UV_PYTHON Environment Variable
Installing Dependencies
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 theactions/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 theuv pip interface, enable system Python:
Private Repositories
Access private GitHub repositories using a Personal Access Token (PAT):Create and store PAT
Create a PAT with repository read access and add it as a repository secret (e.g.,
MY_PAT).Publishing to PyPI
Publish packages using trusted publishing (no credentials needed):Configure PyPI environment
Create a
pypi environment in your repository settings under Settings → Environments.Add trusted publisher
Configure trusted publishing in your PyPI project settings, matching the workflow name, environment, and repository details.