↓ Skip to main content

10 Practical Python Automation Scripts

10 Practical Python Automation Scripts

Repetitive tasks can consume valuable time: resizing hundreds of images, extracting PDF pages, fetching API data, correcting text, downloading files, or monitoring system status.

Python provides a large ecosystem of libraries that can automate many of these workflows with relatively little code.

This article presents 10 practical Python automation scripts covering image and video processing, PDFs, APIs, notifications, text correction, downloads, news retrieval, and desktop GUI development.

🖼️ 1. Image Optimizer
#

The Pillow library provides a convenient API for common image-processing tasks such as cropping, resizing, rotating, flipping, filtering, and adjusting brightness or contrast.

# pip install Pillow

from PIL import Image, ImageEnhance, ImageFilter, ImageOps

image = Image.open("Image1.jpg")

# Crop
image = image.crop((34, 23, 100, 100))

# Resize
image = image.resize((50, 50))

# Flip
image = image.transpose(Image.Transpose.FLIP_LEFT_RIGHT)

# Rotate
image = image.rotate(90)

# Blur
image = image.filter(ImageFilter.BLUR)

# Sharpen
image = image.filter(ImageFilter.SHARPEN)

# Brightness
image = ImageEnhance.Brightness(image).enhance(1.5)

# Contrast
image = ImageEnhance.Contrast(image).enhance(1.5)

# Image operations
image = ImageOps.grayscale(image)

# Save with JPEG optimization
image.save("Image1.jpg", optimize=True, quality=90)

For batch processing, the same operations can be placed inside a loop and applied to every file in a directory.

🎬 2. Video Optimizer
#

MoviePy can automate common video-editing operations such as trimming, concatenation, playback-speed changes, audio replacement, and video effects.

# pip install moviepy

from moviepy import (
    VideoFileClip,
    AudioFileClip,
    concatenate_videoclips,
)

video = VideoFileClip("vid.mp4")

# Cut segments
clip1 = video.subclipped(0, 10)
clip2 = video.subclipped(20, 40)

# Merge clips
final_video = concatenate_videoclips([clip1, clip2])

# Speed up
final_video = final_video.with_speed_scaled(factor=2)

# Add background audio
audio = AudioFileClip("bg.mp3")
final_video = final_video.with_audio(audio)

# Save
final_video.write_videofile("final.mp4")

MoviePy APIs vary between major releases, so check the installed version’s documentation when adapting older examples.

📄 3. Convert PDF Pages to Images
#

PyMuPDF can render PDF pages into raster images. This is useful for generating thumbnails, previews, or image-based processing pipelines.

# pip install PyMuPDF

import fitz


def pdf_to_images(pdf_file):
    document = fitz.open(pdf_file)

    for page_number, page in enumerate(document, start=1):
        pixmap = page.get_pixmap()
        pixmap.save(f"page{page_number}.png")

    document.close()


pdf_to_images("test.pdf")

The rendering resolution can be controlled with a matrix or DPI-based transformation when higher-quality output is required.

🌐 4. Fetch Data from an API
#

Python can automate REST API requests using libraries such as urllib3 or requests.

# pip install urllib3

import urllib3

http = urllib3.PoolManager()

# GET request
url = "https://api.github.com/users/psf/repos"

response = http.request("GET", url)

print("Status:", response.status)
print(response.data.decode("utf-8"))

# POST request
url = "https://httpbin.org/post"

response = http.request(
    "POST",
    url,
    fields={"hello": "world"},
)

print("Status:", response.status)

For production applications, also consider timeouts, retries, authentication, response validation, and rate limiting.

🔋 5. Battery Level Reminder
#

A combination of psutil and Plyer can monitor the battery and display a desktop notification when the charge level falls below a threshold.

# pip install plyer psutil

import time

import psutil
from plyer import notification

THRESHOLD = 50

while True:
    battery = psutil.sensors_battery()

    if battery is not None and battery.percent < THRESHOLD:
        notification.notify(
            title="Low Battery",
            message="Please connect the charger.",
            timeout=10,
        )

    time.sleep(60)

