If you download the same report, clean the same folder, and call the same API by hand every morning, you are wasting time. The more a task repeats, the more likely you are to make a mistake. A computer handles repetition better than you do.Python automation steps in exactly here. With a few lines of code you can organize files, pull data from APIs, and run tasks at set times. This article gives developers concrete examples for daily work. Each one follows a copy, run, and adapt logic.Python's standard library already covers most of this. Before installing external packages, take a look at the official standard library docs. Modules like os, pathlib, and subprocess do a lot of work on their own.
File handling with python automation
Organizing folders by hand is tedious. If your downloads folder is a mess, Python can sort it in seconds. File handling is where most python automation work begins. The script below moves files into subfolders based on their extension.
from pathlib import Path
import shutil
source = Path.home() / "Downloads"
rules = {
"images": [".jpg", ".png", ".gif"],
"documents": [".pdf", ".docx", ".txt"],
"archives": [".zip", ".tar", ".gz"],
}
for item in source.iterdir():
if not item.is_file():
continue
for folder, extensions in rules.items():
if item.suffix.lower() in extensions:
target = source / folder
target.mkdir(exist_ok=True)
shutil.move(str(item), str(target / item.name))This example uses pathlib because it reads more clearly for path work. The shutil module handles moving and copying safely. You can reuse the same logic to archive log files or delete old backups.
API calls: fetch data automatically
Most modern services expose a REST API. Instead of calling these APIs by hand, a script can collect data on a schedule. The requests library is the de facto standard for this job.
import requests
def get_exchange_rate(code="USD"):
url = f"https://api.example.com/rates/{code}"
try:
response = requests.get(url, timeout=10)
response.raise_for_status()
return response.json()["rate"]
except requests.RequestException as error:
print(f"Request failed: {error}")
return None
rate = get_exchange_rate("EUR")
if rate:
print(f"Current rate: {rate}")Two points deserve attention. First, set a timeout, because an unresponsive server can block your script forever. Second, catch errors, because the network is not always up. These two habits make your scripts far more reliable.
Scheduled tasks: pick the right tool
To run a script automatically every day, you have two paths. One is your operating system scheduler, the other is a Python library. Which one fits depends on the shape of the job.
MethodBest forLimitation
cron / Task Scheduler | Simple, one-shot daily jobs | Tied to the operating system
schedule library | Long-running, cross-platform jobs | Jobs stop if the program stops
APScheduler | Persistent, complex scheduling needs | Heavier to set up
For a simple daily job on a server, cron is usually the most reliable choice. If your program needs to stay awake, the schedule library is more practical. Here is a small example.
import schedule
import time
def run_backup():
print("Backup running...")
schedule.every().day.at("03:00").do(run_backup)
schedule.every(10).minutes.do(run_backup)
while True:
schedule.run_pending()
time.sleep(60)Web scraping and sysadmin scripts
When there is no API, you may need to pull data straight from a page. BeautifulSoup is a common choice for this. The example below collects every heading from a page.
import requests
from bs4 import BeautifulSoup
response = requests.get("https://example.com", timeout=10)
soup = BeautifulSoup(response.text, "html.parser")
for heading in soup.find_all("h2"):
print(heading.get_text(strip=True))When scraping, take care not to overload the site. Add a delay between requests and respect the site's robots.txt rules. On the system administration side, the subprocess module gets the job done.
- Disk check: call the df command through subprocess and watch free space.
- Service status: read systemctl output and alert if a service goes down.
- Log cleanup: automatically delete log files older than a set age.
When these small scripts come together, they remove most of the work you do by hand. The key is to start and turn every repeating task into a script.
Summary and next step
Python automation is not a complicated subject. Most of the tools you need for file handling, API calls, scheduled tasks, and scraping sit ready in the standard library. Start with a small script, see it work, and grow it step by step.Want to run these automations safely in production? At Kritm Cloud Solutions we build custom Python software and deploy it on cloud and VPS infrastructure. Explore our services or get in touch to talk through your project.
