Skip to content →

Here’s how to build a Python app and get worse at Fantasy Premier League

The key to succeeding at Fantasy Premier League is information. So, here’s how to build a Python web app which will gather every data point that you could possibly need and then help you to get worse at the game i.e. just because you have good information does not mean that you will make good decisions.

What is Fantasy Premier League?

In the game you are presented with a budget of €100 million and select a real-world squad of fifteen players (two goalkeepers, five defenders, five midfielders and three forwards) – eleven of those players will be awarded points based on their performance each week; then, over the course of the season, you accumulate points on a gameweek-by-gameweek basis.

Last season 11.4 million people from around the world played Fantasy Premier League. In theory, the idea is to win the competition outright, but the heart of the game is really found among the mini leagues where you enjoy an opportunity to pit your wits against your friends and/or beloved work colleagues – matters escalate from there.

When Darwin Núñez spurns a goal-scoring opportunity for Liverpool and a forty-something reacts with a meltdown which would put a small child to shame you would have to wonder whether Fantasy Premier League represents a force for good.

But check out Jane McGonigal’s book Reality Is Broken: Why Games Make Us Better and How They Can Change the World. Here, the American game theorist insists that the desire to play alternate reality games makes perfect sense.

Such games, apparently, offer us a structured environment in which success and failure is very clearly defined. In contrast, the real world is confusing, uninspiring, dull and, as Jane McGonigal argues, broken – in the real world we rarely enjoy an opportunity to be the hero.

“We are starving, and our games are feeding us,” writes McGonigal before asking the reader to consider the “genuine human needs” which games are designed to satisfy.

API (Application Programming Interface)

Anyway, back to the project.

Those nice people at Fantasy Premier League HQ host a static API via which you can access a mountain of data from the game (the actual data which drives the game). This API consists of a number of endpoints; an endpoint is basically a URL which responds with some data when you send it a request. In order to access Fantasy Premier League player data you just send a request to and go from there.

Connecting to the API really is as simple as this piece of Python code; the output can be stored in JSON format and off you go.

Paul Corcoran (@Footballdotpy) published an excellent article in April illustrating how Python can be used to access this API, retrieve the data and to then create a web app which will help you to process the information and, hopefully, make more-informed decisions.

The key to the project is Streamlit – this is a Python framework which allows you to create a web app. Essentially, Streamlit will help you to transform your work into a website.

So, following the example set we elect to adapt Paul’s work to suit our own needs.

The GitHub repository for this project is available here while the finished web app is accessible here – one Python file is used to access and transform the data while another publishes the data on a simple web app.

Please note: if you wish to use the web app to inform your Fantasy Premier League strategy this season the data, which currently populates the app, is from the 2022-23 season; the app will be populated to reflect the 2023-24 season once the league games get underway on August 11. Then, after each gameweek, the app will be updated.

As it stands, the app looks something like the screenshot below – you can filter the data by position; a click on the header of each column will sort the entire table for you based on the specific variable and you can also deselect columns if you desire to do so.

Return on investment

Data like this is pretty valuable (if you have the capacity and inclination to select on optimal team based on the resource), but a high percentage of Fantasy Premier League players do not consider their options based on the potential return on investment (ROI).

How is the ROI calculated? Return on investment = points divided by player cost.

Typically, a Fantasy Premier League player select individuals from their favourite team, adds in five or six from the strongest clubs in the division and then fills out their squad with the cheapest options possible.

The idea is to select players who will generate the optimal number of points for your team, but that selection can often be biased since it is based on a personal desire to see a player perform as opposed to the actual likelihood that the player will perform.

Data can help us to reach beyond such bias and improve our decision-making.

As the season progresses the competing selections also tend to become similar, in that each team features the leading point-scoring players. Therefore, the game is won at the edges, by those who can identify the players who will generate the highest return on investment and out-perform their cost.

Helpfully, we have built an ROI metric into our dataset.

This scatterplot tracks the return on investment for each of the top 200 points scorers during the 2022-23 season against their price for the forthcoming season – no prize for guessing who the blue dot is on the far right of the plot.

It is reasonably easy to see here that the highest-scoring players do not represent the best value in terms of ROI.

Take a look at the top left-hand corner of the plot, did you expect to see so many goalkeepers feature in that area? Might this pattern alter how you select your squad of players?

Ideally, we should wish to select players from the top left corner of the plot (cheap players who earn a reasonable number of points), but we also need to marry those selections to the stars who are likely to generate lots of points (even if they are expensive). The challenge is to optimize your resources and high ROI players won’t score enough on their own.

Real-world problem

There is a danger, however, that access to all of this data could actually transform you into an even worse Fantasy Premier League player.

The volume of data available is mind-numbing; it undulates towards you in wave after wave of monotonous brilliance.

Indeed, the game echoes a real-world problem: you can have access to all the data in the world, but you still need to interpret it and make good decisions based on what you have discovered. Just because you have good data does not mean that you have good insight.

Data should not be confused with knowledge; there is a big difference between statistics and insight. The skill is not in accumulating information, but in making sense of it and to then act based on that insight. Data is only useful if you can do something with it.

Feedback welcome

Feel free to contact Brian McDonnell by email on Brian, of course, can also be contacted via @sixtwofourtwo, on LinkedIn and or, alternatively, on Instagram.

Published in Uncategorized