# Python application workflow

> GitHub's official Python application starter workflow, explained and hardened by Latchkey.

Source: https://latchkey.dev/workflows/python-application  
Upstream: [GitHub official starter workflow](https://github.com/actions/starter-workflows/blob/main/ci/python-app.yml) (ci/python-app.yml), licence CC0-1.0

## What it does

This is the Python application workflow GitHub offers by default. It sets up Python, installs dependencies, lints with flake8, and runs tests with pytest.

Notably it does not cache pip downloads and sets no job timeout or concurrency, all of which Latchkey adds below.

## The workflow

```yaml
name: Python application

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python 3.10
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install flake8 pytest
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
      - name: Lint with flake8
        run: |
          flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
      - name: Test with pytest
        run: pytest
```

## FAQ

### What does the Python application workflow workflow do?

This is the Python application workflow GitHub offers by default. It sets up Python, installs dependencies, lints with flake8, and runs tests with pytest.

### What CI health grade does this workflow get?

This Python workflow grades D. Paste your own workflow into the Latchkey grader to see its grade and the exact fixes.

### How can I improve this Python workflow?

Add run de-duplication, caching, and job timeouts. Latchkey applies these automatically on managed runners when you point runs-on at Latchkey.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
