NIXX/DEVv1.14.0
ArticlesFavorites
Sign In
Sign In
Articles

Welcome to our blog

A curated collection of insightful articles, practical guides, and expert tips designed to simplify your workflow

Cover image for: Automate Your Python Script Deployments with GitHub Actions
July 4, 20255 MIN READ min readBy ℵi✗✗

Automate Your Python Script Deployments with GitHub Actions

From manual runs to scheduled automation—learn how to run and deploy Python scripts using GitHub Actions.

automationpythongithub actionsguide
ℵi✗✗

ℵi✗✗

Full-Stack Developer

Passionate about building tools and sharing knowledge with the developer community.

Was this helpful?

Popular Posts

  • NixOS vs. Arch Linux: Which One Belongs in Your Dev Setup?

    NixOS vs. Arch Linux: Which One Belongs in Your Dev Setup?

    5 MIN READ min read

  • How to Enable HTTPS on Localhost in Under 2 Minutes

    How to Enable HTTPS on Localhost in Under 2 Minutes

    3 MIN READ min read

  • Migrating from Create React App (CRA) to Vite: A Step-by-Step Guide

    Migrating from Create React App (CRA) to Vite: A Step-by-Step Guide

    4 MIN READ min read

  • Array Destructuring in PHP: A Practical Guide for Modern Developers

    Array Destructuring in PHP: A Practical Guide for Modern Developers

    5 MIN READ min read

Recommended Products

  • Apple iPad (7th Gen)

    Apple iPad (7th Gen)

    4.3
  • Fitbit Versa 4

    Fitbit Versa 4

    4.3
  • JBL Flip 6

    JBL Flip 6

    4.8
  • Dell 24 Monitor — SE2425HM Full HD

    Dell 24 Monitor — SE2425HM Full HD

    4.7

May contain affiliate links

Topics

webdev33productivity16cybersecurity12javascript11automation9guide8react7typescript7php6tutorial6freelancing5github actions5privacy5how to4Node.js4
+111 more topics →
🇺🇸USD ACCOUNTOpen a free US-based USD accountReceive & save in USD — powered by ClevaSponsoredInterserver Hosting#1 VALUEAffordable, reliable hosting from $2.50/mo99.9% uptimeSponsored

Running a Python script manually every time it is needed works at first. It stops working when the script needs to run daily, when you are not at the machine, or when the output needs to be available somewhere other than a local folder.

GitHub Actions solves this without requiring a server, a cron job on a remote machine, or any DevOps infrastructure. A workflow file in the repository defines when and how the script runs. Everything else is handled by GitHub.

This guide covers setting up a Python script for automated execution, creating a workflow that triggers on push or a schedule, saving output files as downloadable artefacts, and optionally routing results to cloud storage or email.

What this covers:

  • Structuring a Python script and repository for GitHub Actions

  • Creating a workflow that triggers on push and on a schedule

  • Installing dependencies and running the script in the workflow

  • Saving output files as build artefacts

  • Optional: uploading results to Google Drive or sending via email


What Gets Built

By the end of this guide, a GitHub repository will:

  • Run a Python script automatically on every push to main

  • Run the same script on a daily schedule using a cron expression

  • Install any required dependencies before each run

  • Save output files (CSVs, logs, reports) as downloadable artefacts from the Actions tab

Practical use cases this covers: daily web scraping, scheduled report generation, data cleaning pipelines, and any recurring task currently run by hand.


Step 1: Prepare the Python Script

The script needs to run cleanly from the command line with no interactive input. A minimal example that writes output to a file:

# main.py
import datetime

now = datetime.datetime.now()
print(f"Script executed at: {now}")

with open("output.txt", "w") as f:
    f.write(f"Last run: {now}\n")
    f.write("This file was generated by GitHub Actions.")

If the script has dependencies, list them in requirements.txt:

requests==2.31.0
pandas==2.1.0

Pinning versions in requirements.txt ensures the workflow installs exactly the same library versions every run, which prevents dependency updates from silently breaking the script.


Step 2: Push the Repository to GitHub

The repository structure before adding the workflow:

your-repo/
├── main.py
├── requirements.txt
└── .github/
    └── workflows/

Create the .github/workflows/ directory now. The workflow file added in the next step goes there.


Step 3: Create the Workflow File

Create .github/workflows/run-python.yml with the following content:

name: Run Python Script

on:
  push:
    branches:
      - main
  schedule:
    - cron: '0 8 * * *'  # Runs every day at 8:00 AM UTC

jobs:
  run-script:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Code
        uses: actions/checkout@v4

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

      - name: Install Dependencies
        run: |
          pip install --upgrade pip
          pip install -r requirements.txt

      - name: Run Python Script
        run: python main.py

      - name: Upload Output File
        uses: actions/upload-artifact@v4
        with:
          name: script-output
          path: output.txt

What this workflow does, step by step:

  • Triggers on every push to main and once daily at 08:00 UTC

  • Checks out the repository code onto the runner

  • Installs Python 3.11

  • Upgrades pip and installs the dependencies from requirements.txt

  • Runs main.py

  • Uploads output.txt as a named artefact available for download

