Package: chesscomwrapper
chesscomwrapperThis is a wrapper for the chess.com API.It is a work in progress and is not complete.The purpose of this package is to provide a simple way to access the chess.com API. It is not meant to be a complete wrapper for the API, but rather a simple way to access the data you need.The API is documented here:https://www.chess.com/news/view/published-data-apiand it is the source of the data used in this package.With the public API you can access the following data:PlayerProfile ( avatar, player_id, id, url, name, username, followers, country, location, last_online, joined, status, is_streamer, verified, league )Stats ( chess_daily, chess960_daily, chess_rapid, chess_bullet, chess_blitz, fide, tactics, puzzle_rush, puzzle_rush_daily )Games ( url, pgn, time_control, rated, fen, start_time, time_class, rules, white, black, end_time, accuracies, tcn, uuid, initial_setup )Clubs ( name, joined )Tournaments ( finished, inProgress, registered )ClubProfile ( idUrl, name, club_id, country, average_daily_rating, members_count, created, last_activity, admin, visibility, join_request, icon, description, url )Members ( player, joined )Country( profile, players, clubs )Daily PuzzleRandom PuzzleStreamers Info( username, avatar, twitch_url, url, is_live, is_community_streamer )Leaderboards( daily, daily960, live_rapid, live_blitz, live_bullet, live_bughouse, live_blitz960, live_threecheck, live_crazyhouse, live_kingofthehill, tactics, rush, battle )TournamentTournament RoundTournament Round GroupTeam Match(board_scores, games)Titled PlayersInstallationTo install this package, run the following command in your terminal:pip install chesscomwrapperUsageTo use this package, import it into your project and create a new instance of the ChesscomWrapper class. You can then use the methods to access the data you need.PlayerThis instance of the Player class will contain the data for the player you requested.
####### ExamplechesscomWrapper = ChesscomWrapper()
player = chesscomWrapper.getPlayer("nicolapanozzo")

print(player.stats.tactics.highest.rating)

print(player.games[0].pgn)ClubThis instance of the Club class will contain the data for the club you requested.ExamplechesscomWrapper = ChesscomWrapper()
club = chess_instance.getClub("bonobo")
       
print(club.profile.name)
print(club.profile.average_daily_rating)CountryThis instance of the Country class will contain the data for the country you requested.
####### ExamplechesscomWrapper = ChesscomWrapper()
country = chess_instance.getCountry("IT")

print(country.players[0].name)
print(country.clubs[0].name)DailyPuzzleThis instance of the DailyPuzzle class will contain the data for the puzzle of the current day.ExamplechesscomWrapper = ChesscomWrapper()
dailyPuzzle = chesscomWrapper.getDailyPuzzle()

print(dailyPuzzle.fen)
print(dailyPuzzle.title)
print(dailyPuzzle.image)RandomPuzzleThis instance of the RandomPuzzle class will contain the data for a random puzzle.ExamplechesscomWrapper = ChesscomWrapper()
randomPuzzle = chesscomWrapper.getRandomPuzzle()

print(randomPuzzle.title)StreamersInfoThis instance of the StreamersInfo class will contain the data for the streamers.ExamplechesscomWrapper = ChesscomWrapper()
streamersInfo = chesscomWrapper.getStreamersInfo()

print(streamersInfo[0].username)LeaderboardsThis instance of the Leaderboards class will contain the data for the leaderboards.ExamplechesscomWrapper = ChesscomWrapper()
leaderboards = chesscomWrapper.getLeaderboards()

print(leaderboards.daily[0].username)TournamentThis instance of the Tournament class will contain the data for the tournament you requested.ExamplechesscomWrapper = ChesscomWrapper()
tournament = chesscomWrapper.getTournament("https://api.chess.com/pub/tournament/-33rd-chesscom-quick-knockouts-1401-1600")

print(tournament.name)
print(tournament.info.creator)
print(tournament.info.players)TeamMatchThis instance of the TeamMatch class will contain the data for the team match you requested.ExamplechesscomWrapper = ChesscomWrapper()
teamMatch = chesscomWrapper.getTeamMatch("https://api.chess.com/pub/match/53")

print(team_match.info.teams.team1.name)TitledPlayersThis instance of the TitledPlayers class will contain the data for the titled players.ExamplechesscomWrapper = ChesscomWrapper()
titledPlayers = chesscomWrapper.getTitledPlayers(TitledCategory.GM)

print(titledPlayers[0].name)Advanced UsageThis is a basic UML rapresentation of the package is architectured:Handling requestsThe API doesn't allow you to make parallel requests, so the wrapper will handle the requests for you to avoid missusages.
But if you want to create your own policy, there are few more tricks you can do with this package. You can handle the requests by yourself implementing a RequestHandler, or the error handling by implementing an ErrorHandler. You can also modify the ChesscomHandler to modify the overall behavior of the requests.Laziness behaviorBy default, the wrapper will make a request to the API when you call a property, making them lazy. You can pass also the lazy parameter to false to trigger all the needed calls to retrive any information available as soon as the objest is created. If you want to use always fresh data,  use the getter methods to trigger a new request instead of retrive the cached data (e.g. : player._getInfo() instead of player.info).