A Python wrapper for the Sleeper Fantasy Football API.
This repo is no longer actively maintained. @dtsong has created a new repo that will contain new updates for this project, please check it out: https://github.com/dtsong/sleeper-api-wrapper
A Python API wrapper for Sleeper Fantasy Football, as well as tools to simplify data recieved. It makes all endpoints found in the sleeper api docs: https://docs.sleeper.app/ available and turns the JSON response recieved into python types for easy usage.
pip install sleeper-api-wrapper
There are five objects that get data from the Sleeper API specified below. Most of them are intuitive based on the Sleeper Api docs.
from sleeper_wrapper import League
league = League(league_id)
Gets data for the league that was specified when the League object was initialized. Data returned looks like: https://docs.sleeper.app/#get-a-specific-league
Gets all of the rosters in the league. Data returned looks like: https://docs.sleeper.app/#getting-rosters-in-a-league
Gets all of the users in the league. Data returned looks like: https://docs.sleeper.app/#getting-users-in-a-league
Gets all of the users in the league. Data returned looks like: https://docs.sleeper.app/#getting-matchups-in-a-league
Gets the playoff winners bracket for the league. Data returned looks like: https://docs.sleeper.app/#getting-the-playoff-bracket
Gets the playoff losers bracket for the league. Data returned looks like: https://docs.sleeper.app/#getting-the-playoff-bracket
Gets all of the transactions data in the league. Data returned looks like: https://docs.sleeper.app/#get-transactions
Gets all of the traded picks in the league. Data returned looks like: https://docs.sleeper.app/#get-traded-picks
Gets all of the draft data in the league. Data returned looks like: https://docs.sleeper.app/#get-all-drafts-for-a-league
Gets the standings in a league. Returns a list of the standings in order of most wins to least wins.
Data returned looks like:
[(username, number_of_wins, number_of_losses, total_points), (username, number_of_wins, number_of_losses, total_points),...]
Example usage:
league = League(league_id)
rosters = league.get_rosters()
users = league.get_users()
standings = league.get_standings(rosters,users)
Gets the scoreboards of the league. Returns a dict of league mathups and scores.
Data returned looks like:
{matchup_id:[(team_name,score), (team_name, score)], matchup_id:[(team_name,score), (team_name, score)], ... }
Example usage:
league = League(league_id)
matchups = league.get_matchups(11)
users = league.get_users()
rosters = league.get_rosters()
scoreboards = league.get_scoreboards(rosters, matchups, users)
Gets all of the close games in a league. Returns a dict.
Data returned looks like:
{matchup_id:[(team_name,score), (team_name, score)], matchup_id:[(team_name,score), (team_name, score)], ... }
Example usage:
league = League(league_id)
matchups = league.get_matchups(11)
users = league.get_users()
rosters = league.get_rosters()
scoreboards = league.get_scoreboards(rosters, matchups, users)
close_games = league.get_close_games(scoreboards, 10)
from sleeper_wrapper import User
user = User(user_id)
Gets data for the user that was specified by the user_id or username when the User object was initialized. Data returned looks like: https://docs.sleeper.app/#user
Gets the data of all of the leagues that a user belongs to. Data returned looks like: https://docs.sleeper.app/#get-all-leagues-for-user
Gets the data of all of the drafts of a user in the specified season. Data returned looks like: https://docs.sleeper.app/#get-all-drafts-for-user
Returns the username of the User. This can be useful if the User was initialized with a user_id.
Returns the user_id of the User. This can be useful if the User was initialized with a username.
from sleeper_wrapper import Stats
stats = Stats()
Gets all of the stats in a season. Data returned looks like: https://docs.sleeper.app/#stats-and-projections
Gets all of the stats for a specific week in a season. Data returned looks like: https://docs.sleeper.app/#stats-and-projections
Gets all of the projections in a season. Data returned looks like: https://docs.sleeper.app/#stats-and-projections
Gets all of the projections for a specific week in a season. Data returned looks like: https://docs.sleeper.app/#stats-and-projections
Gets the player score of a specified week.
Data returned looks like:
{'pts_ppr':score_float, 'pts_std': score_float, 'pts_half_ppr': score_float}
Example usage:
stats = Stats()
week_stats = stats.get_week_stats("regular",2018, 5)
score = stats.get_player_week_score(week_stats, "DET")
from sleeper_wrapper import Players
players = Players()
Gets all of the players in fantasy football. Data returned looks like: https://docs.sleeper.app/#fetch-all-players
Gets all of the players in fantasy football. Data returned looks like: https://docs.sleeper.app/#trending-players
This package is intended to be used by Python version 3.5 and higher. There might be some wacky results for previous versions.
This project is licensed under the terms of the MIT license.