GUARDLABS
GuardLabs ยท Technical note

Schedule a Python Script to Run Automatically Without a Server

To run a Python script on a schedule without provisioning or maintaining a dedicated server (VPS), choose between Cloud Serverless (executes in the cloud regardless of your local machine's power state) or OS-Native Schedulers (executes on your local machine in the background).

1. Cloud Serverless (Best for 24/7 Reliability)

If your computer is turned off regularly, cloud serverless options are required. GitHub Actions provides 2,000 free execution minutes per month for public and private repositories using standard cron syntax.

Create .github/workflows/scheduled_script.yml in your repository:

name: Scheduled Python Run

on:
  schedule:
    # Runs at 09:00 UTC every day
    - cron: '0 9 * * *'
  workflow_dispatch: # Allows manual triggers from GitHub UI

jobs:
  run-python:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repo
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Install dependencies
        run: |
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

      - name: Execute script
        env:
          MY_API_KEY: ${{ secrets.MY_API_KEY }}
        run: python main.py

Alternative Cloud Providers: AWS Lambda (paired with EventBridge rules) or Google Cloud Functions (paired with Cloud Scheduler) for event-driven payloads or long-running jobs.

2. Local OS Schedulers (Requires Computer to Stay On)

If your script accesses local files, local network resources, or runs on hardware that is always on, use native OS background schedulers.

macOS / Linux: Cron

Cron is built into Unix-based systems. Open the user cron table in terminal:

crontab -e

Add a line using full system paths for both the Python executable and your script:

# Runs every day at 08:00 AM local time
0 8 * * * /usr/bin/python3 /Users/username/scripts/main.py >> /Users/username/scripts/cron.log 2>&1

Windows: Task Scheduler

Windows Task Scheduler manages background processes without a third-party server. Open Command Prompt as Administrator and run schtasks:

schtasks /create /tn "MyPythonTask" /tr "C:\Python311\python.exe C:\scripts\main.py" /sc daily /st 08:00

Alternatively, open the Task Scheduler GUI > Create Basic Task > Set Action to Start a program > Program: python.exe > Add arguments: C:\path\to\script.py.

Comparison Matrix

  • GitHub Actions / Cloud Functions:
    • Power Dependency: Runs independently of your computer.
    • Cost: Free tier available; pay-per-use after limits.
    • Setup Effort: Medium (requires Git, YAML, environment secret configuration).
    • Best For: Web scraping, sending alerts, API polling, automated reports.
  • Linux/macOS Cron:
    • Power Dependency: Machine must be powered on and awake.
    • Cost: Free.
    • Setup Effort: Low (1-line terminal command).
    • Best For: Local file processing, system maintenance, offline tasks.
  • Windows Task Scheduler:
    • Power Dependency: Machine must be powered on.
    • Cost: Free.
    • Setup Effort: Low (GUI or CLI).
    • Best For: Windows-native automation, Excel automation, local database updates.

Which One Should You Pick?

  • Select GitHub Actions or Cloud Serverless if the execution must occur at exact intervals without fail, regardless of whether your laptop is open or connected to Wi-Fi.
  • Select Cron or Task Scheduler if the script requires access to local files on your hard drive, local databases, or desktop GUI automation.

Need this done fast? order this automation on FreelanceHunt.

Published 2026-07-30 2 min read All articles
Need help with this?

I take on freelance fixes and builds in this area.