Development
Python + AI: Build Your First Automation Script in 30 Minutes
Learn how to combine Python with AI APIs to automate repetitive tasks. No advanced programming experience needed — just follow this beginner-friendly guide.
March 19, 20267 min read4 views
Python + AI: Build Your First Automation Script in 30 Minutes
Automation used to require years of programming experience. Today, with Python and AI APIs, you can build powerful automations in under an hour — even as a beginner.
What We Will Build
A script that:
- Reads a list of blog post titles from a CSV file
- Uses Claude AI to generate SEO meta descriptions for each
- Saves the results back to a new CSV file
This exact workflow can save hours of manual work every week.
Prerequisites
- Python 3.8+ installed
- Basic Python knowledge (variables, loops)
- An Anthropic API key (free tier available)
Setup
pip install anthropic pandas python-dotenv
Create a .env file:
ANTHROPIC_API_KEY=your_key_here
The Script
import anthropic
import pandas as pd
from dotenv import load_dotenv
import os
import time
load_dotenv()
# Initialize the AI client
client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
def generate_meta_description(title: str) -> str:
"""Generate an SEO meta description for a blog post title."""
prompt = f"""Write a compelling SEO meta description for a blog post titled:
"{title}"
Requirements:
- Exactly 150-160 characters
- Include the main keyword naturally
- End with a subtle call-to-action
- Do not use quotes or special characters
Return only the meta description, nothing else."""
message = client.messages.create(
model="claude-3-haiku-20240307",
max_tokens=200,
messages=[{"role": "user", "content": prompt}]
)
return message.content[0].text.strip()
def process_blog_titles(input_file: str, output_file: str):
"""Process a CSV of blog titles and add meta descriptions."""
# Read the input CSV
df = pd.read_csv(input_file)
if 'title' not in df.columns:
raise ValueError("CSV must have a 'title' column")
meta_descriptions = []
total = len(df)
for i, title in enumerate(df['title'], 1):
print(f"Processing {i}/{total}: {title[:50]}...")
description = generate_meta_description(title)
meta_descriptions.append(description)
# Rate limiting - be nice to the API
time.sleep(0.5)
df['meta_description'] = meta_descriptions
df.to_csv(output_file, index=False)
print(f"Done! Results saved to {output_file}")
if __name__ == "__main__":
process_blog_titles("blog_titles.csv", "blog_with_meta.csv")
Sample Input CSV
Create blog_titles.csv:
title
How to Learn Python in 2025
Best Coffee Shops in New York
10 Tips for Remote Work Productivity
Running the Script
python meta_generator.py
Output in seconds:
Processing 1/3: How to Learn Python in 2025...
Processing 2/3: Best Coffee Shops in New York...
Processing 3/3: 10 Tips for Remote Work Productivi...
Done! Results saved to blog_with_meta.csv
Taking It Further
Now that you have the pattern, you can adapt this for:
- Email subject line generation — feed customer segment data
- Product description writing — process your entire catalog
- Support ticket routing — classify by topic automatically
- Social media captions — generate platform-specific variations
- Invoice processing — extract and categorize data from PDFs
The Power of This Pattern
The core pattern is always:
- Read data from a source (CSV, database, API)
- Loop through items
- Send each item to AI with a specific prompt
- Collect and save results
Once you understand this, you can automate almost anything.
PythonAutomationAI APIBeginnersCoding