Skip to main content

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

Release files for yfantasy-api 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yfantasy-api 0.0.6
File Size Uploaded
yfantasy-api-0.0.6.tar.gz 17.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yfantasy-api 0.0.6
File Interpreter ABI Platform
yfantasy_api-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 42.2 kB

Release files / yfantasy-api-0.0.6.tar.gz

Download URL yfantasy-api-0.0.6.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a3f8bcfc88e58a303874b67045e39fe932b5f57c1342c5b2712913ff881ff99f
BLAKE2b-256 checksum
How to use checksums
f240ac85ea8279b5c8a58642c013f1de256bd73281b47f5daf8fa2820dcfbfd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release files / yfantasy_api-0.0.6-py3-none-any.whl

Download URL yfantasy_api-0.0.6-py3-none-any.whl
Size 24.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6cae3faff1869ddb71ea2d08e232311d998a49900d63bd69a835535796195b24
BLAKE2b-256 checksum
How to use checksums
a209d4b3146c7d4e42db27cb3d34fcbb19cb7d32fcb8a52a29f3e67c2d5077f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page