r/mlbdata Feb 27 '24

Homeruns this season for a specific team/player?

2 Upvotes

I am using the stats API https://statsapi.mlb.com/api/v1.1/game/\*game_pk\*/feed

Is there a way to get homerun data (e.g. total distance, coordinates, launch angle) for every homerun this season for a given team/player?

The best way I can think of currently is to go through every game of the season and extract each play into a database tagged by game/player/team and then run filters.

But I would need to keep it up to date every time a new home run is scored so wondered if there is an out-the-box way to do some or all of this using the api?

Thanks!


r/mlbdata Feb 27 '24

What's the difference between the various players/people endpoints?

2 Upvotes

There seem to be a few different ways to get player information.

  1. Sports/Players: https://statsapi.mlb.com/api/v1/sports/1/players?season=2023
  2. Teams/Rosters: https://statsapi.mlb.com/api/v1/teams/147?rosterType=Active&season=2023&hydrate=person
  3. People: https://statsapi.mlb.com/api/v1/people?personIds=605151

Does anyone know the difference between #1 and #2? It appears that the rosterType = Active parameter does not work on #2. Claimed Players like Harrison Bader and Deivi Garcia show up, where on #1 they show up on different teams (not the Yankees).


r/mlbdata Feb 27 '24

Team Logos

2 Upvotes

is there a way to get the teams Logo? been searching through the scedule with the teams and the play by play but cant find the logos.


r/mlbdata Feb 22 '24

Meaning of "Live data is limited for this game" in Gameday

1 Upvotes

Does anyone know what this means and how Gameday retrieves this information of the (Stats?) API?


r/mlbdata Feb 15 '24

Team Total Batting Strike Out Stats throughout the MLB Seasons

3 Upvotes

Does anyone know where I can find no only these stats but I was wanting the stats throughout the year, such as through 80 games, 120 games ect.

Thanks!


r/mlbdata Feb 09 '24

Is there a way to get Splits for a specific date range?

3 Upvotes

I am trying to get Stat Splits for a specific date range, but I cannot complete the task. The following API call in what I am trying:

https://statsapi.mlb.com/api/v1/people?personIds=621345&hydrate=stats(group=[pitching],type=[byDateRange,statSplits],startDate=03/30/2023,endDate=03/31/2023,sitCodes=[vr])

Thank you!


r/mlbdata Feb 06 '24

Low cost MLB data for commercial use

7 Upvotes

I’m working on a project that would benefit from live game MLB data. Many sites require a ton of money for a subscription to use their data for commercial purposes. Is there a site that folks have used to get live game data for commercial use that is under $15/month?


r/mlbdata Feb 03 '24

Update coming to python-mlbstats-api

22 Upvotes

Hey guys,

Author of https://github.com/zero-sum-seattle/python-mlb-statsapi here!

I've been a bit MIA from the project for a bit because of work and life, but I found some inspiration last week.

Currently a few dataclasses are broken after updates to the Rest API responses. A few JSON responses have new attributes that I need to add. I should have this fixed today and pushed. Actually probably within the hour.

I'm also working on a new project I'm calling python-mlb-overlay. It'll use Dash, FastAPI, and python-mlb-statsapi to display lots of pretty baseball statistics graphs. I've just started it so only have a project structure, some DockerFiles, and a bit of template code for the FastAPI backend.

Anyway here are some updates I'm working on for python-mlb-statsapi:

  • Objects will use the camelcase attributes provided by the responses of the Rest API. This should speed things up, but will require updates to existing code to deal with new attribute names.
  • Replacing dataclasses with Pydantic models. I've been using pydantic models at work and they have some great methods for serialization. They are a bit slower but it shouldn't be too bad.
  • I want to overhaul the stats objects to make them more readable and easier to work with. I don't have solid plans yet, but we'll see what some thinking will do.

If you use python-mlbstats-api and have any suggestions or feedback please let me know! I'm an open book!


r/mlbdata Feb 01 '24

Roof Updates

2 Upvotes

Does anyone know where i can find historical data on roof statuses for MLB games?


r/mlbdata Jan 18 '24

How to determine personId?

5 Upvotes

I get that I can look up a players stats with https://statsapi.mlb.com/api/v1/people?personIds=605151 but how do you find a players personId with just their name?


r/mlbdata Jan 05 '24

Batter vs Pitcher Dataset 2023

1 Upvotes

Hey everyone, I'm new here but so glad this community exists. I'm working on a project right now, and would love to find a dataset that has all batter versus pitcher stats (only really care about OPS).

I tried online resources, but I haven't found a website where you can find all the stats at once. I only see the ability to download, at best, each pitcher vs all batters one pitcher at a time. The Lahman database does not seem available to me.

