Tools for working with Fantasy Premier League data
Project description
FPL-data-loader
Python package for loading and transforming data from the Fantasy Premier Leage API.
Usage
For getting raw data in JSON form, use the fpl_data.load module.
For getting enriched data as Pandas DataFrames, use the fpl_data.transform module.
fpl_data.load
This module provides a single class: FplApiDataRaw
This class can be used to download all relevant data from the FPL API, including:
- Elements (Players)
- Element types (Positions)
- Teams
- Events (Game weeks)
- Fixtures
To use the FplApiDataRaw class, first create an instance of the class:
from fpl_data.load import FplApiDataRaw
# make a request to the FPL API
data = FplApiDataRaw()
Then, you can access the data using the following attributes:
elements_json: A list of all players in the current seasonelement_types_json: A list of all positions in the FPL gameteams_json: A list of all teams in the Premier Leagueevents_json: A list of all game weeks in the current seasonfixtures_json: A list of all fixtures in the current season
For example, to get the list of all players in the current season, you would do the following:
players = data.elements_json
The get_element_summary function can be used to get all past gameweek/season info for a given player_id.
To use the get_element_summary function, you need to pass the player_id as an argument:
from fpl_data.load import get_element_summary
summary = get_element_summary(player_id)
The summary object will contain the following information:
history: all gameweek data for the current seasonhistory_past: all summary data for past seasonsfixtures: all upcoming fixtures in current season
For example, to get all past gameweek/season info for the player with ID 1, you would do the following:
summary = get_element_summary(1)
The history attribute of the summary object will contain a list of dictionaries, each of which representing a gameweek. The dictionaries will contain the following keys:
gameweek: The gameweek number.points: The number of points the player scored in the gameweek.minutes: The number of minutes the player played in the gameweek.goals_scored: The number of goals the player scored in the gameweek.assists: The number of assists the player provided in the gameweek.clean_sheets: The number of clean sheets the player kept in the gameweek.bonus: The bonus points the player earned in the gameweek.red_card: A boolean value indicating whether the player was sent off in the gameweek.
The history_past attribute of the summary object will contain a list of dictionaries, each of which representing a summary from a past season.
fpl_data.transform
This module builds on the load module, by performing some transformations including:
- Renaming columns to match those shown in the FPL website
- Correcting data types for some columns
- Calculating additional columns such as:
GI(goal involvements): goals plus assistsPts90: points scored per 90 minutes
The FplApiDataTransformed class can be used to download and transform data from the FPL API, which are then returned as Pandas DataFrames:
players_df: summary of players' season statistics so farpositions_df: all positions in the FPL gameteams_df: summary of teams in the Premier Leaguegameweeks_df: list of all game weeks in the current season
To use the FplApiDataTransformed class, first create an instance of the class:
from fpl_data.transform import FplApiDataTransformed
# load and transform data
data = FplApiDataTransformed()
Then, you can access the data in DataFrame format using the classes attributes.
For example, to get the main players dataframe, you would do the following:
players = data.players_df
Local development
If you would like to contribute to this package, you can set up an environment for local development using the following steps:
1. Clone the repository
https://github.com/James-Leslie/fpl-data
2. Make a virtual environment
cd fpl-data
conda env create -f environment.yml --prefix ./.env
3. Activate your environemt
conda activate ./.env
4. Create an editable install of the package
pip install --editable .
5. Create a pull request
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file FPL-data-loader-0.0.9.tar.gz.
File metadata
- Download URL: FPL-data-loader-0.0.9.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
425b2b6c82efb4a30f97708867bc926ac6cc8cfcc66cea225af2639388ab5423
|
|
| MD5 |
6a33d0ce480df581bb692b9e30dd6ffc
|
|
| BLAKE2b-256 |
bc5def3ece7279b7b5f3a4f1447c8283f47e162236f920dec68a4ca5d37df60c
|
File details
Details for the file FPL_data_loader-0.0.9-py3-none-any.whl.
File metadata
- Download URL: FPL_data_loader-0.0.9-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23768deac995301ee08af554d219efbaab459728b583881b8a08565438114cb2
|
|
| MD5 |
e11a83af8c04fa68f34b278dd43bb218
|
|
| BLAKE2b-256 |
97c9a1925bbb467bc3aedc6cae784ba92675d88d6a672e40c57900ddcf6c2a8e
|