WordPress REST API Python Tutorial for Beginners: What Actually Works and What Wastes Your Time
6/10
8/10
9/10
7/10
“The WordPress REST API with Python is free and works, but expect authentication to eat your first afternoon.”
You want to publish WordPress posts from a Python script. Maybe you are building an automated blog, pulling data from another source, or just tired of copying and pasting content into the WordPress editor. The WordPress REST API lets you do exactly this. I use it to run my own automated blog pipeline, and I will show you what the tutorials leave out.
Most tutorials assume you already understand API authentication. They skip the part where your first 47 requests return 401 errors. This guide covers what actually happens when a non-developer tries to set this up, including the specific point where I wasted 3 hours because I missed one plugin setting.
THIS IS FOR YOU IF:
- You publish more than 10 posts per week: Manual posting at that volume costs you 2-3 hours weekly minimum
- You generate content programmatically: Whether from AI, data sources, or content scrapers, you need automated publishing
SKIP THIS IF:
- You post 1-3 times weekly: The WordPress editor with scheduled posts handles this fine
- You have never used Python before: Learn Python basics first, this is not the tutorial for that
The Free Alternative Test
The WordPress REST API itself is free. The question is whether you need Python specifically, or whether a no-code tool handles your use case.
Zapier and similar automation platforms can connect content sources to WordPress without code. They work well for straightforward workflows: new RSS item triggers new draft post. The limitation hits when you need custom logic. If you want to format content, add custom fields based on conditions, or handle errors gracefully, you need code.
For basic automation like posting from a Google Sheet or Airtable, a no-code platform like Make.com covers roughly 70% of use cases without writing Python. The remaining 30% involves custom formatting, conditional publishing, or handling edge cases that no-code tools cannot express.
How Hard Is This to Actually Set Up
Let me be specific about what you need before starting. You need a WordPress site with admin access. You need Python installed on your computer. You need to install the Application Passwords plugin or use WordPress 5.6+ which has it built in. You need basic familiarity with running Python scripts from your terminal.
The setup took me about 4 hours the first time, including time spent debugging authentication errors. Here is the sequence that worked.
Step 1: Enable Application Passwords
If you are on WordPress 5.6 or newer, Application Passwords is built in. Go to Users, click your profile, scroll down to Application Passwords. Create one. Copy it immediately because you will not see it again.
The part that tripped me up: some security plugins block this feature. If you use Wordfence or iThemes Security, check their settings. I spent an hour wondering why the section was missing before realizing Wordfence had disabled it.
Step 2: Test the API Manually First
Before writing Python code, verify the API works. Open your browser and go to: yoursite.com/wp-json/wp/v2/posts
You should see JSON data showing your posts. If you get a 404, your permalinks might be set to Plain. Change them to Post name in Settings, Permalinks. This detail is not in most tutorials and costs people hours of confusion.
Step 3: The Minimum Python Code
Install the requests library if you have not already. Open your terminal and run: pip install requests
Here is the smallest working script that creates a draft post:
import requests
import base64
# Your credentials
user = 'your_username'
password = 'your_application_password' # Not your login password
url = 'https://yoursite.com/wp-json/wp/v2/posts'
# Create auth header
credentials = f'{user}:{password}'
token = base64.b64encode(credentials.encode())
headers = {
'Authorization': f'Basic {token.decode("utf-8")}'
}
# Post data
post = {
'title': 'Test Post from Python',
'content': 'This is the body of the post.',
'status': 'draft'
}
response = requests.post(url, headers=headers, json=post)
print(response.status_code)
print(response.json())
If this returns a 201 status code, your post was created. If it returns 401, your authentication is wrong. The most common error is using your WordPress login password instead of the Application Password.
Step 4: Handle Common Publishing Needs
The basic script creates plain text posts. Real publishing requires categories, tags, featured images, and custom fields. Each of these has quirks.
For categories and tags, you need the ID numbers, not names. To find them, visit yoursite.com/wp-json/wp/v2/categories and yoursite.com/wp-json/wp/v2/tags. Then add them to your post object like this:
post = {
'title': 'Test Post',
'content': 'Body text here.',
'status': 'draft',
'categories': [3, 7], # Category IDs
'tags': [12, 45] # Tag IDs
}
Featured images require uploading the image first, getting its ID, then attaching it. This adds roughly 30 lines of code and involves handling file uploads via the media endpoint. I will not pretend this is simple. It took me another 2 hours to get featured images working reliably.
Where This Breaks
The REST API fails silently in frustrating ways. If you include invalid HTML in your content, WordPress strips it without telling you. If your server has strict security rules, some requests get blocked without meaningful error messages.
I hit rate limiting on my own site once. Not WordPress rate limiting, but my hosting provider throttling API requests. Shared hosting often has these invisible limits. If you plan to publish more than 20-30 posts per day, you need hosting that can handle it.
Custom fields require the Advanced Custom Fields plugin to expose them via the API, and you need to enable that in ACF settings. This is not automatic. I spent an evening wondering why my custom fields were not appearing in API responses before finding this setting.
The Math
| Cost Component | Monthly Cost | Notes |
|---|---|---|
| WordPress REST API | $0 | Built into WordPress |
| Python | $0 | Free and open source |
| Hosting capable of handling API load | Varies | Shared hosting may throttle; VPS gives consistent performance |
| Initial setup time | 4-6 hours | One-time, assuming basic Python knowledge |
| Posts Per Week | Manual Time | Automated Time | Monthly Hours Saved |
|---|---|---|---|
| 5 | 2.5 hours/week | 5 minutes/week | 9.7 hours |
| 15 | 7.5 hours/week | 15 minutes/week | 29 hours |
| 30 | 15 hours/week | 30 minutes/week | 58 hours |
Break-even calculation: If your time is worth $30/hour and you publish 15 posts weekly, you save about $870 per month in labor. The 4-6 hour setup cost pays for itself in the first week.
Extending This for Real Automation
The basic script is a starting point. Real automation requires scheduling, error handling, and logging. Here is what my production setup includes that the basic script does not.
A retry mechanism for failed requests. Network issues happen. I retry 3 times with exponential backoff before logging a failure. Without this, random network hiccups cause lost posts.
Logging to a file so I can see what published, what failed, and why. When you are publishing dozens of posts daily, you need records. I lost track of my publishing pipeline for a week before implementing proper logging and had no idea which posts had gone out.
Validation before posting. Check that the title is not empty, the content meets minimum length, categories exist. The API does not validate everything. You can accidentally publish empty posts if your script has bugs upstream.
Verdict
The WordPress REST API with Python works well for beginners who have basic Python skills and publish frequently enough to justify the setup time. The authentication step causes the most friction. Once past that, publishing is straightforward. I use this approach for my own automated blog, running it on a VPS for reliable performance.
If you publish fewer than 5 posts weekly, stay with the WordPress editor. If you have never written Python code before, start with a Python fundamentals course first. This tutorial assumes you can install packages and run scripts from the command line. For everyone else, particularly those building automated content systems, this is the foundation you need.