Skip to main content

Python API wrapper for the Yahoo Fantasy Sports public API.

Project description

 __     ________ _______     __
 \ \   / /  ____|  __ \ \   / /
  \ \_/ /| |__  | |__) \ \_/ / 
   \   / |  __| |  ___/ \   /  
    | |  | |    | |      | |   
    |_|  |_|    |_|      |_|   

Python API wrapper for the Yahoo Fantasy Sports public API

By Wren J. R. (uberfastman)

GitHub release (latest SemVer) GitHub tag (latest SemVer) GitHub Workflow Status (branch)

PyPI PyPI PyPI PyPI


Do you like the YFPY API wrapper? Star the repository here on GitHub and please consider helping support its ongoing development:

Cryptocurrency Address
Bitcoin (BTC) bc1qataspvklhewtswm357m0677q4raag5new2xt3e
Ethereum (ETH) 0x5eAa522e66a90577D49e9E72f253EC952CDB4059

Yahoo Fantasy Sports API Wrapper (YFPY)

Table of Contents


About

YFPY 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).


Installation

  • If you wish to use YFPY within another project, from within your project directory, run

    pip install yfpy
    

    or add yfpy to your project requirements.txt.

  • If you wish to download and use YFPY locally, clone the git repository:

    git clone git@github.com:uberfastman/yfpy.git
    

Setup

  • Log in to a Yahoo account with access to whatever fantasy leagues from which you wish to retrieve data.
  • Go to https://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 the Installed Application radio button.
    • Description (Optional): you may write a short description of what the app does.
    • Home Page URL (Optional): if you have a web address related to your app you may add it here.
    • Redirect URI(s) (Required): this field must contain a valid redirect address, so you can use https://localhost:8080
    • API Permissions (Required): check the Fantasy Sports checkbox. You can leave the Read option selected (appears in an accordion expansion underneath the Fantasy Sports checkbox once you select it).
    • Click the Create App button.
    • Once the app is created, it should redirect you to a page for your app, which will show both a Client ID and a Client Secret.
    • Make a copy of test/EXAMPLE.private.json, rename it to just private.json, and copy the Client ID and Client Secret values 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.

Usage

  • Follow the instructions in the Installation and Setup sections.
  • The first time you use YFPY, a browser window will open up asking you to allow your app to access your Yahoo fantasy sports data. You MUST hit 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 a token.json for you in the same directory where you stored your private.json credentials, 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 same token.json file to authenticate your app.

Testing

YFPY has a collection of fully functional code snippets that can be run using pytest. These snippets demonstrate how to use YFPY to retrieve your Yahoo Fantasy Sports data.

  • See test/test_yfpy.py for the example code snippets.
  • Before running any tests, make a copy of test/EXAMPLE.env in the test directory and rename it to .env.
  • Copy your Yahoo Client ID and Client Secret into the environment variables in .env so that pytest can use them when hitting the Yahoo Fantasy Sports API.
  • You can invoke the pytest tests by first changing to the test directory from the root of the YFPY repository:
    • cd test
    • pytest test_yfpy.py
  • If you want to run the tests from elsewhere, you will need to allow pytest to use interactive prompts:
    • pytest -s test/test_yfpy.py

Dependencies

YFPY has only been tested on macOS, but is written to be platform-agnostic. It runs only in Python 3, and has only been tested from Python 3.6 through Python 3.10.

Direct project dependencies can be viewed in requirements.txt, and all dependencies, including transitive dependencies, can be viewed in dev-requirements.txt.


Troubleshooting

Occasionally 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 range

Typically 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yfpy-4.1.4.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yfpy-4.1.4-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

Details for the file yfpy-4.1.4.tar.gz.

File metadata

  • Download URL: yfpy-4.1.4.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.12

File hashes

Hashes for yfpy-4.1.4.tar.gz
Algorithm Hash digest
SHA256 7b1127c1f80fbbe967043acf8a2d6cf98d55da67557e1e014322922b9367c4a8
MD5 ef3bca916201ae96767deb320489ecf2
BLAKE2b-256 053cc098fb0b0efd49d436ebbca68b15e0dbced676f2bc0cd2f65c5429ec9db7

See more details on using hashes here.

File details

Details for the file yfpy-4.1.4-py3-none-any.whl.

File metadata

  • Download URL: yfpy-4.1.4-py3-none-any.whl
  • Upload date:
  • Size: 44.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/57.4.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.12

File hashes

Hashes for yfpy-4.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9180d05b6eb6fee0a8ba438c5eb0e844ea91582ba88c0e22b34718d5e2fd9975
MD5 94175d0e0f4eabbf72847021fb2782de
BLAKE2b-256 dae522b5b717c8cfda4f8396838286b32a4c33ce9e34fc05c28724a48510e972

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page