A production version should also check battery.power_plugged to avoid repeatedly notifying the user after the charger is connected.

✍️ 6. Grammar Correction
#

Grammar correction can be automated with transformer-based text-to-text models. Happy Transformer provides a convenient interface for experimenting with such models.

# pip install happytransformer

from happytransformer import HappyTextToText, TTSettings


model = HappyTextToText(
    "T5",
    "prithivida/grammar_error_correcter_v1",
)

settings = TTSettings(
    do_sample=True,
    top_k=10,
    max_length=100,
)


def grammar_fixer(text):
    result = model.generate_text(text, args=settings)
    print("Corrected:", result.text)


grammar_fixer("This is smple tet we how know this")

For repeated processing, load the model once and reuse it rather than initializing it for every input.

🔤 7. Spelling Correction
#

TextBlob provides a simple interface for basic spelling correction.

# pip install textblob

from textblob import TextBlob, Word


def fix_paragraph(text):
    return str(TextBlob(text).correct())


def fix_word(word):
    return str(Word(word).correct())


print(fix_paragraph("This is sammple tet!!"))
print(fix_word("maangoo"))

TextBlob’s correction is convenient for lightweight tasks, but it should not be treated as a replacement for a context-aware modern language model or professional proofreading workflow.

📥 8. Resumable File Downloader
#

For large files, resumable downloads can help recover from interrupted transfers.

A Python downloader library can automate multipart or resumable transfers, depending on the server and protocol.

# pip install internetdownloadmanager

import internetdownloadmanager as idm


def download_file(url, output):
    downloader = idm.Downloader(
        worker=20,
        part_size=10 * 1024 * 1024,
        resumable=True,
    )
    downloader.download(url, output)


download_file(
    "https://example.com/image.jpg",
    "image.jpg",
)

download_file(
    "https://example.com/video.mp4",
    "video.mp4",
)

Before using a multipart downloader, verify that the server supports the required range requests and that the download source permits automated access.

📰 9. World News Fetcher
#

News APIs make it possible to integrate current articles into scripts, dashboards, monitoring systems, and research workflows.

For example, the World News API can be queried with the requests library.

# pip install requests

import requests

API_KEY = "YOUR_API_KEY"

url = "https://api.worldnewsapi.com/search-news"

params = {
    "text": "hurricane",
    "api-key": API_KEY,
}

response = requests.get(
    url,
    params=params,
    headers={"Accept": "application/json"},
    timeout=10,
)

response.raise_for_status()

data = response.json()

print("News:", data)

Keep API keys outside source code in production. Environment variables or a secrets manager are better choices.

🖥️ 10. Build a GUI App with PySide6
#

PySide6 provides Python bindings for the Qt framework, allowing you to build cross-platform desktop applications.

# pip install PySide6

import sys

from PySide6.QtWidgets import (
    QApplication,
    QLabel,
    QPushButton,
    QWidget,
)


app = QApplication(sys.argv)

window = QWidget()
window.resize(500, 500)
window.setWindowTitle("PySide6 App")

button = QPushButton("Click Me", window)
button.move(200, 200)

label = QLabel("Hello World", window)
label.move(200, 150)

window.show()

sys.exit(app.exec())

From this foundation, you can add layouts, menus, dialogs, signals and slots, background workers, file selectors, and other application components.

🧠 Conclusion
#

These 10 Python automation examples demonstrate how a relatively small amount of code can automate a wide range of repetitive tasks:

  • Image transformation and optimization
  • Video editing
  • PDF rendering
  • REST API integration
  • System monitoring and notifications
  • Grammar correction
  • Spelling correction
  • Resumable file downloads
  • News API integration
  • Cross-platform GUI development

The most useful automation scripts are usually the ones that eliminate repetitive work from your own workflow. Start with a small task, turn it into a reusable script, and gradually add error handling, configuration, logging, and scheduling as the automation becomes more important.

Related