Automate Your Workflow with These 5 Python Scripts

*Photo by Mathews Jumba on Pexels*
Python remains the best language for automation in 2027. These five scripts solve real problems that developers face daily — file organization, data extraction, API testing, report generation, and system monitoring.
## 1. File Organizer
Stop your Downloads folder from becoming a mess. This script sorts files into folders by type.
“`python
import os, shutil
from pathlib import Path
EXTENSIONS = {
‘Images’: [‘.jpg’,’.jpeg’,’.png’,’.gif’,’.webp’],
‘Documents’: [‘.pdf’,’.docx’,’.txt’,’.md’],
‘Code’: [‘.py’,’.js’,’.ts’,’.html’,’.css’],
‘Archives’: [‘.zip’,’.tar’,’.gz’,’.rar’],
}
def organize(path):
for file in Path(path).iterdir():
if file.is_file():
for folder, exts in EXTENSIONS.items():
if file.suffix.lower() in exts:
os.makedirs(f'{path}/{folder}’, exist_ok=True)
shutil.move(str(file), f'{path}/{folder}/{file.name}’)
print(f’Moved: {file.name} → {folder}’)
break
organize(‘~/Downloads’)
“`
## 2. CSV to API Converter
Turn any CSV file into a REST API endpoint in seconds.
“`python
import csv, json
from flask import Flask, jsonify
app = Flask(__name__)
def csv_to_json(filepath):
with open(filepath) as f:
return [row for row in csv.DictReader(f)]
DATA = csv_to_json(‘data.csv’)
@app.route(‘/api/data’)
def get_data():
return jsonify(DATA)
if __name__ == ‘__main__’:
app.run(port=5000)
“`
## 3. Automated Log Parser
Extract errors, warnings, and patterns from log files and generate a summary report.
“`python
import re
from collections import Counter
def parse_logs(filepath):
errors, warnings = [], []
with open(filepath) as f:
for line in f:
if ‘ERROR’ in line: errors.append(line.strip())
elif ‘WARN’ in line: warnings.append(line.strip())
print(f’Errors: {len(errors)}’)
print(f’Warnings: {len(warnings)}’)
# Find most common error type
error_types = Counter(
re.search(r’ERROR\s+(\w+)’, e).group(1)
for e in errors if re.search(r’ERROR\s+(\w+)’, e)
)
print(f’Top error: {error_types.most_common(1)[0][0]}’)
parse_logs(‘app.log’)
“`
## 4. Data Export Script
Export database query results to Excel or CSV with formatting.
“`python
import pandas as pd
from sqlalchemy import create_engine
engine = create_engine(‘postgresql://user:pass@localhost/db’)
query = ‘SELECT * FROM sales WHERE date >= NOW() – INTERVAL 30 DAY’
df = pd.read_sql(query, engine)
with pd.ExcelWriter(‘report.xlsx’, engine=’xlsxwriter’) as writer:
df.to_excel(writer, sheet_name=’Sales’, index=False)
worksheet = writer.sheets[‘Sales’]
worksheet.set_column(‘A:E’, 20) # Set column widths
print(f’Exported {len(df)} rows to report.xlsx’)
“`
## 5. Server Health Dashboard
A lightweight Flask dashboard that displays real-time server metrics.
“`python
import psutil
from flask import Flask, jsonify
app = Flask(__name__)
@app.route(‘/health’)
def health():
return jsonify({
‘cpu’: psutil.cpu_percent(interval=1),
‘memory’: psutil.virtual_memory().percent,
‘disk’: psutil.disk_usage(‘/’).percent,
‘uptime’: psutil.boot_time(),
})
if __name__ == ‘__main__’:
app.run(host=’0.0.0.0′, port=8080)
“`

*Photo by Nemuel Sereti on Pexels*
## How to Run These Scripts
“`bash
# Install dependencies
pip3 install flask pandas psutil sqlalchemy xlsxwriter
# Run any script
python3 script_name.py
# For web-based scripts, open http://localhost:8080
“`
All scripts are tested on Python 3.12+ and Ubuntu 24.04. Download the full collection with error handling and logging included from freefile.store.
*For more developer scripts, tools, and resources, visit freefile.store.*