yfpy


Nameyfpy JSON
Version 16.0.3 PyPI version JSON
download
home_pagehttps://github.com/uberfastman/yfpy
SummaryPython API wrapper for the Yahoo Fantasy Sports public API.
upload_time2024-09-23 01:56:06
maintainerNone
docs_urlNone
authorWren J. R.
requires_python>=3.10
licenseNone
keywords yahoo fantasy sports api wrapper nfl football nhl hockey mlb baseball nba basketball
VCS
bugtrack_url
requirements bandit coverage flake8 pytest python-dotenv requests ruamel.yaml stringcase yahoo-oauth
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [<img src="https://raw.githubusercontent.com/uberfastman/yfpy/refs/heads/main/docs/yfpy-logo.svg" width="400"/>](https://github.com/uberfastman/yfpy)

## YFPY - Yahoo Fantasy Sports API Wrapper
Python API wrapper for the Yahoo Fantasy Sports public API

*Author: Wren J. R. (uberfastman)*

[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/uberfastman/yfpy?color=yellowgreen&label=latest%20release&sort=semver)](https://github.com/uberfastman/yfpy/releases/latest)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/uberfastman/yfpy?color=yellowgreen&label=latest%20version&sort=semver)](https://github.com/uberfastman/yfpy/tags)
[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/uberfastman/yfpy/python-package.yml?color=brightgreen&label=build)](https://github.com/uberfastman/yfpy/actions/workflows/python-package.yml)

[![PyPI](https://img.shields.io/pypi/v/yfpy.svg?style=flat)](https://pypi.python.org/pypi/yfpy)
[![PyPI](https://img.shields.io/pypi/dm/yfpy.svg?style=flat)](https://pypi.python.org/pypi/yfpy)
[![PyPI](https://img.shields.io/pypi/pyversions/yfpy.svg?style=flat)](https://pypi.python.org/pypi/yfpy)
[![PyPI](https://img.shields.io/pypi/l/yfpy.svg?style=flat)](https://pypi.python.org/pypi/yfpy)

---

<sub>***Do you like the YFPY API wrapper? Star the repository on GitHub and please consider helping support its ongoing development:***</sub>

[<img src="https://github.com/uberfastman/yfpy/raw/main/resources/images/donate-paypal.png" width="75"/>](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=VZZCNLRHH9BQS) [<img src="https://github.com/uberfastman/yfpy/raw/main/resources/images/donate-bitcoin.png" width="75"/>](https://share.trustwallet.com/ZoAkTpY1I9) [<img src="https://github.com/uberfastman/yfpy/raw/main/resources/images/donate-ethereum.png" width="75"/>](https://share.trustwallet.com/MF8YBO01I9)

|                                                                <sub><sup>Cryptocurrency</sup></sub> |                                                      <sub><sup>Address</sup></sub>                                                       |
|----------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------:|
|                                                                 <sub><sup>Bitcoin (BTC)</sup></sub> |                                    <sub><sup>`bc1qataspvklhewtswm357m0677q4raag5new2xt3e`</sup></sub>                                    | 
|                                                                <sub><sup>Ethereum (ETH)</sup></sub> |                                    <sub><sup>`0x5eAa522e66a90577D49e9E72f253EC952CDB4059`</sup></sub>                                    |

<sub><sup></sup></sub>

---

**[READ THE DOCS HERE!](https://yfpy.uberfastman.com)**
<br/>
<sup>Detailed documentation on YFPY can be found at [https://yfpy.uberfastman.com](https://yfpy.uberfastman.com).</sup>

### Table of Contents
* [About](#about)
* [Installation](#installation)
    * [Pip](#pip)
    * [Manual](#manual)
* [Setup](#setup)
    * [Yahoo Developer Network App](#yahoo-developer-network-app)
    * [Environment Variables](#environment-variables)
* [Usage](#usage)
    * [Authentication](#authentication)
        * [Programmatic Persistent Authentication](#programmatic-persistent-authentication)
        * [Persistent Authentication Using Access Token Fields](#persistent-authentication-using-access-token-fields)
        * [Persistent Authentication Using Access Token JSON](#persistent-authentication-using-access-token-json)
    * [Querying the Yahoo Fantasy Sports API](#querying-the-yahoo-fantasy-sports-api)
    * [Docker](#docker)
        * [Docker Development](#docker-development)
        * [Docker Image Deployment](#docker-image-deployment)
* [Testing](#testing)
    * [Unit Tests](#unit-tests)
    * [Integration Tests](#integration-tests)
    * [Run Tests](#run-tests)
* [Dependencies](#dependencies)
    * [Platform](#platform)
    * [Python](#python)
    * [Development](#development)
* [Troubleshooting](#troubleshooting)
    * [Yahoo Fantasy Sports API](#yahoo-fantasy-sports-api)

---

<a name="about"></a>
### 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). 

---

<a name="installation"></a>
### Installation

<a name="pip"></a>
#### Pip

* If you wish to use YFPY within another project, from within your project directory, run
    ```shell
    pip install yfpy
    ```
    
    or add `yfpy` to your project `requirements.txt`.

<a name="manual"></a>
#### Manual

* If you wish to download and use YFPY locally, clone the git repository:
  ```shell
  git clone git@github.com:uberfastman/yfpy.git
  ```

---

<a name="setup"></a>
### Setup

<a name="yahoo-developer-network-app"></a>
#### Yahoo Developer Network App

In 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 see [Getting Started](https://developer.yahoo.com/oauth2/guide/openid_connect/getting_started.html) in 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 to [https://developer.yahoo.com/apps/create/](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`.
    * Copy the `Client ID` and `Client Secret` and proceed with the steps in [Environment Variables](#environment-variables) or [Programmatic Persistent Authentication](#programmatic-persistent-authentication).

<a name="environment-variables"></a>
#### Environment Variables

YFPY now supports the usage of environment variables, either directly within the command line or using a `.env` file. Any environment variables exported to the same shell in which YFPY runs will automatically be read when a `YahooFantasySportsQuery` object is instantiated when `env_var_fallback=True` (default).

* If you wish to *also* use environment variables stored in a `.env` file, you can set up a `.env` file by making a copy of `.env.template` in the root project directory and renaming it `.env` (you can do this in the command line by running `cp .env.template .env`).
* Paste the `Client ID` and `Client Secret` retrieved by following the steps in [Yahoo Developer Network App](#yahoo-developer-network-app) into their respective environment variables in your `.env` file:
```dotenv
YAHOO_CONSUMER_KEY=<YAHOO_DEVELOPER_APP_CONSUMER_KEY_STRING>
YAHOO_CONSUMER_SECRET=<YAHOO_DEVELOPER_APP_CONSUMER_SECRET_STRING>
```
* YFPY is configured by default to check for environment variables for authentication with Yahoo, so you will now be able to proceed directly to [Authentication](#authentication).

**Note**: *You can disable the fallback to environment variables behavior during instantiation of a YFPY query by passing the argument `env_var_fallback=False` to the object:*
```python
from yfpy.query import YahooFantasySportsQuery

query = YahooFantasySportsQuery(
    league_id="<YAHOO_LEAGUE_ID>",
    game_code="nfl",
    game_id=449,
    yahoo_consumer_key="<YAHOO_CONSUMER_KEY>",
    yahoo_consumer_secret="<YAHOO_CONSUMER_SECRET>",
    env_var_fallback=False
)
```

---

<a name="usage"></a>
### Usage

<a name="authentication"></a>
#### Authentication

* Follow the instructions in the [Installation](#installation) and [Setup](#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.

**Note**: *If you are running YFPY in Docker, instead of opening a new browser window, YFPY will output a URL to the command line, which you must then copy to a browser window in order to log in to your Yahoo account, allow access to your app, and retrieve the required verification code.*

<a name="programmatic-persistent-authentication"></a>
##### Programmatic Persistent Authentication

YFPY supports programmatic authentication using `yahoo_consumer_key` and `yahoo_consumer_secret` arguments when instantiating a `YahooFantasySportsQuery` object. Additionally, you can pass in either a valid JSON string or a Python dictionary to `yahoo_access_token_json` containing all required fields of a Yahoo access token.

* Providing `yahoo_consumer_key` and `yahoo_consumer_secret` overrides any values provided in a `.env` file.
* Providing a value to `yahoo_access_token_json` overrides `yahoo_consumer_key`/`yahoo_consumer_secret` values *and* any values provided in a `.env` file for Yahoo access token individual fields.
  * Required fields (either in a JSON string with escaped double quotes or a Python dictionary) for the value of `yahoo_access_token_json` are the following:
    * `access_token`
    * `consumer_key`
    * `consumer_secret`
    * `guid`
    * `refresh_token`
    * `token_time`
    * `token_type`
  * The `consumer_key` and `consumer_secret` fields in `yahoo_access_token_json` override any values provided in `yahoo_consumer_key`/`yahoo_consumer_secret`.

Example of Using `yahoo_access_token_json`:
```python
from yfpy.query import YahooFantasySportsQuery

query = YahooFantasySportsQuery(
    league_id="<YAHOO_LEAGUE_ID>",
    game_code="nfl",
    game_id=449,
    yahoo_access_token_json={
        "access_token": "<YAHOO_ACCESS_TOKEN>",
        "consumer_key": "<YAHOO_CONSUMER_KEY>",
        "consumer_secret": "<YAHOO_CONSUMER_SECRET>",
        "guid": "<YAHOO_TOKEN_GUID>",
        "refresh_token": "<YAHOO_REFRESH_TOKEN>",
        "token_time": 1234567890.123456,
        "token_type": "bearer"
    }
)
```

<a name="persistent-authentication-using-access-token-fields"></a>
##### Persistent Authentication Using Access Token Fields

* YFPY no longer uses JSON files to store Yahoo credentials or access tokens. However, if you wish to preserve your access token in order to remain verified, you can now instantiate a YFPY query with `save_token_data_to_env_file=True`, which will write all required Yahoo access token fields an `.env` file located in the provided `env_file_location` directory.
* 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 `.env` file to authenticate your app.

**Note**: *You **MUST** provide a value for `env_file_location` or else **NO** Yahoo access token data will be saved!*

<a name="persistent-authentication-using-access-token-json"></a>
##### Persistent Authentication Using Access Token JSON

* YFPY *also* supports the use of a **single** environment variable by providing a valid JSON string in `YAHOO_ACCESS_TOKEN_JSON`. This environment variable is only used if `env_var_fallback=True` (default) when instantiating a YFPY query.
* You can save the Yahoo access token fields as valid JSON with escaped double quotes (`"`) by invoking `YahooFantasySportsQuery.save_access_token_data_to_env_file` with `save_json_to_var_only=True` (instead of saving the Yahoo access token fields to individual environment variables as described in [Persistent Authentication Using Access Token Fields](#persistent-authentication-using-access-token-fields)) like below:
```python
from pathlib import Path

from yfpy.query import YahooFantasySportsQuery

query = YahooFantasySportsQuery(
    league_id="<YAHOO_LEAGUE_ID>",
    game_code="nfl",
    game_id=449,
    yahoo_consumer_key="<YAHOO_CONSUMER_KEY>",
    yahoo_consumer_secret="<YAHOO_CONSUMER_SECRET>",
    env_file_location=Path(".env")
)

query.save_access_token_data_to_env_file(
    env_file_location=Path(".env"), 
    save_json_to_var_only=True
)
```

<a name="querying-the-yahoo-fantasy-sports-api"></a>
#### Querying the Yahoo Fantasy Sports API

* See the documentation on the  [`yfpy.query.YahooFantasySportsQuery`](https://yfpy.uberfastman.com/_autosummary/yfpy.query.YahooFantasySportsQuery.html#yfpy.query.YahooFantasySportsQuery) class for example usage of all available queries.
* See [`quickstart/quickstart.py`](https://github.com/uberfastman/yfpy/blob/main/quickstart/quickstart.py) for 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 the `RUN QUERIES` section you wish to run.
  * Uncomment/comment out whichever query lines in the `CHECK FOR MISSING DATA FIELDS` section you wish to check for any new/missing data fields returned by the Yahoo Sports Fantasy Football API.

<a name="docker"></a>
#### Docker

YFPY 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):
    ```shell
    docker compose up
    ``` 
* You can then run commands in the Docker container in two different ways:
  * Connect to the running container and run commands from within it:
    ```shell
    docker exec -it yfpy-package-1 bash
    ```
    Then:
    ```shell
    python quickstart/quickstart.py
    ```
  * Send commands to the running container from your host machine:
    ```shell
    docker exec -i yfpy-package-1 bash -c "python quickstart/quickstart.py"
    ```

<a name="docker-development"></a>
##### Docker Development

* Run the Docker container for local development (mount all local code into container):
    ```shell
    docker compose -f compose.yaml -f compose.dev.yaml up
    ```

<a name="docker-image-deployment"></a>
##### Docker Image Deployment

See [DEPLOYMENT.md](https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md) for Docker image deployment.

---

<a name="testing"></a>
### Testing

YFPY has a collection of fully functional code snippets that can be run using [pytest](https://docs.pytest.org/en/6.2.x/). These snippets demonstrate how to use YFPY to retrieve your Yahoo Fantasy Sports data.

<a name="unit-tests"></a>
#### Unit Tests

* See the [`test/unit`](https://github.com/uberfastman/yfpy/blob/main/test/unit/) directory for example code snippets using pytest.

<a name="integration-tests"></a>
#### Integration Tests

* See the [`test/integration`](https://github.com/uberfastman/yfpy/blob/main/test/integration/) directory for example code snippets using pytest.
* Before running any integration tests, make a copy of [`auth/.env.template`](https://github.com/uberfastman/yfpy/blob/main/auth/.env.template) in the [`auth/`](https://github.com/uberfastman/yfpy/blob/main/auth/) 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.
* If this is the first time running pytest with your Yahoo API credentials, you ***MUST*** allow interactive prompts within pytest by using the `-s` flag.
* The fixture values in [`test/integration/conftest.py`](https://github.com/uberfastman/yfpy/blob/main/test/integration/conftest.py) are defined in [`quickstart/quickstart.py`](https://github.com/uberfastman/yfpy/blob/main/quickstart/quickstart.py), and can be changed for testing by uncommenting/commenting out the values inside each respective function.

<a name="run-tests"></a>
#### Run Tests

* You can invoke all pytest tests (both integration test and unit tests) by running the below from the root directory:
  * `pytest -v -s`
* If you want to run only the unit tests, you can run:
  * `pytest -v -s -m unit`
* If you want to run only the integration tests, you can run:
  * `pytest -v -s -m integration`

---

<a name="dependencies"></a>
### Dependencies

<a name="platform"></a>
#### Platform

YFPY has only been tested extensively on macOS, but is written to be platform-agnostic, and seems to work without issue on Windows and Linux. 

<a name="python"></a>
#### Python

YFPY requires Python 3.10 or later, and has been tested through Python 3.12.

<a name="development"></a>
#### Development

Direct project dependencies can be viewed in `requirements.txt`, and additional development and build dependencies (*not* including transitive dependencies) can be viewed in `requirements-dev.txt`.

---

<a name="troubleshooting"></a>
### Troubleshooting

<a name="yahoo-fantasy-sports-api"></a>
#### Yahoo Fantasy Sports API

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:
```shell
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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/uberfastman/yfpy",
    "name": "yfpy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "yahoo fantasy sports api wrapper nfl football nhl hockey mlb baseball nba basketball",
    "author": "Wren J. R.",
    "author_email": "uberfastman@uberfastman.dev",
    "download_url": "https://files.pythonhosted.org/packages/77/3c/67c151747fdc53e23aeecf109fc9e917811f0f166576a8865835f7337e3e/yfpy-16.0.3.tar.gz",
    "platform": null,
    "description": "[<img src=\"https://raw.githubusercontent.com/uberfastman/yfpy/refs/heads/main/docs/yfpy-logo.svg\" width=\"400\"/>](https://github.com/uberfastman/yfpy)\n\n## YFPY - Yahoo Fantasy Sports API Wrapper\nPython API wrapper for the Yahoo Fantasy Sports public API\n\n*Author: Wren J. R. (uberfastman)*\n\n[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/uberfastman/yfpy?color=yellowgreen&label=latest%20release&sort=semver)](https://github.com/uberfastman/yfpy/releases/latest)\n[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/uberfastman/yfpy?color=yellowgreen&label=latest%20version&sort=semver)](https://github.com/uberfastman/yfpy/tags)\n[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/uberfastman/yfpy/python-package.yml?color=brightgreen&label=build)](https://github.com/uberfastman/yfpy/actions/workflows/python-package.yml)\n\n[![PyPI](https://img.shields.io/pypi/v/yfpy.svg?style=flat)](https://pypi.python.org/pypi/yfpy)\n[![PyPI](https://img.shields.io/pypi/dm/yfpy.svg?style=flat)](https://pypi.python.org/pypi/yfpy)\n[![PyPI](https://img.shields.io/pypi/pyversions/yfpy.svg?style=flat)](https://pypi.python.org/pypi/yfpy)\n[![PyPI](https://img.shields.io/pypi/l/yfpy.svg?style=flat)](https://pypi.python.org/pypi/yfpy)\n\n---\n\n<sub>***Do you like the YFPY API wrapper? Star the repository on GitHub and please consider helping support its ongoing development:***</sub>\n\n[<img src=\"https://github.com/uberfastman/yfpy/raw/main/resources/images/donate-paypal.png\" width=\"75\"/>](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=VZZCNLRHH9BQS) [<img src=\"https://github.com/uberfastman/yfpy/raw/main/resources/images/donate-bitcoin.png\" width=\"75\"/>](https://share.trustwallet.com/ZoAkTpY1I9) [<img src=\"https://github.com/uberfastman/yfpy/raw/main/resources/images/donate-ethereum.png\" width=\"75\"/>](https://share.trustwallet.com/MF8YBO01I9)\n\n|                                                                <sub><sup>Cryptocurrency</sup></sub> |                                                      <sub><sup>Address</sup></sub>                                                       |\n|----------------------------------------------------------------------------------------------------:|:----------------------------------------------------------------------------------------------------------------------------------------:|\n|                                                                 <sub><sup>Bitcoin (BTC)</sup></sub> |                                    <sub><sup>`bc1qataspvklhewtswm357m0677q4raag5new2xt3e`</sup></sub>                                    | \n|                                                                <sub><sup>Ethereum (ETH)</sup></sub> |                                    <sub><sup>`0x5eAa522e66a90577D49e9E72f253EC952CDB4059`</sup></sub>                                    |\n\n<sub><sup></sup></sub>\n\n---\n\n**[READ THE DOCS HERE!](https://yfpy.uberfastman.com)**\n<br/>\n<sup>Detailed documentation on YFPY can be found at [https://yfpy.uberfastman.com](https://yfpy.uberfastman.com).</sup>\n\n### Table of Contents\n* [About](#about)\n* [Installation](#installation)\n    * [Pip](#pip)\n    * [Manual](#manual)\n* [Setup](#setup)\n    * [Yahoo Developer Network App](#yahoo-developer-network-app)\n    * [Environment Variables](#environment-variables)\n* [Usage](#usage)\n    * [Authentication](#authentication)\n        * [Programmatic Persistent Authentication](#programmatic-persistent-authentication)\n        * [Persistent Authentication Using Access Token Fields](#persistent-authentication-using-access-token-fields)\n        * [Persistent Authentication Using Access Token JSON](#persistent-authentication-using-access-token-json)\n    * [Querying the Yahoo Fantasy Sports API](#querying-the-yahoo-fantasy-sports-api)\n    * [Docker](#docker)\n        * [Docker Development](#docker-development)\n        * [Docker Image Deployment](#docker-image-deployment)\n* [Testing](#testing)\n    * [Unit Tests](#unit-tests)\n    * [Integration Tests](#integration-tests)\n    * [Run Tests](#run-tests)\n* [Dependencies](#dependencies)\n    * [Platform](#platform)\n    * [Python](#python)\n    * [Development](#development)\n* [Troubleshooting](#troubleshooting)\n    * [Yahoo Fantasy Sports API](#yahoo-fantasy-sports-api)\n\n---\n\n<a name=\"about\"></a>\n### About\n\nYFPY 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). \n\n---\n\n<a name=\"installation\"></a>\n### Installation\n\n<a name=\"pip\"></a>\n#### Pip\n\n* If you wish to use YFPY within another project, from within your project directory, run\n    ```shell\n    pip install yfpy\n    ```\n    \n    or add `yfpy` to your project `requirements.txt`.\n\n<a name=\"manual\"></a>\n#### Manual\n\n* If you wish to download and use YFPY locally, clone the git repository:\n  ```shell\n  git clone git@github.com:uberfastman/yfpy.git\n  ```\n\n---\n\n<a name=\"setup\"></a>\n### Setup\n\n<a name=\"yahoo-developer-network-app\"></a>\n#### Yahoo Developer Network App\n\nIn 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 see [Getting Started](https://developer.yahoo.com/oauth2/guide/openid_connect/getting_started.html) in the Yahoo Developer Network docs for more details.\n\n**Note:** *If you are only planning on using YFPY to pull \"read only\" data from public leagues, you do not need to do this.*\n\n* Log in to a Yahoo account with access to whatever fantasy leagues from which you wish to retrieve data.\n* Go to [https://developer.yahoo.com/apps/create/](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:\n    * `Application Name` (**Required**): `yfpy` (you can name your app whatever you want, but this is just an example).\n    * `Application Type` (**Required**): select the `Installed Application` radio button.\n    * `Description` (*Optional*): you *may* write a short description of what the app does.\n    * `Home Page URL` (*Optional*): if you have a web address related to your app you *may* add it here.\n    * `Redirect URI(s)` (**Required**): this field must contain a valid redirect address, so you can use `https://localhost:8080`\n    * `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).\n    * Click the `Create App` button.\n    * 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`.\n    * Copy the `Client ID` and `Client Secret` and proceed with the steps in [Environment Variables](#environment-variables) or [Programmatic Persistent Authentication](#programmatic-persistent-authentication).\n\n<a name=\"environment-variables\"></a>\n#### Environment Variables\n\nYFPY now supports the usage of environment variables, either directly within the command line or using a `.env` file. Any environment variables exported to the same shell in which YFPY runs will automatically be read when a `YahooFantasySportsQuery` object is instantiated when `env_var_fallback=True` (default).\n\n* If you wish to *also* use environment variables stored in a `.env` file, you can set up a `.env` file by making a copy of `.env.template` in the root project directory and renaming it `.env` (you can do this in the command line by running `cp .env.template .env`).\n* Paste the `Client ID` and `Client Secret` retrieved by following the steps in [Yahoo Developer Network App](#yahoo-developer-network-app) into their respective environment variables in your `.env` file:\n```dotenv\nYAHOO_CONSUMER_KEY=<YAHOO_DEVELOPER_APP_CONSUMER_KEY_STRING>\nYAHOO_CONSUMER_SECRET=<YAHOO_DEVELOPER_APP_CONSUMER_SECRET_STRING>\n```\n* YFPY is configured by default to check for environment variables for authentication with Yahoo, so you will now be able to proceed directly to [Authentication](#authentication).\n\n**Note**: *You can disable the fallback to environment variables behavior during instantiation of a YFPY query by passing the argument `env_var_fallback=False` to the object:*\n```python\nfrom yfpy.query import YahooFantasySportsQuery\n\nquery = YahooFantasySportsQuery(\n    league_id=\"<YAHOO_LEAGUE_ID>\",\n    game_code=\"nfl\",\n    game_id=449,\n    yahoo_consumer_key=\"<YAHOO_CONSUMER_KEY>\",\n    yahoo_consumer_secret=\"<YAHOO_CONSUMER_SECRET>\",\n    env_var_fallback=False\n)\n```\n\n---\n\n<a name=\"usage\"></a>\n### Usage\n\n<a name=\"authentication\"></a>\n#### Authentication\n\n* Follow the instructions in the [Installation](#installation) and [Setup](#setup) sections.\n* 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.\n\n**Note**: *If you are running YFPY in Docker, instead of opening a new browser window, YFPY will output a URL to the command line, which you must then copy to a browser window in order to log in to your Yahoo account, allow access to your app, and retrieve the required verification code.*\n\n<a name=\"programmatic-persistent-authentication\"></a>\n##### Programmatic Persistent Authentication\n\nYFPY supports programmatic authentication using `yahoo_consumer_key` and `yahoo_consumer_secret` arguments when instantiating a `YahooFantasySportsQuery` object. Additionally, you can pass in either a valid JSON string or a Python dictionary to `yahoo_access_token_json` containing all required fields of a Yahoo access token.\n\n* Providing `yahoo_consumer_key` and `yahoo_consumer_secret` overrides any values provided in a `.env` file.\n* Providing a value to `yahoo_access_token_json` overrides `yahoo_consumer_key`/`yahoo_consumer_secret` values *and* any values provided in a `.env` file for Yahoo access token individual fields.\n  * Required fields (either in a JSON string with escaped double quotes or a Python dictionary) for the value of `yahoo_access_token_json` are the following:\n    * `access_token`\n    * `consumer_key`\n    * `consumer_secret`\n    * `guid`\n    * `refresh_token`\n    * `token_time`\n    * `token_type`\n  * The `consumer_key` and `consumer_secret` fields in `yahoo_access_token_json` override any values provided in `yahoo_consumer_key`/`yahoo_consumer_secret`.\n\nExample of Using `yahoo_access_token_json`:\n```python\nfrom yfpy.query import YahooFantasySportsQuery\n\nquery = YahooFantasySportsQuery(\n    league_id=\"<YAHOO_LEAGUE_ID>\",\n    game_code=\"nfl\",\n    game_id=449,\n    yahoo_access_token_json={\n        \"access_token\": \"<YAHOO_ACCESS_TOKEN>\",\n        \"consumer_key\": \"<YAHOO_CONSUMER_KEY>\",\n        \"consumer_secret\": \"<YAHOO_CONSUMER_SECRET>\",\n        \"guid\": \"<YAHOO_TOKEN_GUID>\",\n        \"refresh_token\": \"<YAHOO_REFRESH_TOKEN>\",\n        \"token_time\": 1234567890.123456,\n        \"token_type\": \"bearer\"\n    }\n)\n```\n\n<a name=\"persistent-authentication-using-access-token-fields\"></a>\n##### Persistent Authentication Using Access Token Fields\n\n* YFPY no longer uses JSON files to store Yahoo credentials or access tokens. However, if you wish to preserve your access token in order to remain verified, you can now instantiate a YFPY query with `save_token_data_to_env_file=True`, which will write all required Yahoo access token fields an `.env` file located in the provided `env_file_location` directory.\n* 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 `.env` file to authenticate your app.\n\n**Note**: *You **MUST** provide a value for `env_file_location` or else **NO** Yahoo access token data will be saved!*\n\n<a name=\"persistent-authentication-using-access-token-json\"></a>\n##### Persistent Authentication Using Access Token JSON\n\n* YFPY *also* supports the use of a **single** environment variable by providing a valid JSON string in `YAHOO_ACCESS_TOKEN_JSON`. This environment variable is only used if `env_var_fallback=True` (default) when instantiating a YFPY query.\n* You can save the Yahoo access token fields as valid JSON with escaped double quotes (`\"`) by invoking `YahooFantasySportsQuery.save_access_token_data_to_env_file` with `save_json_to_var_only=True` (instead of saving the Yahoo access token fields to individual environment variables as described in [Persistent Authentication Using Access Token Fields](#persistent-authentication-using-access-token-fields)) like below:\n```python\nfrom pathlib import Path\n\nfrom yfpy.query import YahooFantasySportsQuery\n\nquery = YahooFantasySportsQuery(\n    league_id=\"<YAHOO_LEAGUE_ID>\",\n    game_code=\"nfl\",\n    game_id=449,\n    yahoo_consumer_key=\"<YAHOO_CONSUMER_KEY>\",\n    yahoo_consumer_secret=\"<YAHOO_CONSUMER_SECRET>\",\n    env_file_location=Path(\".env\")\n)\n\nquery.save_access_token_data_to_env_file(\n    env_file_location=Path(\".env\"), \n    save_json_to_var_only=True\n)\n```\n\n<a name=\"querying-the-yahoo-fantasy-sports-api\"></a>\n#### Querying the Yahoo Fantasy Sports API\n\n* See the documentation on the  [`yfpy.query.YahooFantasySportsQuery`](https://yfpy.uberfastman.com/_autosummary/yfpy.query.YahooFantasySportsQuery.html#yfpy.query.YahooFantasySportsQuery) class for example usage of all available queries.\n* See [`quickstart/quickstart.py`](https://github.com/uberfastman/yfpy/blob/main/quickstart/quickstart.py) for example usage output.\n  * Uncomment/comment out whichever configuration values in their respective functions with which you wish to experiment.\n  * Uncomment/comment out whichever query lines in the `RUN QUERIES` section you wish to run.\n  * Uncomment/comment out whichever query lines in the `CHECK FOR MISSING DATA FIELDS` section you wish to check for any new/missing data fields returned by the Yahoo Sports Fantasy Football API.\n\n<a name=\"docker\"></a>\n#### Docker\n\nYFPY can be used within Docker for a more seamless, platform-agnostic experience.\n\n* Run the Docker container (pulls the YFPY Docker image from GitHub Package Registry):\n    ```shell\n    docker compose up\n    ``` \n* You can then run commands in the Docker container in two different ways:\n  * Connect to the running container and run commands from within it:\n    ```shell\n    docker exec -it yfpy-package-1 bash\n    ```\n    Then:\n    ```shell\n    python quickstart/quickstart.py\n    ```\n  * Send commands to the running container from your host machine:\n    ```shell\n    docker exec -i yfpy-package-1 bash -c \"python quickstart/quickstart.py\"\n    ```\n\n<a name=\"docker-development\"></a>\n##### Docker Development\n\n* Run the Docker container for local development (mount all local code into container):\n    ```shell\n    docker compose -f compose.yaml -f compose.dev.yaml up\n    ```\n\n<a name=\"docker-image-deployment\"></a>\n##### Docker Image Deployment\n\nSee [DEPLOYMENT.md](https://github.com/uberfastman/yfpy/blob/main/DEPLOYMENT.md) for Docker image deployment.\n\n---\n\n<a name=\"testing\"></a>\n### Testing\n\nYFPY has a collection of fully functional code snippets that can be run using [pytest](https://docs.pytest.org/en/6.2.x/). These snippets demonstrate how to use YFPY to retrieve your Yahoo Fantasy Sports data.\n\n<a name=\"unit-tests\"></a>\n#### Unit Tests\n\n* See the [`test/unit`](https://github.com/uberfastman/yfpy/blob/main/test/unit/) directory for example code snippets using pytest.\n\n<a name=\"integration-tests\"></a>\n#### Integration Tests\n\n* See the [`test/integration`](https://github.com/uberfastman/yfpy/blob/main/test/integration/) directory for example code snippets using pytest.\n* Before running any integration tests, make a copy of [`auth/.env.template`](https://github.com/uberfastman/yfpy/blob/main/auth/.env.template) in the [`auth/`](https://github.com/uberfastman/yfpy/blob/main/auth/) directory and rename it to `.env`.\n* 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.\n* If this is the first time running pytest with your Yahoo API credentials, you ***MUST*** allow interactive prompts within pytest by using the `-s` flag.\n* The fixture values in [`test/integration/conftest.py`](https://github.com/uberfastman/yfpy/blob/main/test/integration/conftest.py) are defined in [`quickstart/quickstart.py`](https://github.com/uberfastman/yfpy/blob/main/quickstart/quickstart.py), and can be changed for testing by uncommenting/commenting out the values inside each respective function.\n\n<a name=\"run-tests\"></a>\n#### Run Tests\n\n* You can invoke all pytest tests (both integration test and unit tests) by running the below from the root directory:\n  * `pytest -v -s`\n* If you want to run only the unit tests, you can run:\n  * `pytest -v -s -m unit`\n* If you want to run only the integration tests, you can run:\n  * `pytest -v -s -m integration`\n\n---\n\n<a name=\"dependencies\"></a>\n### Dependencies\n\n<a name=\"platform\"></a>\n#### Platform\n\nYFPY has only been tested extensively on macOS, but is written to be platform-agnostic, and seems to work without issue on Windows and Linux. \n\n<a name=\"python\"></a>\n#### Python\n\nYFPY requires Python 3.10 or later, and has been tested through Python 3.12.\n\n<a name=\"development\"></a>\n#### Development\n\nDirect project dependencies can be viewed in `requirements.txt`, and additional development and build dependencies (*not* including transitive dependencies) can be viewed in `requirements-dev.txt`.\n\n---\n\n<a name=\"troubleshooting\"></a>\n### Troubleshooting\n\n<a name=\"yahoo-fantasy-sports-api\"></a>\n#### Yahoo Fantasy Sports API\n\nOccasionally 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:\n```shell\nTraceback (most recent call last):\n  File \"yfpy-app.py\", line 114, in <module>\n    var = app.run()\n  File \"/Users/your_username/PATH/T0/LOCAL/PROJECT/yfpy-app.py\", line 429, in run\n    for team in team_standings:\nIndexError: list index out of range\n```\n\nTypically, 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.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python API wrapper for the Yahoo Fantasy Sports public API.",
    "version": "16.0.3",
    "project_urls": {
        "Download": "https://github.com/uberfastman/yfpy/archive/v16.0.3.tar.gz",
        "Homepage": "https://github.com/uberfastman/yfpy"
    },
    "split_keywords": [
        "yahoo",
        "fantasy",
        "sports",
        "api",
        "wrapper",
        "nfl",
        "football",
        "nhl",
        "hockey",
        "mlb",
        "baseball",
        "nba",
        "basketball"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ad2f651cf3c6b5ec9a06b38f4d1c01cf4a8025f0acaab3cdeb15f3e80119a1a6",
                "md5": "c3bb1347941d646ac0fcd3c651b993f1",
                "sha256": "2d9557f295c2eb033e8e2f908dcd1be6c939e1d33d5efa7405c099dfb8044238"
            },
            "downloads": -1,
            "filename": "yfpy-16.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c3bb1347941d646ac0fcd3c651b993f1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 68162,
            "upload_time": "2024-09-23T01:56:04",
            "upload_time_iso_8601": "2024-09-23T01:56:04.876781Z",
            "url": "https://files.pythonhosted.org/packages/ad/2f/651cf3c6b5ec9a06b38f4d1c01cf4a8025f0acaab3cdeb15f3e80119a1a6/yfpy-16.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "773c67c151747fdc53e23aeecf109fc9e917811f0f166576a8865835f7337e3e",
                "md5": "d16fc15206b973e4fc84196d151cbd59",
                "sha256": "957fa46c175edb58653397f465a1f43c811b3faa5b3f986549d3cce551ed43bb"
            },
            "downloads": -1,
            "filename": "yfpy-16.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "d16fc15206b973e4fc84196d151cbd59",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 72992,
            "upload_time": "2024-09-23T01:56:06",
            "upload_time_iso_8601": "2024-09-23T01:56:06.672461Z",
            "url": "https://files.pythonhosted.org/packages/77/3c/67c151747fdc53e23aeecf109fc9e917811f0f166576a8865835f7337e3e/yfpy-16.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-23 01:56:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "uberfastman",
    "github_project": "yfpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "bandit",
            "specs": [
                [
                    "==",
                    "1.7.9"
                ]
            ]
        },
        {
            "name": "coverage",
            "specs": [
                [
                    "==",
                    "7.6.1"
                ]
            ]
        },
        {
            "name": "flake8",
            "specs": [
                [
                    "==",
                    "7.1.1"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    "==",
                    "8.3.3"
                ]
            ]
        },
        {
            "name": "python-dotenv",
            "specs": [
                [
                    "==",
                    "1.0.1"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.32.3"
                ]
            ]
        },
        {
            "name": "ruamel.yaml",
            "specs": [
                [
                    "==",
                    "0.18.6"
                ]
            ]
        },
        {
            "name": "stringcase",
            "specs": [
                [
                    "==",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "yahoo-oauth",
            "specs": [
                [
                    "==",
                    "2.1.0"
                ]
            ]
        }
    ],
    "lcname": "yfpy"
}
        
Elapsed time: 0.30520s