actions/setup-python: Install Python in CI
setup-python installs the Python version you ask for and can cache pip downloads.
Pin a Python version (or matrix several) and optionally cache pip, pipenv, or poetry to speed up installs.
Key inputs (with:)
- python-version: e.g. 3.12 or a range like 3.x.
- python-version-file: read from .python-version or pyproject.toml.
- cache: pip, pipenv, or poetry.
- cache-dependency-path: requirements or lock file path.
- architecture: x64 or arm64.
Example workflow
.github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
- run: pip install -r requirements.txt
- run: pytestOn any runner
setup-python works on any runner. Latchkey managed runners run it unchanged, cheaper and self-healing.
Key takeaways
- Use a matrix to test multiple Python versions in parallel.
- cache: pip skips re-downloading wheels between runs.
- python-version-file keeps CI in sync with local tooling.
Related guides
actions/checkout: Inputs & Workflow UsageReference for actions/checkout: clone your repository into the runner, control fetch-depth, submodules, refs,…
codecov/codecov-action: Upload Coverage ReportsReference for codecov/codecov-action: upload test coverage reports to Codecov with a token, flags, and file p…