While WordPress runs on PHP, you can still use Python to extend its functionality via the WordPress REST API. This approach lets you build external Python services that interact with your WordPress site – for example, a Django microservice that fetches posts, adds custom metadata, or triggers actions based on webhooks.
To start, enable the REST API in WordPress (it’s on by default from version 4.7). Then from Python, use the requests library to GET or POST to endpoints like /wp-json/wp/v2/posts. You can authenticate using Application Passwords or OAuth. For advanced automation, write a Python script that monitors a folder for new images, uploads them to WordPress as media, and creates a gallery post.
If you really want to run Python inside WordPress, consider using a plugin like “WP Python Shell” (experimental) or execute Python scripts via WP CLI. However, the cleanest method is to build a separate Python app that communicates with WordPress via its API. This gives you the best of both worlds: WordPress’s easy content editing and Python’s powerful data processing capabilities.