Skip to main content

Python package to access the Yahoo! Fantasy APIs

Project description

Yahoo Fantasy API

A simply Python client that can be used to make calls to the Yahoo! Fantasy Sports API.

Python package

This library provides a fluent API to build and make calls to the Yahoo! Fantasy Sports API. It was developed specifically for NHL use initially, but should be generic enough to support MLB, NBA, and NFL as well.

Installation

pip install yfantasy_api

Usage examples

Obtain team information, including the roster with player stats for March 31st 2021

# The request url created is: /team/nhl.l.12345.t.1/roster/players/stats;type=date;date=2021-03-31
from yfantasy_api.api import YahooFantasyApi

league_id = 12345  # This should be the id of the league you are querying
game_id = 'nhl'    # This should be the id of the game you are querying
team_id = 1        # This should be the id of the team you are querying

api = YahooFantasyApi(league_id, game_id)
team = api \
    .team(team_id) \
    .roster() \
    .stats(date='2021-03-31') \
    .get()

for player in team.players:
    print(player.full_name, player.points)

# Output:
# Brock Nelson 0.00
# Joel Eriksson Ek 0.05
# Nazem Kadri 4.00
# Alex Ovechkin 0.00
# Jake Guentzel 0.00
# ...truncated for brevity...

Obtain draft_results, including player information for each pick.

# The request url created is: /league/nhl.l.12345/draft_results/players
from yfantasy_api.api import YahooFantasyApi

league_id = 12345  # This should be the id of the league you are querying
game_id = 'nhl'    # This should be the id of the game you are querying
team_id = 1        # This should be the id of the team you are querying

api = YahooFantasyApi(league_id, game_id)
league = api \
    .league() \
    .draft_results() \
    .players() \
    .get()

for draft_result in league.draft_results:
    print(f'{draft_result.round} - {draft_result.pick} - {draft_result.player.full_name}')

# Output:
# 1 - 1 - Connor McDavid
# 1 - 2 - Alex Ovechkin
# 1 - 3 - Patrick Kane
# 1 - 4 - Steven Stamkos
# 1 - 5 - Sidney Crosby
# ...truncated for brevity...

For working examples of the above scenarios, see examples.py

Development setup

I suggest you use some form of virtual environment to avoid clashing dependencies, but that is obviously your call. My suggested virtual environment is virtualenvwrapper.

git clone git@github.com:hkyplyr/yfantasy-api.git
...
cd yfantasy_api
...
pip install -r requirements.txt

Release History

TODO

Meta

Travis Paquette - @hkyplyr - tpaqu15@gmail.com
Distributed under the MIT license. See LICENSE for more information.

How to Contribute

  1. Clone repo and create a new branch: $ git checkout -b short_feature_name.
  2. Make changes and test
  3. Submit a Pull Request

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

yfantasy-api-0.0.3.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

yfantasy_api-0.0.3-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file yfantasy-api-0.0.3.tar.gz.

File metadata

  • Download URL: yfantasy-api-0.0.3.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for yfantasy-api-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ff747b6cd7ceb253f92b2958489e5450aa6c945b2fd2a1c9e9b00faa19949c8d
MD5 87b04a69b02abcb089ed8920c3bf4814
BLAKE2b-256 4f0097a69a5a106ad8cd9cf2ef1d6bd5ab061ab09d61ac1b2ae3b42165179c5b

See more details on using hashes here.

File details

Details for the file yfantasy_api-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: yfantasy_api-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for yfantasy_api-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ba0224af02df83462242ea7491cf4caa7fc9fd88783eba3bfa51e36307867346
MD5 318fa2726cdeb363f88bf7a90d826269
BLAKE2b-256 fe7ef64a18f9544ee8329ff3ac988c0edc5df04d62de5d7c7041185b62b2b806

See more details on using hashes here.

Supported by

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