01 — Why

WordPress stays on PHP. Python runs around it.

Python doesn’t replace PHP and nobody rewrites the site. It takes the work that lives outside WordPress: scripts, data, tests and AI.

>_

Scripts

Reports, files, checks and schedules, where bash gets awkward and WP-CLI can’t reach.

{ }

Data

CSV, XML, HTML from another CMS: clean it before it ever reaches WordPress.

✓

Tests

Playwright and pytest scenarios that check checkout after every update.

AI

AI

Model calls, structured output, embeddings and RAG prototypes over your content.

02 — Popularity

What GitHub’s Octoverse says.

Numbers from GitHub’s yearly Octoverse reports. Pick a year.

#1Python overtook JavaScript as the most used language on GitHub.
+92%spike in usage across Jupyter Notebooks.
137,000public generative AI projects, +98% year over year.
Aug 2025TypeScript overtook both Python and JavaScript. Python remains dominant for AI and data science.
2.4Mrepositories used Notebooks, +75% year over year.
1.1M+public repositories use an LLM SDK, +178% year over year.

Sources: Octoverse 2024 · Octoverse 2025

03 — Easy to start

Same task, two languages.

Read a CSV and create draft posts through the WordPress REST API with an Application Password. Switch and compare.

posts.csv → /wp-json/wp/v2/posts
import csv, requests

with open("posts.csv", newline="") as f:
    for post in csv.DictReader(f):
        requests.post(
            "https://example.com/wp-json/wp/v2/posts",
            auth=("user", "app-password"),
            json={"title": post["title"], "status": "draft"},
        ).raise_for_status()
<?php
$rows = array_map( 'str_getcsv', file( 'posts.csv', FILE_IGNORE_NEW_LINES ) );
$head = array_shift( $rows );

foreach ( $rows as $row ) {
    $post = array_combine( $head, $row );
    $ch   = curl_init( 'https://example.com/wp-json/wp/v2/posts' );
    curl_setopt_array( $ch, array(
        CURLOPT_POST           => true,
        CURLOPT_USERPWD        => 'user:app-password',
        CURLOPT_POSTFIELDS     => array( 'title' => $post['title'], 'status' => 'draft' ),
        CURLOPT_RETURNTRANSFER => true,
    ) );
    curl_exec( $ch );
    curl_close( $ch );
}

04 — Works with

Everything around a WordPress site.

REST

WordPress REST API

requests + Application Passwords: create, update and audit content from outside.

CLI

WP-CLI

Call wp from a script and parse --format=json output.

E2E

Playwright + pytest

Browser scenarios that run in CI after every plugin or core update.

AI

AI SDKs

Official SDKs for the major model providers, embeddings and vector search.

CSV

Data

csv and json in the standard library, more when you need it.

05 — How we use it

The 4wp.dev content pipeline runs on Python.

Three scripts sit next to the content and feed 4WP Planner. WordPress itself stays on PHP.

gaps.pyevery meta.json × every enabled platform → a gaps report
plan.pygaps + playbook + what’s already scheduled → the plan of the day
agent.pydrafts platform texts with the Claude API; without a key it only reports
4WP Plannera person approves before anything is posted

06 — Limits

Where Python is the wrong tool.

  • Inside WordPress. Hooks, blocks, templates and plugins are PHP and JavaScript. Python doesn’t run there.
  • On the hosting. Many WordPress hosts run PHP only. Python scripts usually run on your machine, in CI or on a separate server.
  • One-liners. If WP-CLI already does it in one command, a script is extra code to maintain.
  • Code you can’t read. AI writes the syntax fast. If you can’t check what it does, don’t run it against production.

07 — FAQ

Questions WordPress developers ask about Python.

Do I need Python if I already know PHP?

Not for the site itself. You need it for the work around the site: automation, data migrations, end-to-end tests and AI integrations, and for job posts that list it.

Python script or WP-CLI command?

WP-CLI when the job lives inside one WordPress install. Python when it spans several sites, external APIs, files or data that isn’t in WordPress yet.

How does a Python script talk to WordPress?

Through the REST API with an Application Password, or by calling WP-CLI and reading its JSON output.

Can AI just write the Python for me?

It can write the syntax. You still set the task, read the code and check the result before it touches a live site.

Python for WordPress Developers

7 sections: mindset, scripts, REST API, migrations, tests, AI, interview prep.

Open the course →

“Python” and the Python logos are trademarks or registered trademarks of the Python Software Foundation, used here to refer to the language. 4wp.dev is an independent educational project, not affiliated with the PSF. Primary source: python.org.