The cron expression '0 8 * * *' means: minute 0, hour 8, every day of the month, every month, every day of the week. Adjusting the hour and minute values changes when it runs. GitHub uses UTC, so account for the offset from your local timezone.

Note: GitHub Actions does not guarantee exact cron timing under high load. Scheduled runs may be delayed by several minutes but will not be skipped.


Step 4: View and Download Artefacts

After the workflow runs:

  1. Open the repository on GitHub and click the Actions tab

  2. Select the workflow run from the list

  3. Scroll to the Artefacts section at the bottom of the run summary

  4. Click the artefact name to download it

GitHub retains artefacts for 90 days by default. For output that needs to persist longer or be accessible outside of GitHub, the optional steps below cover routing results to cloud storage or email.


Optional: Extend with Cloud Storage or Email

Upload Output to Google Drive

- name: Upload to Google Drive
  uses: itrsgroup/drive-upload-action@v1
  with:
    client_id: ${{ secrets.DRIVE_CLIENT_ID }}
    client_secret: ${{ secrets.DRIVE_CLIENT_SECRET }}
    refresh_token: ${{ secrets.DRIVE_REFRESH_TOKEN }}
    file_path: output.txt

Store the OAuth credentials in GitHub Secrets under repository Settings. The DRIVE_REFRESH_TOKEN requires completing a Google OAuth flow once to obtain the refresh token, which the action then uses for all subsequent uploads.

Send Output via Email

- name: Send Email
  uses: dawidd6/action-send-mail@v3
  with:
    server_address: smtp.gmail.com
    server_port: 465
    username: ${{ secrets.EMAIL_USER }}
    password: ${{ secrets.EMAIL_PASSWORD }}
    subject: Python Script Output
    body: Attached is today's output.
    attachments: output.txt

For Gmail, use an App Password rather than the account password. Store both values in GitHub Secrets.


Common Issues and Fixes

Script runs locally but fails in the workflow. The most common cause is a dependency missing from requirements.txt. Add pip list as a step before the run step to log what is installed, then compare against what the script imports.

The scheduled run is not triggering. GitHub pauses scheduled workflows on repositories with no activity for 60 days. Push a commit or manually trigger the workflow from the Actions tab to reactivate it.

The artefact upload step fails with "no files found". The path in upload-artifact must match exactly where the script writes its output. Print the working directory in the script with print(os.getcwd()) and verify the output file path is correct.


Key Takeaways

  • GitHub Actions runs Python scripts automatically on push or a cron schedule without requiring a server.

  • Pinning dependency versions in requirements.txt ensures consistent behavior across every workflow run.

  • Artefacts store output files for 90 days and are downloadable directly from the Actions tab.

  • Google Drive uploads and email delivery are available through third-party actions, with credentials stored in GitHub Secrets.

  • Scheduled workflows on inactive repositories are paused after 60 days and need to be manually reactivated.


Conclusion

Any Python script that runs manually on a schedule is a candidate for automation with GitHub Actions. The setup is low overhead: a repository, a workflow file, and the existing script. The result is a process that runs reliably whether or not anyone is at the machine, with output stored and accessible without any manual steps.

The workflow structure covered here scales to more complex scripts without changing the approach. Additional steps, conditional logic, matrix builds across Python versions, and integration with other tools all follow the same YAML-based pattern established in this guide.


Automating a specific Python workflow and running into a problem? Describe it in the comments.

Topics
automationpythongithub actionsguide
Interserver Hosting#1 VALUEAffordable, reliable hosting from $2.50/mo99.9% uptimeSponsored

Discussion

Join the discussion

Sign in to share your thoughts and engage with the community.

Sign In
Loading comments…

Continue Reading

More Articles

View all
Cover image for: Embedding Cybersecurity in Development: Best Practices for 2025
Jul 1, 20257 MIN READ min read

Embedding Cybersecurity in Development: Best Practices for 2025

A developer-focused guide to integrating security into your workflow—covering tools, practices, and mindset shifts for 2025.

Cover image for: Array Destructuring in PHP: A Practical Guide for Modern Developers
Mar 12, 20255 MIN READ min read

Array Destructuring in PHP: A Practical Guide for Modern Developers

From PHP 7.1 to 8.1—learn how array destructuring simplifies variable assignment, reduces boilerplate, and improves readability in modern PHP development.

Cover image for: Build a Fun Alphabet Reader with TypeScript, Vite & Speech Synthesis API
Jun 27, 20254 MIN READ min read

Build a Fun Alphabet Reader with TypeScript, Vite & Speech Synthesis API

An interactive, educational project for beginners to learn modern frontend development.

Cover image for: Why You Should Use TypeScript in Every JavaScript Project
Jul 23, 20255 MIN READ min read

Why You Should Use TypeScript in Every JavaScript Project

JavaScript gets the job done—but TypeScript helps you write cleaner, safer, and easier-to-maintain code. Here’s why it’s worth using everywhere.

|Made with · © 2026|TermsPrivacy
AboutBlogContact

Free, open-source tools for developers and creators · Community driven