Skip to content
Latchkey

How to Run a Job on Multiple Python Versions in GitHub Actions

A version matrix fans one job out into one parallel run per Python interpreter.

List the versions under strategy.matrix, then pass matrix.python-version to actions/setup-python. Each value becomes its own job.

Steps

  • Declare a python-version matrix array.
  • Feed matrix.python-version to actions/setup-python.
  • Optionally set fail-fast: false to keep other versions running when one fails.

Workflow

.github/workflows/test.yml
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ['3.10', '3.11', '3.12', '3.13']
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - run: pip install -e '.[test]' && pytest

Gotchas

  • Use quotes around versions so 3.10 is not parsed as the number 3.1.
  • Pin a single version for the deploy job; a matrix is for testing.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →