Package: yfpy
YFPY - Yahoo Fantasy Sports API WrapperPython API wrapper for the Yahoo Fantasy Sports public APIAuthor: Wren J. R. (uberfastman)Do you like the YFPY API wrapper? Star the repository on GitHub and please consider helping support its ongoing development:CryptocurrencyAddressBitcoin (BTC)bc1qataspvklhewtswm357m0677q4raag5new2xt3eEthereum (ETH)0x5eAa522e66a90577D49e9E72f253EC952CDB4059READ THE DOCS HERE!Detailed documentation on YFPY can be found athttps://yfpy.uberfastman.com.Table of ContentsAboutInstallationSetupUsageTestingDependenciesTroubleshootingAboutYFPY is a comprehensive wrapper around the Yahoo Fantasy Sports API. It allows for easy retrieval and parsing of almost any data you might wish to extract and use from any Yahoo fantasy league to which your Yahoo account has access (or for public leagues). The primary focus of this wrapper is on fantasy football (NFL), but it also supports usage with fantasy hockey (NHL), fantasy baseball (MLB), and fantasy basketball (NBA).InstallationPipIf you wish to use YFPY within another project, from within your project directory, runpipinstallyfpyor addyfpyto your projectrequirements.txt.ManualIf you wish to download and use YFPY locally, clone the git repository:gitclonegit@github.com:uberfastman/yfpy.gitSetupYahoo Developer Network AppIn order to use YFPY with private fantasy leagues, you must set up an app on your Yahoo account to allow access. Follow the step-by-step guide below for instructions on how to do so, or seeGetting Startedin the Yahoo Developer Network docs for more details.Note:If you are only planning on using YFPY to pull "read only" data from public leagues, you do not need to do this.Log in to a Yahoo account with access to whatever fantasy leagues from which you wish to retrieve data.Go tohttps://developer.yahoo.com/apps/create/and create an app (you must be logged into your Yahoo account as stated above). For the app, select the following options:Application Name(Required):yfpy(you can name your app whatever you want, but this is just an example).Application Type(Required): select theInstalled Applicationradio button.Description(Optional): youmaywrite a short description of what the app does.Home Page URL(Optional): if you have a web address related to your app youmayadd it here.Redirect URI(s)(Required): this field must contain a valid redirect address, so you can usehttps://localhost:8080API Permissions(Required): check theFantasy Sportscheckbox. You can leave theReadoption selected (appears in an accordion expansion underneath theFantasy Sportscheckbox once you select it).Click theCreate Appbutton.Once the app is created, it should redirect you to a page for your app, which will show both aClient IDand aClient Secret.Make a copy ofauth/private.template.json, rename it to justprivate.json, and copy theClient IDandClient Secretvalues to their respective fields (make sure the strings are wrapped regular quotes (""), NOT formatted quotes (“”)). The path to this file will be needed to point YFPY to your credentials.Now you should be ready to initialize the OAuth2 connection between YFPY your Yahoo account.UsageAuthenticationFollow the instructions in theInstallationandSetupsections.Thefirsttime you use YFPY, a browser window will open up asking you to allow your app to access your Yahoo fantasy sports data. YouMUSThit allow, and then copy the verification code that pops up into the command line prompt where it will now be asking for verification, hit enter, and the OAuth2 three-legged handshake should be complete and your data should have been successfully retrieved.YFPY should have now generated atoken.jsonfor you in the same directory where you stored yourprivate.jsoncredentials, and for all subsequent runs of your app, you should be able to keep retrieving Yahoo fantasy sports data using YFPY without re-verifying, since the generated refresh token should now just renew whenever you use the sametoken.jsonfile to authenticate your app.Querying the Yahoo Fantasy Sports APISee the documentation on theyfpy.query.YahooFantasySportsQueryclass for example usage of all available queries.Seequickstart/quickstart.pyfor example usage output.Uncomment/comment out whichever configuration values in their respective functions with which you wish to experiment.Uncomment/comment out whichever query lines in theRUN QUERIESsection you wish to run.Uncomment/comment out whichever query lines in theCHECK FOR MISSING DATA FIELDSsection you wish to check for any new/missing data fields returned by the Yahoo Sports Fantasy Football API.DockerYFPY can be used within Docker for a more seamless, platform-agnostic experience.Run the Docker container (pulls the YFPY Docker image from GitHub Package Registry):dockercomposeupYou can then run commands in the Docker container in two different ways:Connect to the running container and run commands from within it:dockerexec-ityfpy-package-1bashThen:pythonquickstart/quickstart.pySend commands to the running container from your host machine:dockerexec-iyfpy-package-1bash-c"python quickstart/quickstart.py"Docker Development (optional)Run the Docker container for local development (mount all local code into container):dockercompose-fcompose.yaml-fcompose.dev.yamlupDocker Image DeploymentSeeDEPLOYMENT.mdfor Docker image deployment.TestingYFPY has a collection of fully functional code snippets that can be run usingpytest. These snippets demonstrate how to use YFPY to retrieve your Yahoo Fantasy Sports data.UnitSee thetest/unitdirectory for example code snippets using pytest.IntegrationSee thetest/integrationdirectory for example code snippets using pytest.Before running any integration tests, make a copy ofauth/.env.templatein theauth/directory and rename it to.env.Copy your YahooClient IDandClient Secretinto the environment variables in.envso that pytest can use them when hitting the Yahoo Fantasy Sports API.If this is the first time running pytest with your Yahoo API credentials, youMUSTallow interactive prompts within pytest by using the-sflag.The fixture values intest/integration/conftest.pyare defined inquickstart/quickstart.py, and can be changed for testing by uncommenting/commenting out the values inside each respective function.RunningYou can invoke all pytest tests (both integration test and unit tests) by running the below from the root directory:pytest -v -sIf you want to run only the unit tests, you can run:pytest -v -s -m unitIf you want to run only the integration tests, you can run:pytest -v -s -m integrationDependenciesPlatformYFPY has only been tested extensively on macOS, but is written to be platform-agnostic, and seems to work without issue on Windows and Linux.PythonYFPY requires Python 3.8 or later, and has been tested through Python 3.11.DevelopmentDirect project dependencies can be viewed inrequirements.txt, and additional development and build dependencies (notincluding transitive dependencies) can be viewed inrequirements-dev.txt.TroubleshootingYahoo Fantasy Sports APIOccasionally when you use the Yahoo Fantasy Sports API, there are hangups on the other end that can cause data not to transmit, and you might encounter an error similar to this:Traceback (most recent call last):
  File "yfpy-app.py", line 114, in <module>
    var = app.run()
  File "/Users/your_username/PATH/T0/LOCAL/PROJECT/yfpy-app.py", line 429, in run
    for team in team_standings:
IndexError: list index out of rangeTypically, when the above error (or a similar error) occurs, it simply means that one of the Yahoo Fantasy Sports API calls failed and so no data was retrieved. This can be fixed by simply re-running data query.