### Fetch Entry Gameweek Picks - Python FPL API Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Gets the squad selection (picks) and captain information for a specific team across multiple gameweeks. Uses the `get_entry_gws_data` function, requiring team ID, number of gameweeks, and start gameweek. Output includes points and captain details per gameweek. ```python from getters import get_entry_gws_data # Fetch gameweek picks for team 4582 from GW1 to GW10 team_id = 4582 num_gws = 10 start_gw = 1 gw_data = get_entry_gws_data(team_id, num_gws, start_gw) # Examine picks for each gameweek for gw in gw_data: event = gw['entry_history']['event'] total_points = gw['entry_history']['points'] picks = gw['picks'] print(f"\nGW{event}: {total_points} points") print(f"Captain: Player ID {[p for p in picks if p['is_captain']][0]['element']}") print(f"Players: {len(picks)}") ``` -------------------------------- ### Fetch Entry Gameweek Picks Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Gets the squad selection and transfers for a specific team across multiple gameweeks. This provides insight into a manager's strategic decisions. ```APIDOC ## Fetch Entry Gameweek Picks ### Description Gets the squad selection and transfers for a specific team across multiple gameweeks. ### Method GET ### Endpoint /api/entry/{entry_id}/event/{event_id}/picks/ ### Parameters #### Path Parameters - **entry_id** (integer) - Required - The unique identifier for the FPL team/entry. - **event_id** (integer) - Required - The gameweek ID for which to fetch picks. ### Request Example ```python from getters import get_entry_gws_data # Fetch gameweek picks for team 4582 from GW1 to GW10 team_id = 4582 num_gws = 10 start_gw = 1 gw_data = get_entry_gws_data(team_id, num_gws, start_gw) # Examine picks for each gameweek for gw in gw_data: event = gw['entry_history']['event'] total_points = gw['entry_history']['points'] picks = gw['picks'] print(f"\nGW{event}: {total_points} points") print(f"Captain: Player ID {[p for p in picks if p['is_captain']][0]['element']}") print(f"Players: {len(picks)}") ``` ### Response #### Success Response (200) - **picks** (array) - An array of objects representing the selected players for the gameweek. - **entry_history** (object) - Historical performance data for the entry in that gameweek. #### Response Example ```json [ { "picks": [ { "element": 10, "is_captain": true, "is_vice_captain": false } ], "entry_history": { "event": 1, "points": 60, "overall_rank": 5000 } } ] ``` ``` -------------------------------- ### Fetch Fixtures Data Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Gets fixture schedule and results for all Premier League matches. This endpoint provides information on upcoming and past fixtures. ```APIDOC ## Fetch Fixtures Data ### Description Gets fixture schedule and results for all Premier League matches. ### Method GET ### Endpoint /api/fixtures/ ### Parameters This endpoint does not require any specific parameters. ### Request Example ```python from getters import get_fixtures_data fixtures = get_fixtures_data() for fixture in fixtures[:5]: # First 5 fixtures print(f"GW{fixture['event']}: Team {fixture['team_h']} vs Team {fixture['team_a']}") if fixture['finished']: print(f" Score: {fixture['team_h_score']}-{fixture['team_a_score']}") else: print(f" Kickoff: {fixture['kickoff_time']}") ``` ### Response #### Success Response (200) - **fixtures** (array) - An array of objects, each representing a fixture. #### Response Example ```json [ { "event": 1, "team_h": 1, "team_a": 2, "team_h_score": 2, "team_a_score": 1, "finished": true, "kickoff_time": "2023-08-11T19:00:00Z" } ] ``` ``` -------------------------------- ### Scrape Complete Team Data - Python Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Downloads all historical data for a specific FPL team/manager for a given season, starting from a specified gameweek. It creates a dedicated output folder containing various CSV files like gws.csv, chips.csv, and more. ```python from teams_scraper import store_data import os # Scrape data for team 4582, season 24_25, starting from GW1 team_id = 4582 season = '24_25' start_gw = 1 output_folder = f'team_{team_id}_data{season}' if not os.path.exists(output_folder): os.makedirs(output_folder) store_data(team_id, output_folder, start_gw) # Creates: # team_4582_data24_25/gws.csv - GW-by-GW performance # team_4582_data24_25/chips.csv - Chips used # team_4582_data24_25/history.csv - Past seasons # team_4582_data24_25/classic_leagues.csv # team_4582_data24_25/h2h_leagues.csv # team_4582_data24_25/transfers.csv # team_4582_data24_25/picks_*.csv - Team selection for each GW ``` -------------------------------- ### Fetch Fixtures Data - Python FPL API Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Gets the fixture schedule and results for all Premier League matches. Uses the `get_fixtures_data` function. The output includes gameweek, participating teams, and scores if the match has finished, or kickoff time if not. ```python from getters import get_fixtures_data fixtures = get_fixtures_data() for fixture in fixtures[:5]: # First 5 fixtures print(f"GW{fixture['event']}: Team {fixture['team_h']} vs Team {fixture['team_a']}") if fixture['finished']: print(f" Score: {fixture['team_h_score']}-{fixture['team_a_score']}") else: print(f" Kickoff: {fixture['kickoff_time']}") ``` -------------------------------- ### Access FPL Data with Pandas in Python Source: https://github.com/vaastav/fantasy-premier-league/blob/master/README.md This snippet demonstrates how to access FPL data directly from the repository using Python and the pandas library. It reads a specified CSV file (e.g., merged_gw.csv) into a pandas DataFrame. Ensure you have pandas installed (`pip install pandas`). ```python import pandas as pd # URL of the CSV file (example) url = "https://raw.githubusercontent.com/vaastav/Fantasy-Premier-League/master/data/2023-24/gws/merged_gw.csv" # Read the CSV file into a pandas DataFrame df = pd.read_csv(url) ``` -------------------------------- ### Fetch Individual Player Detailed Data Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Gets gameweek-by-gameweek history and fixture data for a specific player. This is useful for in-depth analysis of a single player's performance and upcoming matches. ```APIDOC ## Fetch Individual Player Detailed Data ### Description Gets gameweek-by-gameweek history and fixture data for a specific player. ### Method GET ### Endpoint /api/element-summary/{player_id}/ ### Parameters #### Path Parameters - **player_id** (integer) - Required - The unique identifier for the player. ### Request Example ```python from getters import get_individual_player_data # Fetch data for player ID 389 (e.g., Erling Haaland) player_data = get_individual_player_data(389) # Access player gameweek history gw_history = player_data['history'] for gw in gw_history: print(f"GW{gw['round']}: {gw['total_points']} points, {gw['goals_scored']} goals") # Access player's past season history past_seasons = player_data['history_past'] for season in past_seasons: print(f"{season['season_name']}: {season['total_points']} points") # Access upcoming fixtures fixtures = player_data['fixtures'] ``` ### Response #### Success Response (200) - **history** (array) - An array of objects, each representing a gameweek's performance for the player. - **history_past** (array) - An array of objects, each representing the player's performance in past seasons. - **fixtures** (array) - An array of objects, representing upcoming fixtures for the player's team. #### Response Example ```json { "history": [ { "round": 1, "total_points": 10, "goals_scored": 2 } ], "history_past": [ { "season_name": "2022/23", "total_points": 300 } ], "fixtures": [ { "opponent_team": 5, "team_h_score": null, "team_a_score": null } ] } ``` ``` -------------------------------- ### Get Recent Gameweek ID - Python Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Retrieves the ID of the most recently completed gameweek. It depends on the 'gameweek' module and returns an integer representing the gameweek ID. ```python from gameweek import get_recent_gameweek_id # Get the most recent completed gameweek recent_gw = get_recent_gameweek_id() print(f"Most recent gameweek: {recent_gw}") ``` -------------------------------- ### Fetch Individual Player History - Python FPL API Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Gets gameweek-by-gameweek history, past season performance, and upcoming fixture data for a specific player ID. Uses the `get_individual_player_data` function from the `getters` module. Provides insights into player's performance and schedule. ```python from getters import get_individual_player_data # Fetch data for player ID 389 (e.g., Erling Haaland) player_data = get_individual_player_data(389) # Access player gameweek history gw_history = player_data['history'] for gw in gw_history: print(f"GW{gw['round']}: {gw['total_points']} points, {gw['goals_scored']} goals") # Access player's past season history past_seasons = player_data['history_past'] for season in past_seasons: print(f"{season['season_name']}: {season['total_points']} points") # Access upcoming fixtures fixtures = player_data['fixtures'] ``` -------------------------------- ### Download Team Data using teams_scraper.py Source: https://github.com/vaastav/fantasy-premier-league/blob/master/README.md This command-line script, `teams_scraper.py`, allows users to download specific data for their FPL team. It requires a team ID as an argument and generates a folder containing individual data files for the team. ```bash python teams_scraper.py #Eg: python teams_scraper.py 4582 ``` -------------------------------- ### Collect Gameweek Data - Python Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Aggregates player performance data for a specific gameweek, including team and opponent information. It requires the gameweek number, player directory, and output directory, producing a 'gwX.csv' file. ```python from collector import collect_gw # Collect data for gameweek 10 gw_number = 10 players_dir = 'data/2024-25/players' output_dir = 'data/2024-25/gws' root_dir = 'data/2024-25' collect_gw(gw_number, players_dir, output_dir, root_dir) # Creates: data/2024-25/gws/gw10.csv # The output includes: name, position, team, xP (expected points), # plus all performance stats (minutes, goals, assists, bonus, etc.) ``` -------------------------------- ### Fetch All Player Data Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Retrieves the complete FPL bootstrap-static dataset, which includes all players, teams, gameweeks, and season information. This data is essential for a general overview of the FPL landscape. ```APIDOC ## Fetch All Player Data ### Description Retrieves the complete FPL bootstrap-static dataset containing all players, teams, gameweeks, and season information. ### Method GET ### Endpoint /api/bootstrap-static/ ### Parameters This endpoint does not require any specific parameters. ### Request Example ```python from getters import get_data import json # Fetch complete FPL data data = get_data() # Save to file with open('raw.json', 'w') as outf: json.dump(data, outf) # Access different data sections players = data['elements'] # All player data teams = data['teams'] # All team data gameweeks = data['events'] # All gameweek data # Example: Print first player's name and total points print(f"{players[0]['first_name']} {players[0]['second_name']}: {players[0]['total_points']} points") ``` ### Response #### Success Response (200) - **data** (object) - The complete FPL bootstrap-static dataset, containing keys like 'elements', 'teams', 'events', etc. #### Response Example ```json { "elements": [ { "id": 1, "first_name": "Mesut", "second_name": "Özil", "total_points": 130, "team_id": 1 } ], "teams": [ { "id": 1, "name": "Arsenal" } ], "events": [ { "id": 1, "name": "Gameweek 1", "deadline_time": "2023-08-11T18:30:00Z" } ] } ``` ``` -------------------------------- ### Create Player ID Mapping - Python Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Generates a CSV file that maps player names to their FPL IDs and can also load this mapping into a Python dictionary. It requires the raw players CSV file and an output directory. ```python from cleaners import id_players, get_player_ids # Create player ID list players_file = 'data/2024-25/players_raw.csv' output_dir = 'data/2024-25/' id_players(players_file, output_dir) # Creates: data/2024-25/player_idlist.csv # Load player IDs into a dictionary player_ids = get_player_ids('data/2024-25/') # Returns: {4: 'Bukayo_Saka', 17: 'Gabriel_Martinelli', ...} print(f"Player ID 4: {player_ids[4]}") ``` -------------------------------- ### Fetch Team/Entry Data Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Retrieves historical performance data for a specific FPL team/manager, including current season performance and past season summaries. ```APIDOC ## Fetch Team/Entry Data ### Description Retrieves historical performance data for a specific FPL team/manager. ### Method GET ### Endpoint /api/entry/{entry_id}/ ### Parameters #### Path Parameters - **entry_id** (integer) - Required - The unique identifier for the FPL team/entry. ### Request Example ```python from getters import get_entry_data, get_entry_personal_data # Fetch data for team ID 4582 team_id = 4582 entry_data = get_entry_data(team_id) personal_data = get_entry_personal_data(team_id) # Current season gameweek-by-gameweek data current_season = entry_data['current'] for gw in current_season: print(f"GW{gw['event']}: {gw['points']} points, Rank: {gw['overall_rank']}") # Past seasons summary past_seasons = entry_data['past'] for season in past_seasons: print(f"{season['season_name']}: {season['total_points']} points, Rank: {season['rank']}") # Team leagues classic_leagues = personal_data['leagues']['classic'] print(f"Number of leagues: {len(classic_leagues)}") ``` ### Response #### Success Response (200) - **current** (array) - Gameweek-by-gameweek performance for the current season. - **past** (array) - Summary of performance for past seasons. - **leagues** (object) - Information about leagues the entry participates in. #### Response Example ```json { "current": [ { "event": 1, "points": 50, "overall_rank": 10000 } ], "past": [ { "season_name": "2022/23", "total_points": 2200, "rank": 5000 } ], "leagues": { "classic": [ { "id": 123, "name": "My Classic League" } ] } } ``` ``` -------------------------------- ### Parse Fixtures to CSV - Python Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Converts FPL fixture data from JSON format to a structured CSV file. It fetches fixture data using 'getters' and parses it using 'parsers', creating a 'fixtures.csv' file. ```python from getters import get_fixtures_data from parsers import parse_fixtures # Fetch and parse fixtures fixtures = get_fixtures_data() parse_fixtures(fixtures, 'data/2024-25/') # Creates: data/2024-25/fixtures.csv # Columns include: id, event (gameweek), team_h, team_a, team_h_score, # team_a_score, kickoff_time, finished, stats (detailed match events) ``` -------------------------------- ### Parse Individual Player History - Python Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Saves individual player gameweek and season history to separate CSV files. It requires player IDs, player names, and output directories, utilizing data from 'getters' and 'parsers' modules. ```python from getters import get_individual_player_data from parsers import parse_player_history, parse_player_gw_history from cleaners import get_player_ids # Get player name mapping player_ids = get_player_ids('data/2024-25/') player_id = 389 player_name = player_ids[player_id] # Fetch individual player data player_data = get_individual_player_data(player_id) # Parse season history parse_player_history( player_data['history_past'], 'data/2024-25/players/', player_name, player_id ) # Creates: data/2024-25/players/{player_name}_{id}/history.csv # Parse gameweek history parse_player_gw_history( player_data['history'], 'data/2024-25/players/', player_name, player_id ) # Creates: data/2024-25/players/{player_name}_{id}/gw.csv ``` -------------------------------- ### Fetch All Player Data - Python FPL API Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Retrieves the complete FPL bootstrap-static dataset, including all players, teams, gameweeks, and season information. The data is fetched using the `get_data` function and can be saved to a JSON file. It allows access to player, team, and gameweek data sections. ```python from getters import get_data import json # Fetch complete FPL data data = get_data() # Save to file with open('raw.json', 'w') as outf: json.dump(data, outf) # Access different data sections players = data['elements'] # All player data teams = data['teams'] # All team data gameweeks = data['events'] # All gameweek data # Example: Print first player's name and total points print(f"{players[0]['first_name']} {players[0]['second_name']}: {players[0]['total_points']} points") ``` -------------------------------- ### Import Multi-Season Merged FPL Data (Python) Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Loads and combines merged gameweek data across multiple FPL seasons ('2020-21' to '2023-24'). It cleans player names, filters for players active in the latest season, adds opponent team names, and exports the consolidated data to 'data/cleaned_merged_seasons.csv'. ```python from mergers import import_merged_gw, clean_players_name_string from mergers import filter_players_exist_latest, get_opponent_team_name from mergers import export_cleaned_data import pandas as pd # Import data for multiple seasons seasons = ['2020-21', '2021-22', '2022-23', '2023-24'] dfs = [] for season in seasons: season_path = import_merged_gw(season) df = pd.read_csv(season_path) df['season'] = season dfs.append(df) # Merge all seasons merged_df = pd.concat(dfs, ignore_index=True) # Clean player names merged_df = clean_players_name_string(merged_df, col='name') # Filter to players existing in latest season merged_df = filter_players_exist_latest(merged_df, col='position') # Add opponent team names merged_df = get_opponent_team_name(merged_df) # Export cleaned merged data export_cleaned_data(merged_df) # Creates: data/cleaned_merged_seasons.csv ``` -------------------------------- ### Fetch Team/Entry Performance Data - Python FPL API Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Retrieves historical performance data for a specific FPL team/manager ID. Uses `get_entry_data` for current and past season gameweek performance and `get_entry_personal_data` for league information. Outputs include gameweek points, overall rank, and league counts. ```python from getters import get_entry_data, get_entry_personal_data # Fetch data for team ID 4582 team_id = 4582 entry_data = get_entry_data(team_id) personal_data = get_entry_personal_data(team_id) # Current season gameweek-by-gameweek data current_season = entry_data['current'] for gw in current_season: print(f"GW{gw['event']}: {gw['points']} points, Rank: {gw['overall_rank']}") # Past seasons summary past_seasons = entry_data['past'] for season in past_seasons: print(f"{season['season_name']}: {season['total_points']} points, Rank: {season['rank']}") # Team leagues classic_leagues = personal_data['leagues']['classic'] print(f"Number of leagues: {len(classic_leagues)}") ``` -------------------------------- ### Access FPL Data via URL (Python/Pandas) Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Reads FPL gameweek data directly from a GitHub URL for the '2024-25' season using Pandas. Demonstrates analysis of top scorers by summing total points and filtering data for a specific gameweek. ```python import pandas as pd # Read merged gameweek data for 2024-25 season url = "https://raw.githubusercontent.com/vaastav/Fantasy-Premier-League/master/data/2024-25/gws/merged_gw.csv" df = pd.read_csv(url) # Analyze top scorers top_scorers = df.groupby('name')['total_points'].sum().sort_values(ascending=False).head(10) print("Top 10 scorers:") print(top_scorers) # Filter specific gameweek gw5_data = df[df['GW'] == 5] print(f"\nGameweek 5 top scorer: {gw5_data.loc[gw5_data['total_points'].idxmax(), 'name']}") ``` -------------------------------- ### Fetch Transfer History - Python FPL API Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Retrieves all transfers made by a specific team throughout the season. Uses the `get_entry_transfers_data` function with the team ID. The output details each transfer, including gameweek, players out/in, and cost. ```python from getters import get_entry_transfers_data # Get all transfers for team 4582 transfers = get_entry_transfers_data(4582) for transfer in transfers: print(f"GW{transfer['event']}: OUT {transfer['element_out']} -> IN {transfer['element_in']} (Cost: {transfer['element_in_cost']/10}m)") ``` -------------------------------- ### Clean Player Data - Python Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Cleans raw player data from a CSV file, calculating value per million and essential performance metrics. It requires input and output file paths and generates a 'cleaned_players.csv' file. ```python from cleaners import clean_players # Clean raw player data input_file = 'data/2024-25/players_raw.csv' output_dir = 'data/2024-25/' clean_players(input_file, output_dir) # Creates: data/2024-25/cleaned_players.csv # The output includes these columns: # first_name, second_name, goals_scored, assists, total_points, minutes, # goals_conceded, creativity, influence, threat, bonus, bps, ict_index, # clean_sheets, red_cards, yellow_cards, selected_by_percent, now_cost, # element_type (GK/DEF/MID/FWD), value_per_m ``` -------------------------------- ### Fetch Transfer History Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Retrieves all transfers made by a specific team throughout the season, detailing player ins and outs along with any cost implications. ```APIDOC ## Fetch Transfer History ### Description Retrieves all transfers made by a specific team throughout the season. ### Method GET ### Endpoint /api/entry/{entry_id}/transfers/ ### Parameters #### Path Parameters - **entry_id** (integer) - Required - The unique identifier for the FPL team/entry. ### Request Example ```python from getters import get_entry_transfers_data # Get all transfers for team 4582 transfers = get_entry_transfers_data(4582) for transfer in transfers: print(f"GW{transfer['event']}: OUT {transfer['element_out']} -> IN {transfer['element_in']} (Cost: {transfer['element_in_cost']/10}m)") ``` ### Response #### Success Response (200) - **transfers** (array) - An array of objects, each representing a transfer made. #### Response Example ```json [ { "event": 5, "element_out": 150, "element_in": 200, "element_in_cost": 55 } ] ``` ``` -------------------------------- ### Parse Raw Player Data to CSV - Python Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Fetches raw player and team data from the FPL API and parses it into structured CSV files. It depends on 'getters' and 'parsers' modules and creates 'players_raw.csv' and 'teams.csv'. ```python from getters import get_data from parsers import parse_players, parse_team_data # Fetch and parse all players data = get_data() parse_players(data['elements'], 'data/2024-25/') # Creates: data/2024-25/players_raw.csv # Parse team data parse_team_data(data['teams'], 'data/2024-25/') # Creates: data/2024-25/teams.csv ``` -------------------------------- ### Merge Gameweek CSVs - Python Source: https://context7.com/vaastav/fantasy-premier-league/llms.txt Combines individual gameweek CSV files into a single merged file or merges a specific gameweek's data. It requires the number of gameweeks or a specific gameweek number and the directory containing the gameweek CSVs. ```python from collector import merge_gw, merge_all_gws # Merge all gameweeks from 1 to 38 num_gws = 38 gw_directory = 'data/2024-25/gws' merge_all_gws(num_gws, gw_directory) # Creates: data/2024-25/gws/merged_gw.csv # Or merge a single gameweek merge_gw(10, gw_directory) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.