Using Python with WordPress



WordPress is one of the most successful and important pieces of software on the internet. It’s the web’s leading architecture running around 20% of all websites.

WordPress’ strength is as a blogging app and a content management system for semi-technical users, but it is flexible enough to do just about anything.

Being an an open source platform with so many users has made WordPress a standard. There is already a high quality, well tested, regularly updated solution available for whatever you want to do. Usually for free and able to be implemented quickly and easily with no additional code. This is why WordPress is such a compelling option.


Python is one of the most popular languages for programing websites and the most popular language for science, data analytics, fin-tech and web scraping apps.

This is partly due to Python’s fantastic numbers, math and charting libraries. In the case of web scraping it’s also due to Python’s efficiency and specialized libraries and frameworks such as Beautiful Soup and Scrapy.

Never the twain shall meet…unless!

WordPress and it’s plugins are coded in PHP. WordPress and Python have nothing to do with each other. You can’t use them together so choose 1. If you want to blog or do content management use WordPress. If you want to do data analytics, fin-tech or web scraping use Python.

But what if you want both of those in the 1 app? For example what if you want to do Python data analyses on the back end then display the results thorough WordPress on the front end? Perhaps embed the results as graphs on blog posts made by non-technical users?

Well there is a bridge that both these technologies work perfectly with which can act as a link to unify them into a single app. WordPress sites have a MySQL databases, Python loves MySQL databases. That’s it! That is how you combine the best of both technologies.

Whatever you want to do with Python put the results of it into WordPresses MySQL database. Then output those results through a custom WordPress plugin. The plugin will make MySQL queries to the database and display the results in whatever format you like on the front end.

You should use the WordPress site’s own database but you could use any MySQL database including one that is not directly connected to the WordPress site. This can all be done on 1 server/container or the Python scripts and the WordPress install can run on separated specialized hosting environments.

A working example

The above architecture is how we make crypto’s only odds comparisons. Python scripts gather the odds from sportsbooks, process the data and put the data we want into this sites MySQL database. Then a custom WordPress plugin makes requests to that database and outputs the results onto tables for easy comparison.

We simply enter a short-code onto a page, with parameters such as

[odds_compariosn “competition= NFL"]

to tell the odds_compariosn plugin to display NFL events. Or the results can be output through custom posts.


Python, MySQL and WordPress are all reliable, secure, performant, best in class technologies and they combine very well together in the architecture I have described.

The challenges are due to the fact that Python and WordPress sit far apart on the web development spectrum and are normally used for different types of apps. Because of this there are very few developers who have a strong command of both and very few managed hosting platforms that support both.


The best fit you are likely to find is a great python developer who is kind of okay at WordPress or a great WordPress developer who is kind of okay at Python.

This is not a problem for decent sized development teams who can simply hire 1 of each. If you are a very small team or a 1 person operation you can hire the best fit available and hope they can up their game in whichever of the technologies they are weaker at.

Alternatively you can hire both a Pythonista and a WordPress dev part time and hope they work well together.


In order to have the fastest and most efficient communication to and from the database you want to have it all running on the same machine. To do that you might have to forgo serverless architecture or managed hosting and host everything on a self-managed VPS.

That means someone on the team also has to be a system admin making the chance of finding 1 developer who can do it all even less likely.

Alternatively you can increase the complexity of the app by hosting the python scripts and the WordPress install on separate specialized environments.


Despite these challenges the rewards of using the best possible data gathering and processing language with the best possible content creation platform in the same app make this a compelling architecture for many applications.


  1. diya

    can u provide me a code to link wordpress with python

  2. Nina

    Is it possible to hook into something like `save_post` (wp function) in order to then fire the Python script located in the document root?

    I’m currently trying to have analyses made through python after a post for a specific CPT has been created, then send data back to the posts table under a different CPT. Triggering the Python script upon action is where I’m lost.

    • BitEdge

      Yes you can use a WP web-hooks to trigger python operations. Sorry I don’t have details of the optimal way to do that.

Leave a comment

Your email address will not be published.


Edge alerts

We have set up alerts when there are opportuntites to gamble crypto with the odds in your favor. We guarantee 100% privacy, your information will not be shared.