17 Essential Python Scripts for Automating Everyday Tasks
This article presents 17 practical Python scripts covering file management, web scraping, email handling, Excel processing, database interaction, system tasks, image editing, and more, each with code examples and explanations, enabling developers and analysts to automate repetitive workflows and boost productivity across diverse domains.
Python’s simplicity and extensive libraries make it ideal for automating a wide range of routine tasks. This guide introduces 17 ready‑to‑use scripts, each accompanied by clear explanations and complete code, allowing developers, data analysts, and IT professionals to streamline their workflows.
1. File Management
Scripts for sorting files by extension, removing empty folders, and batch renaming simplify directory organization.
# Python script to sort files in a directory by their extension
import os
from shutil import move
def sort_files(directory_path):
for filename in os.listdir(directory_path):
if os.path.isfile(os.path.join(directory_path, filename)):
ext = filename.split('.')[-1]
dest = os.path.join(directory_path, ext)
if not os.path.exists(dest):
os.makedirs(dest)
move(os.path.join(directory_path, filename), os.path.join(dest, filename))2. Web Scraping
Using requests and BeautifulSoup , the scripts extract data from web pages or download images in bulk.
# Python script for web scraping to extract data from a website
import requests
from bs4 import BeautifulSoup
def scrape_data(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# Add extraction logic here3. Email Automation
Scripts send personalized emails, attach files, or schedule reminder messages via Gmail’s SMTP server.
# Python script to send personalized emails to a list of recipients
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_personalized_email(sender, password, recipients, subject, body):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(sender, password)
for r in recipients:
msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = r
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
server.sendmail(sender, r, msg.as_string())
server.quit()4. Excel Automation
With pandas , the scripts read, write, and merge Excel sheets, enabling fast data manipulation.
# Python script to read and write data to an Excel spreadsheet
import pandas as pd
def read_excel(path):
return pd.read_excel(path)
def write_excel(df, path):
df.to_excel(path, index=False)5. Database Interaction
SQLite examples demonstrate connecting to a database, executing queries, and backing up data.
# Python script to connect to a database and execute queries
import sqlite3
def connect(db_path):
return sqlite3.connect(db_path)
def execute(conn, query):
cur = conn.cursor()
cur.execute(query)
return cur.fetchall()6. System Tasks
Using psutil and crontab , the scripts list running processes, kill specific ones, and schedule recurring jobs.
7. Image Automation
With Pillow ( PIL ), scripts resize, crop, add watermarks, and generate thumbnails.
8. Network Automation
Scripts check website status, perform FTP transfers, and configure network devices via netmiko .
9. Data Cleaning & Transformation
Using pandas , examples remove duplicates, normalize data, and handle missing values.
10. PDF Operations
PyPDF2 scripts extract text, merge PDFs, and add password protection.
11. GUI Automation
With pyautogui and tkinter , the guide shows how to automate mouse/keyboard actions and build simple graphical interfaces.
12. Testing
Unit testing via unittest and web testing with Selenium provide foundations for reliable automation.
13. Cloud Services
Examples for AWS (Boto3) and generic cloud storage illustrate uploading files and managing resources.
14. Financial Automation
Scripts fetch stock prices, currency rates, and track budgets using CSV/Excel inputs.
15. Natural Language Processing
NLTK‑based sentiment analysis and placeholders for summarization and translation demonstrate basic NLP capabilities.
Overall, the collection equips readers with reusable Python building blocks to replace manual, repetitive work with reliable, programmable solutions.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.