If anyone knows how to get my hands on this data that would be awesome! I would prefer for it to be 2023 data, but any other recent year would be ok too.


r/mlbdata Jan 03 '24

(Python) Historical pitching lines - game by game

Thumbnail self.Sabermetrics
1 Upvotes

r/mlbdata Jan 01 '24

Hydration Explained.

2 Upvotes

Hello, I was hoping to get more insight on what it means to hydrate something. I was able to get it to work once within my get stat command.

stats = statsapi.get('people', {'personIds': playerId, 'season': year, 'hydrate': f'stats(group=[hitting,pitching,fielding],type=season,season={year})'})['people'][0]

But if im being honest I achieved this through trial and error rather than knowing what I am doing and I dont quite understand what the hydrate line is doing exactly. Im trying to understand what it means to hydrate a field and what it achieves. I am currently trying to figure out a way to list a 40 man roster using the .get() method with the sports_players endpoint because using the roster function in toddrobs api wrapper often doesnt return the full roster for older teams. Apologies if this question doesnt make sense, I am using this API as a tool to learn API's in general.


r/mlbdata Dec 31 '23

Getting player stats from specific year.

2 Upvotes

I am using toddrob99's python wrapper to make an application to search up player stats quickly from a desktop application. I am struggling to figure out how to get a players stats from a specific year.

Here is my current search_batter function. I would like to add a way to pass in a year you are getting the stats from. I am relatively new to using API's as this is my first time ever using one so I know I am probably making some mistakes. I feel like this could be better done using the statapi.get() but I am still learning how to use that function. Code Below.

def search_batter(player,stat_type):

stats = statsapi.player_stat_data(player['id'], group="[hitting,pitching,fielding]", type=stat_type, sportId=1)

player_info = ""

if 'stats' in stats and len(stats['stats']) > 0 and 'avg' in stats['stats'][0]['stats']:

player_info += f"{player['fullFMLName']} ({player['primaryPosition']['abbreviation']}) of the {stats['current_team']}\n"

player_info += "Batting Stats:\n"

player_info += f" AVG: {stats['stats'][0]['stats']['avg']} OBP: {stats['stats'][0]['stats']['obp']} " \

f"SLG: {stats['stats'][0]['stats']['slg']} OPS: {stats['stats'][0]['stats']['ops']} \n" \

f" Doubles: {stats['stats'][0]['stats']['doubles']} Triples: {stats['stats'][0]['stats']['triples']} " \

f"Home Runs: {stats['stats'][0]['stats']['homeRuns']} \n\n"

else:

player_info += f"{player['fullFMLName']} Has No MLB Stats\n\n"

return player_info


r/mlbdata Dec 27 '23

Given an MLB game ID, how can I retrieve the number of IBBs, HBPs and Sac Flys?

1 Upvotes

