pubg-client¶
A python client for the pubg API
Features:
- Versioned API Endpoint and response payloads
- Pagination Support
Danger
This library is in alpha. I will try my utmost to not make backwards incompatible changes but it is possible that they will be necessary.
Installing¶
$ pip install pubg-client
Development¶
$ git clone https://github.com/huntcsg/pubg-client.git $ cd pubg-client $ ./utils/manage clean $ ./utils/manage test $ ./utils/manage docs
- All pull requests must pass the travis-ci builds
- All pull requests should include inline (docstring) documentation, updates to built documentation if applicable, and test coverage. This project aspires to be a 100% test coverage library.
Examples¶
Get Status¶
from pubg_client import Client client = Client(autocall=True) status = client.api.status() print(status) print(status.version) print(status.released_at)
Get Matches¶
Get some matches:
from pubg_client import Client import os client = Client(token=os.environ['PUBG_API_KEY'], autocall=True) matches = client.api.matches()
Get the next matches:
from pubg_client import Client import os client = Client(token=os.environ['PUBG_API_KEY'], autocall=True) matches = client.api.matches() next_matches = matches.next(client)
Add Search Options¶
Do some sorting
from pubg_client import Client import os client = Client(token=os.environ['PUBG_API_KEY'], autocall=False) prepared_request = client.api.matches().sort('createdAt') matches = prepared_request()
Filter the matches (and sort)
from pubg_client import Client import os client = Client(token=os.environ['PUBG_API_KEY'], autocall=False) prepared_request = client.api.matches().sort('createdAt').filter('createdAt', '2018-04-01T00:01:01Z') matches = prepared_request()
Development Guides¶
Adding a New Model¶
Find or create a new python module under src/pubg_client/models/
from ._base import Mapping, Model class NewModel(Model): key_map = { 'key': Mapping('key_in_api', type) }
If needed, define a load, next, and previous method.
If appropriate, register it as the deserializer for an endpoint (or in another models key map)
API¶
pubg_client¶
Pubg Client package docstring
client¶
Client Module
-
class
pubg_client._client.
Client
(base_url='https://api.playbattlegrounds.com', token=None, shard='pc-na', raw=False, autocall=False) The client class
-
api
Returns:
-
current_page
(response) Parameters: response – Returns:
-
get_shard
(shard=None) Parameters: shard – Returns:
-
get_token
(token=None) Parameters: token – Returns:
-
make_request
(request) Parameters: request – Returns:
-
next_page
(response) Parameters: response – Returns:
-
prepare_request
(method, url, gzip=False, **kwargs) Parameters: - method –
- url –
- gzip –
- kwargs –
Returns:
-
previous_page
(response) Parameters: response – Returns:
-
request
(method, url, **kwargs) Parameters: - method –
- url –
- kwargs –
Returns:
-
validate_shard
(shard) Parameters: shard – Returns:
-
-
class
pubg_client._client.
PUBGRequest
(prepared_request, client_or_endpoint) A lazy request object
-
filter
(filter_name, filter_value) Parameters: - filter_name –
- filter_value –
Returns:
-
limit
(limit) Parameters: limit – Returns:
-
offset
(offset) Parameters: offset – Returns:
-
sort
(sort_key) Parameters: sort_key – Returns:
-
api¶
-
class
pubg_client._api.
API
(client, raw=False, autocall=False) The api namespace
-
match
-
matches
Matches Endpoint
-
classmethod
register
(name, deserializer) Parameters: - name –
- deserializer –
Returns:
-
classmethod
register_endpoint
(name, deserializer, endpoint) Parameters: - name –
- deserializer –
- endpoint –
Returns:
-
status
The status endpoint
-
endpoints¶
-
class
pubg_client.endpoints.
Match
(deserializer=None, client=None) -
method
= 'GET'
-
path
= 'matches/{id}'
-
requires_shard
= True
-
url
(id) Parameters: id – Returns:
-
-
class
pubg_client.endpoints.
Matches
(deserializer=None, client=None) Matches Endpoint
-
method
= 'GET'
-
path
= 'matches'
-
requires_shard
= True
-
-
class
pubg_client.endpoints.
Status
(deserializer=None, client=None) The status endpoint
-
method
= 'GET'
-
path
= 'status'
-
models¶
-
class
pubg_client.models.
Match
(**kwargs) A match object
-
key_map
= {'assets': Mapping(pubg_key='assets', cls=<pubg_client.models._base.List object at 0x7fccc9242358>), 'created_at': Mapping(pubg_key='createdAt', cls=<function parse at 0x7fccc6a5a268>), 'duration': Mapping(pubg_key='duration', cls=<class 'int'>), 'game_mode': Mapping(pubg_key='gameMode', cls=<class 'str'>), 'id': Mapping(pubg_key='id', cls=<class 'str'>), 'patch_version': Mapping(pubg_key='patchVersion', cls=<class 'str'>), 'rosters': Mapping(pubg_key='rosters', cls=<class 'pubg_client.models.roster.Roster'>), 'rounds': Mapping(pubg_key='rounds', cls=<class 'dict'>), 'shard_id': Mapping(pubg_key='shardId', cls=<class 'str'>), 'spectators': Mapping(pubg_key='spectators', cls=<class 'dict'>), 'stats': Mapping(pubg_key='stats', cls=<class 'dict'>), 'tags': Mapping(pubg_key='tags', cls=<class 'dict'>), 'title_id': Mapping(pubg_key='titleId', cls=<class 'str'>)}
-
-
class
pubg_client.models.
MatchCollection
(**kwargs) A collection of matches with navigation conveninece methods
-
classmethod
load
(payload) Parameters: payload – Returns:
-
next
()
-
classmethod
-
class
pubg_client.models.
Status
(**kwargs) A status
-
key_map
= {'attributes': Mapping(pubg_key='attributes', cls=StatusAttributes('released_at'=None, 'version'=None)), 'id': Mapping(pubg_key='id', cls=<class 'str'>), 'type': Mapping(pubg_key='type', cls=<class 'str'>)}
-
released_at
Convenience Method
-
version
Convenience Method
-
-
class
pubg_client.models.
StatusAttributes
(**kwargs) A status attributes object. This is so that we can parse the released at string into a Datetime
-
key_map
= {'released_at': Mapping(pubg_key='releasedAt', cls=<function parse at 0x7fccc6a5a268>), 'version': Mapping(pubg_key='version', cls=<class 'str'>)}
-
-
class
pubg_client.models.
Participant
(**kwargs) A participant object
-
key_map
= {'actor': Mapping(pubg_key='actor', cls=<class 'str'>), 'id': Mapping(pubg_key='id', cls=<class 'str'>), 'shard_id': Mapping(pubg_key='shardId', cls=<class 'str'>), 'stats': Mapping(pubg_key='stats', cls=<class 'dict'>)}
-
-
class
pubg_client.models.
Asset
(**kwargs) Asset objects contain a URL string that links to a telemetry.json file, which will contain an array of event objects that provide further insight into a match.
-
key_map
= {'content_type': Mapping(pubg_key='contentType', cls=<class 'str'>), 'createdAt': Mapping(pubg_key='description', cls=<class 'str'>), 'description': Mapping(pubg_key='description', cls=<class 'str'>), 'filename': Mapping(pubg_key='filename', cls=<class 'str'>), 'id': Mapping(pubg_key='id', cls=<class 'str'>), 'name': Mapping(pubg_key='name', cls=<class 'str'>), 'shard_id': Mapping(pubg_key='shardId', cls=<class 'str'>), 'title_id': Mapping(pubg_key='titleId', cls=<class 'str'>), 'url': Mapping(pubg_key='URL', cls=<class 'str'>)}
-
-
class
pubg_client.models.
AssetCollection
(**kwargs) A collection of assets
-
classmethod
load
(payload) Parameters: payload – Returns:
-
classmethod
-
class
pubg_client.models.
Roster
(**kwargs) A roster object
-
key_map
= {'id': Mapping(pubg_key='id', cls=<class 'str'>), 'participants': Mapping(pubg_key='participants', cls=<pubg_client.models._base.List object at 0x7fccc6a74048>), 'shard_id': Mapping(pubg_key='shardId', cls=<class 'str'>), 'stats': Mapping(pubg_key='stats', cls=<class 'dict'>), 'team': Mapping(pubg_key='team', cls=<class 'str'>), 'won': Mapping(pubg_key='won', cls=<class 'str'>)}
-