yfpy.data.Data

class Data(data_dir, save_data=False, dev_offline=False)[source]

Bases: object

YFPY Data object for Yahoo Fantasy Sports data retrieval, saving, and loading data as JSON.

Instantiate data object to retrieve, save, and load Yahoo Fantasy Sports data.

Parameters
  • data_dir (Path | str) – Directory path where data will be saved/loaded.

  • save_data (bool, optional) – Boolean determining whether data is saved after retrieval from the Yahoo FF API.

  • dev_offline (bool, optional) – Boolean for offline development (requires a prior online run with save_data = True).

Methods

get

Run query to retrieve Yahoo Fantasy Sports data.

load

Load Yahoo Fantasy Sports data already stored locally.

retrieve

Fetch data from the web or load it locally (combination of the save and load methods).

save

Retrieve and save Yahoo Fantasy Sports data locally.

update_data_dir

Modify the data storage directory if it needs to be updated.

Attributes

YFO

alias of TypeVar('YFO', bound=yfpy.models.YahooFantasyObject)

static get(yf_query, params=None)[source]

Run query to retrieve Yahoo Fantasy Sports data.

Parameters
  • yf_query (Callable of YahooFantasySportsQuery) – Chosen yfpy query method to run.

  • str (params (dict of) – str, optional): Dictionary of parameters to be passed to chosen yfpy query function.

Returns

Data retrieved by the yfpy query.

Return type

object

load(file_name, data_type_class=None, new_data_dir=None)[source]

Load Yahoo Fantasy Sports data already stored locally.

Note

This method will fail if the save method has not been called previously.

Parameters
  • file_name (str) – Name of file from which data will be loaded.

  • data_type_class (Type[YahooFantasyObject], optional) – YFPY models.py class for data casting.

  • new_data_dir (str | Path, optional) – Full path to new desired directory from which data will be loaded.

Returns

Data loaded from the selected JSON file.

Return type

object

retrieve(file_name, yf_query, params=None, data_type_class=None, new_data_dir=None)[source]

Fetch data from the web or load it locally (combination of the save and load methods).

Parameters
  • file_name (str) – Name of file to/from which data will be saved/loaded.

  • yf_query (Callable of YahooFantasySportsQuery) – Chosen yfpy query method to run.

  • str (params (dict of) – str, optional): Dictionary of parameters to be passed to chosen yfpy query function.

  • data_type_class (Type[YahooFantasyObject], optional) – YFPY models.py class for data casting.

  • new_data_dir (str | Path, optional) – Full path to new desired directory to/from which data will be saved/loaded.

Returns

Data retrieved by the yfpy query OR loaded from the selected JSON file.

Return type

object

save(file_name, yf_query, params=None, new_data_dir=None)[source]

Retrieve and save Yahoo Fantasy Sports data locally.

Parameters
  • file_name (str) – Name of file to which data will be saved.

  • yf_query (Callable of YahooFantasySportsQuery) – Chosen yfpy query method to run.

  • str (params (dict of) – str, optional): Dictionary of parameters to be passed to chosen yfpy query function.

  • new_data_dir (str | Path, optional) – Full path to new desired directory to which data will be saved.

Returns

Data retrieved by the yfpy query.

Return type

object

update_data_dir(new_save_dir)[source]

Modify the data storage directory if it needs to be updated.

Parameters

new_save_dir (str | Path) – Full path to new desired directory where data will be saved/loaded.

Return type

None

Returns

None