Skip to main content

Python bindings to access the Yahoo! Fantasy APIs

Project description

Python bindings to the Yahoo! Fantasy API

Build status

https://travis-ci.com/spilchen/yahoo_fantasy_api.svg?branch=master Documentation Status

Installation

This package can be installed via pip:

pip install yahoo_fantasy_api

or from the repo:

git clone https://github.com/spilchen/yahoo_fantasy_api
cd yahoo_fantasy_api
python setup.py install

Documentation

The documentation are hosted at readthedocs.io: https://yahoo-fantasy-api.readthedocs.io/en/latest/

Sample API Usage

In [1]: from yahoo_oauth import OAuth2

In [2]: import yahoo_fantasy_api as yfa

In [3]: sc = OAuth2(None, None, from_file='examples/oauth2.json')
[2019-04-04 20:55:46,745 DEBUG] [yahoo_oauth.yahoo_oauth.__init__] Checking
[2019-04-04 20:55:46,746 DEBUG] [yahoo_oauth.yahoo_oauth.token_is_valid] ELAPSED TIME : 416.15308594703674
[2019-04-04 20:55:46,746 DEBUG] [yahoo_oauth.yahoo_oauth.token_is_valid] TOKEN IS STILL VALID

In [4]: gm = yfa.Game(sc, 'mlb')

In [5]: gm.league_ids(year=2019)
Out[5]: ['388.l.27081']

In [6]: lg = gm.to_league('388.l.27081')

In [7]: lg.stat_categories()
Out[7]:
[{'display_name': 'R', 'position_type': 'B'},
 {'display_name': 'HR', 'position_type': 'B'},
 {'display_name': 'RBI', 'position_type': 'B'},
 {'display_name': 'SB', 'position_type': 'B'},
 {'display_name': 'AVG', 'position_type': 'B'},
 {'display_name': 'OBP', 'position_type': 'B'},
 {'display_name': 'W', 'position_type': 'P'},
 {'display_name': 'K', 'position_type': 'P'},
 {'display_name': 'HLD', 'position_type': 'P'},
 {'display_name': 'ERA', 'position_type': 'P'},
 {'display_name': 'WHIP', 'position_type': 'P'},
 {'display_name': 'NSV', 'position_type': 'P'}]

In [8]: lg.team_key()
Out[8]: '388.l.27081.t.5'

In [9]: lg.current_week()
Out[9]: 12

In [10]: lg.end_week()
Out[10]: 24

In [11]: lg.week_date_range(12)
Out[11]: (datetime.date(2019, 6, 17), datetime.date(2019, 6, 23))

In [12]: tm = lg.to_team('388.l.27081.t.5')

In [13]: tm.roster(1)
Out[13]:
[{'player_id': 8578,
  'name': 'Buster Posey',
  'position_type': 'B',
  'eligible_positions': ['C', '1B', 'Util'],
  'selected_position': 'C'},
 {'player_id': 8967,
  'name': 'Paul Goldschmidt',
  'position_type': 'B',
  'eligible_positions': ['1B', 'Util'],
  'selected_position': '1B'},
 {'player_id': 9961,
  'name': 'Travis Shaw',
  'position_type': 'B',
  'eligible_positions': ['1B', '2B', '3B', 'Util'],
  'selected_position': '2B'},
 {'player_id': 9105,
  'name': 'Nolan Arenado',
  'position_type': 'B',
  'eligible_positions': ['3B', 'Util'],
  'selected_position': '3B'},
 {'player_id': 9468,
  'name': 'Jonathan Villar',
  'position_type': 'B',
  'eligible_positions': ['2B', 'SS', 'Util'],
  'selected_position': 'SS'},
 ...
 {'player_id': 7847,
  'name': 'Andrew Miller',
  'position_type': 'P',
  'eligible_positions': ['RP'],
  'selected_position': 'RP'}]

In [14]: fa_CF = lg.free_agents('CF')

In [15]: len(fa_CF)
Out[15]: 60

In [11]: fa_CF[0]
Out[11]:
{'player_id': 8370,
 'name': 'Dexter Fowler',
 'position_type': 'B',
 'eligible_positions': ['CF', 'RF', 'Util']}

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

yahoo_fantasy_api-2.5.0-py3.8.egg (49.8 kB view details)

Uploaded Egg

File details

Details for the file yahoo_fantasy_api-2.5.0-py3.8.egg.

File metadata

  • Download URL: yahoo_fantasy_api-2.5.0-py3.8.egg
  • Upload date:
  • Size: 49.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for yahoo_fantasy_api-2.5.0-py3.8.egg
Algorithm Hash digest
SHA256 4c2a7c19ee57404a0d0d6bc371b4f8181f31e8b09598a36c71886dae0047de92
MD5 6fd5f971dda91ac2ea412615735e0259
BLAKE2b-256 7fe995f99515a80cd27ee3f91fc3c22a69ddc585c13939f0f78179fa8ea2fdfb

See more details on using hashes here.

Supported by

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