psnawp_api.psnawp module#
PlayStation Network API Wrapper Python (PSNAWP) Retrieve User Information, Trophies, Game and Store data from the PlayStation Network.
- class PSNAWP(npsso_cookie: str, headers: RequestBuilderHeaders | None = None, rate_limit: Rate | None = None)[source]#
Bases:
objectThe PSNAWP class provides convenient access to PlayStation’s API.
Instances of this class are the gateway to interacting with PSN API through PSNAWP.
- Variables:
authenticator (Authenticator) – Instance of Authenticator class. Used to make authenticated HTTPs request to playstation server.
Initializes the authentication handler with the provided NPSSO cookie.
- Parameters:
npsso_cookie – The NPSSO cookie obtained from the PlayStation Network website.
Optional HTTP headers to include in all requests. Can be used to modify the API response language by setting
Accept-Languageor specify a region usingCountry. Defaults to:User-Agent: Generic mobile browser user agentAccept-Language:en-US,en;q=0.9(English)Country:US(United States)
rate_limit – Controls the request rate to the PSN API. By default, PSNAWP enforces a default rate limit of one request every three seconds—equivalent to up to 300 requests in a 15-minute window—to comply with PlayStation Network guidelines. Users may override this rate limit by providing a custom
Rateinstance, but doing so can lead to request throttling or temporary bans if set too aggressively.
- Raises:
PSNAWPAuthenticationError – If the NPSSO cookie is expired or invalid.
- __init__(npsso_cookie: str, headers: RequestBuilderHeaders | None = None, rate_limit: Rate | None = None) None[source]#
Initializes the authentication handler with the provided NPSSO cookie.
- Parameters:
npsso_cookie – The NPSSO cookie obtained from the PlayStation Network website.
Optional HTTP headers to include in all requests. Can be used to modify the API response language by setting
Accept-Languageor specify a region usingCountry. Defaults to:User-Agent: Generic mobile browser user agentAccept-Language:en-US,en;q=0.9(English)Country:US(United States)
rate_limit – Controls the request rate to the PSN API. By default, PSNAWP enforces a default rate limit of one request every three seconds—equivalent to up to 300 requests in a 15-minute window—to comply with PlayStation Network guidelines. Users may override this rate limit by providing a custom
Rateinstance, but doing so can lead to request throttling or temporary bans if set too aggressively.
- Raises:
PSNAWPAuthenticationError – If the NPSSO cookie is expired or invalid.
- game_title(title_id: str, platform: PlatformType, 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.
Important
title_idcan be obtained from https://andshrew.github.io/PlayStation-Titles/, https://serialstation.com/trophies/ or fromUniversalSearch.PlayStation3 and PS Vita cannot be searched using
UniversalSearch. Also their np communication id can’t be fetched usingget_np_communication_id(). The user must provide the np communication id for PS3/PS VITA title themselves.Tip
GameTitle lets you fetch trophies for the game you don’t own. If you are trying to fetch your own trophies see the
psnawp_api.models.client.Clientclass. Use theme()to create instance of the Client class.Note
The PlayStation API requires NP Communication ID to fetch trophies for a title. The only way you can get NP Communication ID (
np_communication_id) endpoint is through Trophy Titles endpoint that takes in NP Title ID (title_id) and fetches the corresponding NP Communication ID for it. However, that catch is that the endpoint only returns NP Communication ID if you own that game.To allow users to retrieve information without having to own 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 providingnp_communication_idin as argument.- Parameters:
title_id – unique ID of game title.
platform – The platform this title belongs to.
np_communication_id – 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
- Raises:
PSNAWPNotFoundError – If the user does not have any trophies for that game or the game doesn’t exist.
PSNAWPIllegalArgumentError – If
np_communication_idis not provided for the following platforms: PlatformType.PS3, PlatformType.PS_VITA, PlatformType.PSPC.
- group(*, group_id: str) Group[source]#
- group(*, users_list: Iterable[User]) Group
Creates a group object from a Group ID or from list of users.
Warning
Passing
users_listwill create a new group each time. If you want to continue from the same group. Use group id obtained frompsnawp_api.models.client.Client.get_groups()- Parameters:
group_id – The Group ID of a group usually retrieved with the
get_groups()method.users_list – A list of users of the members in the group.
- Returns:
Group Object
- Raises:
PSNAWPNotFoundError – If group id does not exist or is invalid.
PSNAWPForbiddenError – If you are sending message a user who has blocked you.
- me() Client[source]#
Retrieve a Client instance for the authenticated user.
The returned Client object represents the currently logged-in user and provides methods to perform user-centric operations, including (but not limited to):
Fetching the user’s trophies.
Accepting or rejecting incoming friend requests.
Sending and receiving messages.
And more—see the Client class documentation for the full list of available methods.
- Returns:
A Client object bound to your account, ready to manage the authenticated user’s data and interactions.
from psnawp_api import PSNAWP psnawp = PSNAWP("<64 character npsso code>") client = psnawp.me()
- search(search_query: str, search_domain: Literal[SearchDomain.USERS], limit: int | None = None, offset: int = 0, page_size: int = 20) Generator[UserSearchResultItem, None, None][source]#
- search(search_query: str, search_domain: Literal[SearchDomain.FULL_GAMES], limit: int | None = None, offset: int = 0, page_size: int = 20) Generator[GameSearchResultItem, None, None]
- search(search_query: str, search_domain: Literal[SearchDomain.ADD_ONS], limit: int | None = None, offset: int = 0, page_size: int = 20) Generator[GameSearchResultItem, None, None]
Creates a new search object based on search_domain that can be used to search for games, games-addons, and users.
- Parameters:
search_query – The search query string, used to specify the terms or keywords to search for.
search_domain – Specifies the domain to search within, such as games, add-ons, or users.
limit – Total numbers of items to receive, None means no limit.
page_size – The number of items to receive per api request.
offset – Specifies the offset for paginator.
- Returns:
Search Iterator object to iterate over search results.
- user(*, online_id: str) User[source]#
- user(*, account_id: str) User
Retrieve a User instance by Online ID or Account ID.
The returned User object represents the specified PlayStation Network user and provides methods to inspect and interact with their account, including (but not limited to):
Fetching the user’s trophies and trophy summaries.
Checking friendship status.
Determining whether the user has blocked you.
Retrieving basic profile information (avatar, bio, locale, etc.).
Querying presence data (online/offline status, current activity).
Sending friend requests or messages (subject to privacy settings).
And more—see the User class documentation for the complete list of available methods.
Note
The account_id takes higher precedence than online_id. If both arguments are passed, online_id will be ignored.
- Parameters:
online_id – Online ID (GamerTag) of the user.
account_id – Account ID of the user.
- Returns:
User Object
- Raises:
PSNAWPIllegalArgumentError – If None of the kwargs are passed.
PSNAWPNotFoundError – If the online_id or account_id is not valid/found.
user1 = psnawp.user(online_id="VaultTec_Trading") user2 = psnawp.user(account_id="1802043923080044300")