psnawp_api package#

Subpackages#

Submodules#

psnawp_api.psnawp module#

class PSNAWP(npsso_cookie: str, *, accept_language: str = 'en-US', country: str = 'US')[source]#

Bases: object

PlayStation Network API Wrapper Python (PSNAWP) Retrieve User Information, Trophies, Game and Store data from the PlayStation Network.

Instances of this class are the gateway to interacting with PSN API through PSNAWP.

from psnawp_api import PSNAWP
psnawp = PSNAWP('<64 character npsso code>')
__init__(npsso_cookie: str, *, accept_language: str = 'en-US', country: str = 'US')[source]#

Constructor Method. Takes the npsso_cookie and creates instance of request_builder.RequestBuilder which is used later in code for HTTPS requests.

Parameters:
  • npsso_cookie (str) – npsso cookie obtained from PSN website.

  • accept_language (str) – The preferred language(s) for content negotiation in HTTP headers.

  • country (str) – The client’s country for HTTP headers.

Raises:

PSNAWPAuthenticationError If npsso code is expired or is incorrect.

me() Client[source]#

Creates a new client object (your account).

Returns:

Client Object

Return type:

Client

from psnawp_api import PSNAWP
psnawp = PSNAWP('<64 character npsso code>')
client = psnawp.me()
user(*, online_id: str) User[source]#
user(*, account_id: str) User

Creates a new user object using Online ID (GamerTag) or Account ID (PSN ID).

Note

The account_id takes higher precedence than online_id. If both arguments are passed, online_id will be ignored.

Parameters:

kwargs (dict) – online_id (str): Online ID (GamerTag) of the user. account_id (str): Account ID of the user.

Returns:

User Object

Return type:

User

Raises:

PSNAWPIllegalArgumentError If None of the kwargs are passed.

Raises:

PSNAWPNotFound If the online_id or account_id is not valid/found.

user1 = psnawp.user(online_id="VaultTec_Trading")
user2 = psnawp.user(account_id='1802043923080044300')
game_title(title_id: str, account_id: str = '6515971742264256071', np_communication_id: str | None = None) GameTitle[source]#

Creates a GameTitle class object from title_id which represents a PlayStation video game title.

Note

The GameTitle class is only useful if the user has played that video game. To allow users to retrieve information without having to play that video game I picked a default user who has played the most number of games based on this website (https://www.truetrophies.com/leaderboard/gamer/gamesplayed). It is possible that the there are games this user has not played and in that case it is better to provide your own account id ('me') or someone who has played that game.

Note

During the construction of the object, an additional call is made to get the np_communication_id. This ID is important for getting trophy data. This call can be skipped by providing np_communication_id in as argument.

Parameters:
  • title_id (str) – unique ID of game title.

  • np_communication_id (Optional[str]) – Unique ID of a game title used to request trophy information.

Param:

account_id: The account whose trophy list is being accessed

Returns:

Title Object

Return type:

GameTitle

Raises:

PSNAWPNotFound If the user does not have any trophies for that game or the game doesn’t exist.

group(*, group_id: str) Group[source]#
group(*, users_list: Iterator[User]) Group

Creates a group object from a Group ID or from list of users.

Warning

Passing users_list will create a new group each time. If you want to continue from the same group. Use group id obtained from client.get_groups()

Parameters:

kwargs – group_id (str): The Group ID of a group usually retrieved with the get_groups() method. users_list(Iterator[User]): A list of users of the members in the group.

Returns:

Group Object

Return type:

Group

Raises:

PSNAWPIllegalArgumentError If None or Both kwargs are passed.

Raises:

PSNAWPForbidden If you are Dming a user who has blocked you.

search() Search[source]#

Creates a new search object

Returns:

Search Object

Module contents#

class PSNAWP(npsso_cookie: str, *, accept_language: str = 'en-US', country: str = 'US')[source]#

Bases: object

PlayStation Network API Wrapper Python (PSNAWP) Retrieve User Information, Trophies, Game and Store data from the PlayStation Network.

Instances of this class are the gateway to interacting with PSN API through PSNAWP.

from psnawp_api import PSNAWP
psnawp = PSNAWP('<64 character npsso code>')
__init__(npsso_cookie: str, *, accept_language: str = 'en-US', country: str = 'US')[source]#

Constructor Method. Takes the npsso_cookie and creates instance of request_builder.RequestBuilder which is used later in code for HTTPS requests.

Parameters:
  • npsso_cookie (str) – npsso cookie obtained from PSN website.

  • accept_language (str) – The preferred language(s) for content negotiation in HTTP headers.

  • country (str) – The client’s country for HTTP headers.

Raises:

PSNAWPAuthenticationError If npsso code is expired or is incorrect.

me() Client[source]#

Creates a new client object (your account).

Returns:

Client Object

Return type:

Client

from psnawp_api import PSNAWP
psnawp = PSNAWP('<64 character npsso code>')
client = psnawp.me()
user(*, online_id: str) User[source]#
user(*, account_id: str) User

Creates a new user object using Online ID (GamerTag) or Account ID (PSN ID).

Note

The account_id takes higher precedence than online_id. If both arguments are passed, online_id will be ignored.

Parameters:

kwargs (dict) – online_id (str): Online ID (GamerTag) of the user. account_id (str): Account ID of the user.

Returns:

User Object

Return type:

User

Raises:

PSNAWPIllegalArgumentError If None of the kwargs are passed.

Raises:

PSNAWPNotFound If the online_id or account_id is not valid/found.

user1 = psnawp.user(online_id="VaultTec_Trading")
user2 = psnawp.user(account_id='1802043923080044300')
game_title(title_id: str, account_id: str = '6515971742264256071', np_communication_id: str | None = None) GameTitle[source]#

Creates a GameTitle class object from title_id which represents a PlayStation video game title.

Note

The GameTitle class is only useful if the user has played that video game. To allow users to retrieve information without having to play that video game I picked a default user who has played the most number of games based on this website (https://www.truetrophies.com/leaderboard/gamer/gamesplayed). It is possible that the there are games this user has not played and in that case it is better to provide your own account id ('me') or someone who has played that game.

Note

During the construction of the object, an additional call is made to get the np_communication_id. This ID is important for getting trophy data. This call can be skipped by providing np_communication_id in as argument.

Parameters:
  • title_id (str) – unique ID of game title.

  • np_communication_id (Optional[str]) – Unique ID of a game title used to request trophy information.

Param:

account_id: The account whose trophy list is being accessed

Returns:

Title Object

Return type:

GameTitle

Raises:

PSNAWPNotFound If the user does not have any trophies for that game or the game doesn’t exist.

group(*, group_id: str) Group[source]#
group(*, users_list: Iterator[User]) Group

Creates a group object from a Group ID or from list of users.

Warning

Passing users_list will create a new group each time. If you want to continue from the same group. Use group id obtained from client.get_groups()

Parameters:

kwargs – group_id (str): The Group ID of a group usually retrieved with the get_groups() method. users_list(Iterator[User]): A list of users of the members in the group.

Returns:

Group Object

Return type:

Group

Raises:

PSNAWPIllegalArgumentError If None or Both kwargs are passed.

Raises:

PSNAWPForbidden If you are Dming a user who has blocked you.

search() Search[source]#

Creates a new search object

Returns:

Search Object