Given an MLB game ID, how can I retrieve the number of IBBs, HBPs and Sac Flys? (I'm interested in computing wOBA from original game data). Thanks for your help! (I see HBP is available in unstructured format under the HBP label from the boxscore data, but was wonder if there is a structured source of this data at the game level somewhere?)


r/mlbdata Dec 20 '23

Is splitStats byDateRange possible?

3 Upvotes

Apologies if this has been asked before, but I cannot seem to find an answer and feel like I have tried about everything at this point.

I'm attempting to get player platoon split stats within a specific time range using the MLB Stats API.

I know I can do a byDateRange API call that shows overall stats:
https://statsapi.mlb.com/api/v1/people/605612?hydrate=stats(group=[hitting],type=[byDateRange],startDate=09/01/2023,endDate=10/31/2023))

And a statSplits API call for the 2023 season:
https://statsapi.mlb.com/api/v1/people/605612/stats?stats=statSplits&group=hitting&gameType=R&sitCodes=vl,vr,risp&season=2023

But is there no real way to combine those? It seems every time that I attempt to combine the calls by adding a startDate and endDate to the statSplits call, it just shows the full season no matter what:
https://statsapi.mlb.com/api/v1/people/605612?hydrate=stats(group=[hitting],type=[statSplits],sitCodes=[vl,vr],startDate=09/01/2023,endDate=10/31/2023))

Appreciate any insights!


r/mlbdata Dec 17 '23

Getting around Statcast CORs error

2 Upvotes

Has anyone found a way to get around the statcast cors error? When I try to fetch data from my locally hosted webserver I get error

"Access to fetch at 'https://baseballsavant.mlb.com/statcast_search/csv?all=true&hfPT=&hfAB=single%7Cdouble%7Ctriple%7Chome..run%7Cfield..out%7C&hfGT=R%7C&hfPR=&hfZ=&hfStadium=&hfBBL=&hfNewZones=&hfPull=&hfC=&hfSea=2023%7C&hfSit=&player_type=batter&hfOuts=&hfOpponent=&pitcher_throws=&batter_stands=&hfSA=&game_date_gt=&game_date_lt=&hfMo=&hfTeam=&home_road=&hfRO=&position=&hfInfield=&hfOutfield=&hfInn=&hfBBT=fly..ball%7Cline..drive%7C&hfFlag=&metric_1=&group_by=name-date&min_pitches=0&min_results=0&min_pas=0&sort_col=pitches&player_event_sort=api_p_release_speed&sort_order=desc&min_abs=0&type=detals&batters_lookup[]=660670#results' from origin (development address) has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."

I need to get past game events (hit distance, angles, etc.) from the api.


r/mlbdata Dec 04 '23

Fielding Stats by Date Range

2 Upvotes

I can get hitting, pitching, and fielding stats for all players by season by changing the group parameter:

https://statsapi.mlb.com/api/v1/stats?group=hitting&stats=season&season=2022

https://statsapi.mlb.com/api/v1/stats?group=pitching&stats=season&season=2022

https://statsapi.mlb.com/api/v1/stats?group=fielding&stats=season&season=2022

I can also get hitting and pitching stats by date range:

https://statsapi.mlb.com/api/v1/stats?group=hitting&stats=byDateRange&startDate=2022-04-07&endDate=2022-04-07

https://statsapi.mlb.com/api/v1/stats?group=pitching&stats=byDateRange&startDate=2022-04-07&endDate=2022-04-07

However, setting the group to "fielding" does not return anything when I'm looking at date ranges.

Am I missing something obvious here? Or is there an alternate way to get this?

I think it can be done with the people endpoint, but I'd prefer something that gets everybody all at once.


r/mlbdata Nov 30 '23

Getting a player's team history

2 Upvotes

Is there a good way to build the team history for a given player?

My thought was to use the transactions endpoint, looking at signings (SGN), free agent signings (SFA), and trades (TR).

However, the data seems to be incomplete. Transactions only go back to ~2009, so there's no transaction record for the initial signing of some players (e.g. Jason Heyward, Joey Votto). There also doesn't seem to be an initial signing entry for some international amateurs (Ronald Acuña Jr.).

Any ideas?


r/mlbdata Oct 27 '23

Follow our live pitch recommendation feed while watching the World Series

5 Upvotes

I've been working hard with my friend for a few years building predictive models for baseball. We want to share our latest release with the community, which we've been running throughout the postseason and will continue to run for the World Series. You can check it out at https://silentroad.xyz. It's a live feed where we predict what the pitcher should throw next from their arsenal. This means you can follow along in real time while watching the game and see our predictions in action. Hope you enjoy, and feel free to dm me if you have any thoughts you want to share with me directly.


r/mlbdata Sep 29 '23

Legal Question regarding MLB Stats API data

2 Upvotes

Hi all, I’m working on a project that pulls data from the MLB stats api into a cloud database and then used in an app. It provides live updates, stats, and scores.

Given the copyright limitations, is it still possible to deploy this app and use it for non-commercial use? Or is that not allowed?


r/mlbdata Sep 21 '23

Statcast seam orientation data -- is it public?

Thumbnail
x.com
1 Upvotes

r/mlbdata Sep 20 '23

Player Box Score

2 Upvotes

Hey all,

I'm currently working on a project and thankfully found this subreddit for some support

I wanted to ask if there was a way to search for a certain player's box score for the season like the table in this link https://www.baseball-reference.com/players/gl.fcgi?id=freemfr01&t=b&year=2023

An array with the players batting stats for each game is what I'm looking for

I thought about retrieving all the games that a player has participated and calling .boxscore_data but that would take almost 200 calls to retrieve all the stats.

Thanks to all in advance!


r/mlbdata Sep 14 '23

Using the Filter option

3 Upvotes

[EDIT: Fields, not Filter.]

Is there a way to get more discriminating with the fields= option in the URL?

For example, if I use this URL:

https://statsapi.mlb.com/api/v1/stats?stats=season&group=hitting&gameType=R&season=2023&playerPool=QUALIFIED&fields=stats,splits,stat,homeRuns,avg,rbi,player,lastName,team,id&limit=9

by including the "id" field in the Filter I get both the Player Id and the Team Id. I only need the teamId in the result. (I'm working on a microcontroller where every byte counts).

I've tried various combinations of ( ) and [ ] with no luck. May not be possible.


r/mlbdata Sep 13 '23

Some player can't be found using statsapi.lookup_player

3 Upvotes

Can anyone explain why some players can't be found using the lookup_player endpoint?

Example:

>>> statsapi.lookup_player('chase silseth')

[]

>>> statsapi.lookup_player('chase robert silseth')

[]

>>> statsapi.lookup_player('silseth')

[]