toddrob99 / MLB-StatsAPI

Python wrapper for MLB Stats API
GNU General Public License v3.0
513 stars 98 forks source link

Determining a list of teams that a player played on #121

Closed Dang1es closed 11 months ago

Dang1es commented 1 year ago

Hello, I am new to Python and I am having trouble determining how to find the teams that a player has played for.

toddrob99 commented 1 year ago

Try something like this:

import statsapi
harper = statsapi.get("person", {"personId": 547180, "hydrate": "transactions"})["people"][0]
print(harper["transactions"])

The transactions should include all of the teams the player has played for. There might be other endpoints that include what you're looking for, but that's the first method that came to my mind.