Package: pubg-python
pubg-pythonA python wrapper for the PUBG Developer APIPUBG Developer API Official DocumentationInstallationTo install the wrapper, simply usepippip install pubg-pythonorpipenvpipenv install pubg-pythonUsageSpecifying a shardThe PUBG API shards data by platform and region, and therefore requires a shard to be specified in the URL for most requests.frompubg_pythonimportPUBG,Shardapi=PUBG('<api-key>',Shard.PC_NA)A list of shards can be foundhereand the wrapper constantshereSamplesSamplesOfficial docsData structureA sample of matches can be retrieved as a starting pointsample=api.samples().get()formatchinsample.matches:print(match.id)Samples can also be filtered by a creation datesample=api.samples().filter(created_at_start='2018-01-01T00:00:00Z').get()formatchinsample.matches:print(match.id)PlayersPlayersOfficial docsData structureRetrieving a single playerplayer=api.players().get('account.3654e255b77b409e87b10dcb086ab00d')formatchinplayer.matches:match_data=api.matches().get(match.id)Retrieving a list of players filtering by namesplayers=api.players().filter(player_names=['Name1','Name2'])forplayerinplayers:player_id=player.idRetrieving a list of players filtering by idsplayers=api.players().filter(player_ids=['account.3654e255b77b409e87b10dcb086ab00d'])forplayerinplayers:player_name=player.nameMatchesMatchesOfficial docsData structureRetrieving a single matchmatch=api.matches().get('276f5bcb-a831-4e8c-a610-d2073692069e')Retrieving a list of matches filtering by idsStill unavailable in the APImatch_ids=['276f5bcb-a831-4e8c-a610-d2073692069e','fasf9082-21de-dkle-13ke-qlamd13nab3a',]matches=api.matches().filter(match_ids=match_ids)formatchinmatches:print(match)TelemetryTelemetry eventsOfficial docsData structureEvent objectsOfficial docsData structureProcessing a match Telemetry datamatch=api.matches().get('276f5bcb-a831-4e8c-a610-d2073692069e')asset=match.assets[0]telemetry=api.telemetry(asset.url)print(len(telemetry.events))>>16871Filtering specific events in a telemetry objectSometimes you're interested in a set of very specific events, so there is a helper function to filter those for you:match=api.matches().get('276f5bcb-a831-4e8c-a610-d2073692069e')asset=match.assets[0]telemetry=api.telemetry(asset.url)player_kill_events=telemetry.events_from_type('LogPlayerKill')player_position_events=telemetry.events_from_type('LogPlayerPosition')Loading a local Telemetry fileIf you want to load a previously downloaded telemetry file, there is a helper
method to create a Telemetry object from it:frompubg_pythonimportTelemetrytelemetry=Telemetry.from_json('telemetry.json',shard='pc')sharddefaults topcbut you need to specify if you're loading axboxtelemetry file.TournamentsTournamentsOfficial docsData structureRetrieving a single tournamenttournament=api.tournaments().get('na-ppc')Retrieving a list of tournamentstournaments=api.tournaments()fortournamentintournaments:print(tournament)SeasonsSeasonsOfficial docsData structureRetrieving the list of seasonsseasons=api.seasons()Retrieving seasons information for a list of playersplayers_seasons=api.seasons(season_id='division.bro.official.2018-09',game_mode='solo').filter(player_ids=['epickitten'])It's also possible to retrieve lifetime stats, instead of a season_id:players_seasons=api.seasons(season_id='lifetime',game_mode='solo').filter(player_ids=['epickitten'])Retrieving season data for a specific playerseason_data=api.seasons('division.bro.official.2018-09',player_id='epickitten').get()It's also possible to retrieve lifetime stats, instead of a season_id:season_data=api.seasons('lifetime',player_id='epickitten').get()Weapon MasteryWeapon MasteryOfficial docsData structureRetrieving a weapon mastery dataplayers=api.players().filter(player_names=['epickitten'])[0]player=players[0]wm=api.weapon_mastery(player.id).get()print(wm.weapon_summaries)LeaderboardsLeaderboardsOfficial docsData structureRetrieving a leaderboard# Leaderboards stats are only available for PC playersapi.shard=Shard.STEAMsolo_leaderboard=api.leaderboards(game_mode='solo').page(0).get()solo_fpp_leaderboard=api.leaderboards(game_mode='solo-fpp').page(0).get()duo_leaderboard=api.leaderboards(game_mode='duo').page(0).get()duo_fpp_leaderboard=api.leaderboards(game_mode='duo-fpp').page(0).get()squad_leaderboard=api.leaderboards(game_mode='squad').page(0).get()squad_fpp_leaderboard=api.leaderboards(game_mode='squad-fpp').page(0).get()pageis always required, even when querying the first leaderboard page.Playing around with dataAn example of how you can manipulate the data:
The domain is all specifiedhereplayers=api.players().filter(player_names=['epickitten'])player=players[0]player.matches>>[<Matchbd6aae34-be05-4094-981c-083285c7e861>,<Match276f5bcb-a831-4e8c-a610-d2073692069e>,..]match=api.matches().get(player.matches[0].id)match.game_mode>>'solo'match.duration>>1899match.rosters>>[<Rosterd542eaee-cd02-4f4e-ad7f-ed5ea71a17cf>,<Rostere9f0962a-ebd4-4d86-b134-95783b713800>,..]roster=match.rosters[0]roster.participants>>[<Participant7cc76d1b-a80e-4997-8eb8-d4b3c1ed4f44>]participant=roster.participans[0]participant.name>>'urdaddyYO'participant.damage_dealt>>291.08participant.kills>>2participant.ride_distance>>3204.53467participant.walk_distance>>2262.81714participant.time_survived>>1367participant.player_id>>account.edb9910f1e9c4f3b9addb87d9329b57cplayer=api.players().get(participant.player_id)player>>account.edb9910f1e9c4f3b9addb87d9329b57cplayer.matches>>[<Matchb3dcd7e8-2270-4fdd-8389-af77acf2d6c2>,<Match2ebb1a9c-ab5e-4264-971f-df77a00918a9>,..]RatelimitsEach application has a limited amount of requests allowed per minute.
The ratelimit is managed through HTTP headers (X-Ratelimit-Limit,X-Ratelimit-Reset, etc..).
In order to facilitate heavy tasks, it is possible to retrieve those values from theRateLimitError. The values available in the exception instance arerl_limit(integer) andrl_reset(datetime).An example snippet that would use this information in favor of processing something big:api=PUBG('my-super-secret-key',Shard.STEAM)whileTrue:try:print('Processing samples...')api.samples().get()exceptRateLimitErroraserror:sleep_seconds=(error.rl_reset-datetime.now()).total_seconds()ifsleep_seconds>0:print('Reached my limit! sleeping for{}'.format(sleep_seconds))time.sleep(sleep_seconds)Limits and OffsetsCurrently disabled from the official APIOffsetting 5 matches and limitting by 10matches=api.matches().limit(10).offset(5)SortingCurrently disabled from the official APIsortdefaults to ascending, you can useascending=Falsefor a descending sortmatches=api.matches().limit(10).sort('createdAt')matches=api.matches().limit(10).sort('createdAt',ascending=False)FilteringSome endpoints allow you to apply filters, for example, filtering players by names:players=api.players().filter(player_names=['Name1','Name2'])Or filtering players by ids:players=api.players().filter(player_ids=['account.3654e255b77b409e87b10dcb086ab00d'])PaginationUsenext()for the next page andprev()for the previous one:matches=api.matches()next_matches=matches.next()previous_matches=matches.prev()ChangelogCHANGELOG.md