psnawp_api.models package — PSNAWP 1.1.0 documentation

# psnawp_api.models package

## Subpackages

- psnawp_api.models.trophies package
  - Submodules
  - psnawp_api.models.trophies.trophy module
    - `Trophy`
      - `Trophy.trophy_set_version`
      - `Trophy.has_trophy_groups`
      - `Trophy.total_items_count`
      - `Trophy.trophy_id`
      - `Trophy.trophy_hidden`
      - `Trophy.trophy_type`
      - `Trophy.trophy_name`
      - `Trophy.trophy_detail`
      - `Trophy.trophy_icon_url`
      - `Trophy.trophy_group_id`
      - `Trophy.trophy_progress_target_value`
      - `Trophy.trophy_reward_name`
      - `Trophy.trophy_reward_img_url`
      - `Trophy.earned`
      - `Trophy.progress`
      - `Trophy.__init__()`
      - `Trophy.progress_rate`
      - `Trophy.progressed_date_time`
      - `Trophy.earned_date_time`
      - `Trophy.trophy_rarity`
      - `Trophy.trophy_earn_rate`
      - `Trophy.from_trophy_dict()`
      - `Trophy.from_trophies_list()`
    - `TrophyBuilder`
      - `TrophyBuilder.__init__()`
      - `TrophyBuilder.game_trophies()`
      - `TrophyBuilder.earned_game_trophies()`
      - `TrophyBuilder.earned_game_trophies_with_metadata()`
  - psnawp_api.models.trophies.trophy_constants module
    - `TrophyType`
      - `TrophyType.BRONZE`
      - `TrophyType.SILVER`
      - `TrophyType.GOLD`
      - `TrophyType.PLATINUM`
    - `PlatformType`
      - `PlatformType.UNKNOWN`
      - `PlatformType.PS_VITA`
      - `PlatformType.PS3`
      - `PlatformType.PS4`
      - `PlatformType.PS5`
    - `TrophyRarity`
      - `TrophyRarity.ULTRA_RARE`
      - `TrophyRarity.VERY_RARE`
      - `TrophyRarity.RARE`
      - `TrophyRarity.COMMON`
    - `TrophySet`
      - `TrophySet.bronze`
      - `TrophySet.silver`
      - `TrophySet.gold`
      - `TrophySet.platinum`
      - `TrophySet.__init__()`
  - psnawp_api.models.trophies.trophy_group module
    - `TrophyGroupSummary`
      - `TrophyGroupSummary.trophy_group_id`
      - `TrophyGroupSummary.trophy_group_name`
      - `TrophyGroupSummary.trophy_group_detail`
      - `TrophyGroupSummary.trophy_group_icon_url`
      - `TrophyGroupSummary.defined_trophies`
      - `TrophyGroupSummary.progress`
      - `TrophyGroupSummary.earned_trophies`
      - `TrophyGroupSummary.last_updated_datetime`
      - `TrophyGroupSummary.__init__()`
    - `TrophyGroupsSummary`
      - `TrophyGroupsSummary.trophy_set_version`
      - `TrophyGroupsSummary.trophy_title_name`
      - `TrophyGroupsSummary.trophy_title_detail`
      - `TrophyGroupsSummary.trophy_title_icon_url`
      - `TrophyGroupsSummary.trophy_title_platform`
      - `TrophyGroupsSummary.defined_trophies`
      - `TrophyGroupsSummary.__init__()`
      - `TrophyGroupsSummary.trophy_groups`
      - `TrophyGroupsSummary.hidden_flag`
      - `TrophyGroupsSummary.progress`
      - `TrophyGroupsSummary.earned_trophies`
      - `TrophyGroupsSummary.last_updated_date_time`
    - `TrophyGroupsSummaryBuilder`
      - `TrophyGroupsSummaryBuilder.__init__()`
      - `TrophyGroupsSummaryBuilder.game_title_trophy_groups_summary()`
      - `TrophyGroupsSummaryBuilder.user_trophy_groups_summary()`
      - `TrophyGroupsSummaryBuilder.user_trophy_groups_summary_with_metadata()`
  - psnawp_api.models.trophies.trophy_summary module
    - `TrophySummary`
      - `TrophySummary.account_id`
      - `TrophySummary.trophy_level`
      - `TrophySummary.progress`
      - `TrophySummary.__init__()`
      - `TrophySummary.tier`
      - `TrophySummary.earned_trophies`
      - `TrophySummary.from_endpoint()`
  - psnawp_api.models.trophies.trophy_titles module
    - `TrophyTitle`
      - `TrophyTitle.total_items_count`
      - `TrophyTitle.np_service_name`
      - `TrophyTitle.np_communication_id`
      - `TrophyTitle.trophy_set_version`
      - `TrophyTitle.title_name`
      - `TrophyTitle.title_detail`
      - `TrophyTitle.title_icon_url`
      - `TrophyTitle.title_platform`
      - `TrophyTitle.has_trophy_groups`
      - `TrophyTitle.progress`
      - `TrophyTitle.hidden_flag`
      - `TrophyTitle.__init__()`
      - `TrophyTitle.earned_trophies`
      - `TrophyTitle.defined_trophies`
      - `TrophyTitle.last_updated_date_time`
      - `TrophyTitle.rarest_trophies`
    - `TrophyTitles`
      - `TrophyTitles.__init__()`
      - `TrophyTitles.get_trophy_titles()`
      - `TrophyTitles.get_trophy_summary_for_title()`
      - `TrophyTitles.get_np_communication_id()`
  - psnawp_api.models.trophies.utility_functions module
    - `trophy_type_str_to_enum()`
    - `trophy_rarity_to_enum()`
  - Module contents

## Submodules

## psnawp_api.models.client module

class Client(request_builder: RequestBuilder)

  Bases: `object`

  The Client class provides the information and methods for the currently authenticated user.

  __init__(request_builder: RequestBuilder)

    Initialize a Client instance.

    Note

    This class is intended to be interfaced with through PSNAWP.

    Parameters

      request_builder (RequestBuilder) – The instance of RequestBuilder. Used to make HTTPRequests.

  property online_id: str

    Gets the online ID of the client logged in the api.

    Returns

      onlineID

    Return type

      str

        client = psnawp.me()
        print(client.online_id)

  property account_id: str

    Gets the account ID of the client logged in the api.

    Returns

      accountID

    Return type

      str

        client = psnawp.me()
        print(client.account_id)

  get_profile_legacy() → dict[str, Any]

    Gets the profile info from legacy api endpoint. Useful for legacy console (PS3, PS4) presence.

    Returns

      A dict containing info similar to what is shown below:

    Return type

      dict[str, Any]

          {
            "profile": {
              "onlineId": "VaultTec_Trading",
              "accountId": "8520698476712646544",
              "npId": "VmF1bHRUZWNfVHJhZGluZ0BiNi51cw==",
              "avatarUrls": [
                {
                  "size": "l",
                  "avatarUrl": "[Redacted]"
                }
              ],
              "plus": 0,
              "aboutMe": "r/Fallout76Marketplace Moderator",
              "languagesUsed": [
                "en"
              ],
              "trophySummary": {
                "level": 1,
                "progress": 0,
                "earnedTrophies": {
                  "platinum": 0,
                  "gold": 0,
                  "silver": 0,
                  "bronze": 0
                }
              },
              "isOfficiallyVerified": false,
              "personalDetail": {
                "firstName": "VaultTec",
                "lastName": "TradingCo",
                "profilePictureUrls": [
                  {
                    "size": "xl",
                    "profilePictureUrl": "[Redacted]"
                  }
                ]
              },
              "personalDetailSharing": "no",
              "personalDetailSharingRequestMessageFlag": false,
              "primaryOnlineStatus": "offline",
              "presences": [
                {
                  "onlineStatus": "offline",
                  "hasBroadcastData": false,
                  "lastOnlineDate": "2021-02-05T20:14:45Z"
                }
              ],
              "friendRelation": "no",
              "requestMessageFlag": false,
              "blocking": false,
              "following": false,
              "consoleAvailability": {
                "availabilityStatus": "offline"
              }
            }
          }

        client = psnawp.me()
        print(client.get_profile_legacy())

  get_account_devices() → list[dict[str, Any]]

    Gets the list of devices the client is logged into.

    Returns

      A dict containing info similar to what is shown below:

    Return type

      list[dict[str, Any]]

          [
            {
              "deviceId": "[Redacted]",
              "deviceType": "PS4",
              "activationType": "PSN_GAME_V3",
              "activationDate": "2021-02-05T20:11:27.815Z",
              "accountDeviceVector": "[Redacted]"
            }
          ]

        client = psnawp.me()
        print(client.get_account_devices())

  friends_list(limit: int = 1000) → Iterator[User]

    Gets the friends list and return their account ids.

    Parameters

      limit (int) – The number of items from input max is 1000.

    Returns

      All friends in your friends list.

    Return type

      Iterator[User]

        client = psnawp.me()
        friends_list = client.friends_list()

        for friend in friends_list:
            ...

  available_to_play() → Iterator[User]

    Gets the list of users on your “Notify when available” subscription list.

    Returns

      Iterator of user objects.

    Return type

      Iterator[User]

        client = psnawp.me()
        available_to_play = client.available_to_play()

        for user in available_to_play:
            ...

  blocked_list() → Iterator[User]

    Gets the blocked list and return their account ids.

    Returns

      Al blocked users on your block list.

    Return type

      Iterator[User]

        client = psnawp.me()
        blocked_list = client.blocked_list()

        for blocked_users in blocked_list:
            ...

  get_groups(limit: int = 200, offset: int = 0) → Iterator[Group]

    Gets all the groups you have participated in.

    Parameters

      - limit (int) – The number of groups to receive.

      - offset (int) – Lets you exclude first N items groups. Offset = 10 lets you skip the first 10 groups.

    Returns

      Iterator of Group Objects.

    Return type

      Iterator[Group]

  trophy_summary() → TrophySummary

    Retrieve an overall summary of the number of trophies earned for a user broken down by

    - type

    - overall trophy level

    - progress towards the next level

    - current tier

    Returns

      Trophy Summary Object containing all information

    Return type

      TrophySummary

        client = psnawp.me()
        print(client.trophy_summary())

  trophy_titles(limit: Optional[int] = None) → Iterator[TrophyTitle]

    Retrieve all game titles associated with an account, and a summary of trophies earned from them.

    Parameters

      limit (Optional[int]) – Limit of titles returned, None means to return all trophy titles.

    Returns

      Generator object with TitleTrophySummary objects

    Return type

      Iterator[TrophyTitle]

        client = psnawp.me()
        for trophy_title in client.trophy_titles(limit=None):
            print(trophy_title)

  trophy_titles_for_title(title_ids: list[str]) → Iterator[TrophyTitle]

    Retrieve a summary of the trophies earned by a user for specific titles.

    Note

    `title_id` can be obtained from https://andshrew.github.io/PlayStation-Titles/ or from `psnawp_api.models.search.Search.get_title_id()`

    Parameters

      title_ids (list[str]) – Unique ID of the title

    Returns

      Generator object with TitleTrophySummary objects

    Return type

      Iterator[TrophyTitle]

        client = psnawp.me()
        for trophy_title in client.trophy_titles_for_title(title_id='CUSA00265_00'):
            print(trophy_title)

  trophies(np_communication_id: str, platform: Literal['PS Vita', 'PS3', 'PS4', 'PS5'], trophy_group_id: str = 'default', limit: Optional[int] = None, include_metadata: bool = False) → Iterator[Trophy]

    Retrieves the earned status individual trophy detail of a single - or all - trophy groups for a title.

    Parameters

      - np_communication_id (str) – Unique ID of a game title used to request trophy information. This can be obtained from `GameTitle` class.

      - platform (Literal) – The platform this title belongs to.

      - trophy_group_id (str) – ID for the trophy group. Each game expansion is represented by a separate ID. all to return all trophies for the title, default for the game itself, and additional groups starting from 001 and so on return expansions trophies.

      - limit (Optional[int]) – Limit of trophies returned, None means to return all trophy titles.

      - include_metadata (bool) – If True, will fetch metadata for trophy such as name and detail

    Warning

    Setting `include_metadata` to `True` will use twice the amount of rate limit since the API wrapper has to obtain metadata from a separate endpoint.

    Returns

      Returns the Trophy Generator object with all the information

    Return type

      Iterator[Trophy]

  trophy_groups_summary(np_communication_id: str, platform: Literal['PS Vita', 'PS3', 'PS4', 'PS5'], include_metadata: bool = False) → TrophyGroupsSummary

    Retrieves the trophy groups for a title and their respective trophy count.

    This is most commonly seen in games which have expansions where additional trophies are added.

    Parameters

      - np_communication_id (str) – Unique ID of a game title used to request trophy information. This can be obtained from `GameTitle` class.

      - platform (Literal) – The platform this title belongs to.

      - platform – The platform this title belongs to.

      - include_metadata (bool) – If True, will fetch results from another endpoint and include metadata for trophy group such as name and detail

    Warning

    Setting `include_metadata` to `True` will use twice the amount of rate limit since the API wrapper has to obtain metadata from a separate endpoint.

    Returns

      TrophyGroupSummary object containing title and title groups trophy information.

    Return type

      TrophyGroupsSummary

  title_stats(limit: Optional[int] = 100) → Iterator[TitleStats]

    Retrieve a list of title with their stats and basic meta-data

    Parameters

      limit (Optional[int]) – Limit of titles returned, will default to 100.

    Warning

    Only returns data for PS4 games and above. Don’t put a very high limit as the data returned includes a lot of extra meta-data which makes the payload large.

    Returns

      List of Titles with their play times

    Return type

      Iterator[TitleStats]

        client = psnawp.me()
        titles = client.title_stats()

## psnawp_api.models.game_title module

class GameTitle(request_builder: RequestBuilder, title_id: str, account_id: str, np_communication_id: Optional[str])

  Bases: `object`

  The GameTitle class provides the information and methods for retrieving Game details and trophies.

  Note

  This class is only useful if the user has played that video game. See `psnawp_api.psnawp.PSNAWP.game_title()` for more information.

  __init__(request_builder: RequestBuilder, title_id: str, account_id: str, np_communication_id: Optional[str])

    The GameTitle class constructor.

    Note

    This class is intended to be interfaced with through PSNAWP.

    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.

    Note

    `title_id` can be obtained from https://andshrew.github.io/PlayStation-Titles/ or from `psnawp_api.models.search.Search.get_title_id()`

    Parameters

      - request_builder (RequestBuilder) – The instance of RequestBuilder. Used to make HTTPRequests.

      - title_id (str) – unique id of game.

      - 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

    Raises

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

  get_details() → list[dict[str, Any]]

    Get game details such as full name, description, genre, promotional videos/images, etc…

    Returns

      A list of dicts containing info similar to what is shown below (Not all values are shown because of space limitations):

    Return type

      list[dict[str, Any]]

          [
            {
              "id": 201930,
              "name": "Grand Theft Auto V (PlayStation®5)",
              "nameEn": "Grand Theft Auto V (PlayStation®5)",
              "publisherName": "Rockstar Games",
              "media": {
              },
              "descriptions": [],
              "categorizedProducts": [],
              "titleIds": [],
              "country": "US",
              "language": "en",
              "type": "GAME",
              "localizedName": {},
              "localizedDescriptions": {},
              "localizedPublisherName": {},
              "defaultProduct": {},
              "genres": [],
              "localizedGenres": [],
              "subGenres": [],
              "localizedSubGenres": [],
              "minimumAge": 17,
              "releaseDate": {},
              "isRecommendableOnStore": true,
              "isSearchableOnStore": true,
              "storeFronts": [],
              "supportedStoreFronts": [],
              "marketingStories": [],
              "compatibilityNotices": [],
              "localizedMedia": {},
              "revisionIds": {},
              "contentRating": {}
            }
          ]

  trophies(platform: Literal['PS Vita', 'PS3', 'PS4', 'PS5'], trophy_group_id: str = 'default', limit: Optional[int] = None) → Iterator[Trophy]

    Retrieves the individual trophy detail of a single - or all - trophy groups for a title.

    Parameters

      - platform (Literal) – The platform this title belongs to.

      - trophy_group_id (str) – ID for the trophy group. Each game expansion is represented by a separate ID. all to return all trophies for the title, default for the game itself, and additional groups starting from 001 and so on return expansions trophies.

      - limit (Optional[int]) – Limit of trophies returned, None means to return all trophy titles.

    Returns

      Returns the Trophy Generator object with all the information

    Return type

      Iterator[Trophy]

    Raises

      `PSNAWPNotFound` if you don’t have any trophies for that game.

  trophy_groups_summary(platform: Literal['PS Vita', 'PS3', 'PS4', 'PS5']) → TrophyGroupsSummary

    Retrieves the trophy groups for a title and their respective trophy count.

    This is most commonly seen in games which have expansions where additional trophies are added.

    Parameters

      platform (Literal) – The platform this title belongs to.

    Returns

      TrophyGroupSummary object containing title and title groups trophy information.

    Return type

      TrophyGroupsSummary

    Raises

      `PSNAWPNotFound` if you don’t have any trophies for that game.

## psnawp_api.models.group module

class Group(request_builder: RequestBuilder, group_id: Optional[str], users: Optional[Iterator[User]])

  Bases: `object`

  The Group class is responsible for providing convenient methods to interact with PSN group endpoints, responsible for managing messages groups and sending messages.

  __init__(request_builder: RequestBuilder, group_id: Optional[str], users: Optional[Iterator[User]])

    Constructor of Group.

    Note

    This class is intended to be interfaced with through PSNAWP.

    Parameters

      - request_builder (RequestBuilder) – The instance of RequestBuilder. Used to make HTTPRequests.

      - group_id (Optional[str]) – The Group ID of a group.

      - users (Optional[Iterator[User]]) – A list of users of the members in the group.

    Raises

      `PSNAWPNotFound` If group id does not exist or is invalid.

    Raises

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

  change_name(group_name: str) → None

    Changes the group name to one specified in arguments.

    Note

    You cannot change the name of DM groups. i.e. Groups with only two people (including you).

    Parameters

      group_name (str) – The name of the group that will be set.

    Returns

      None

    Raises

      `PSNAWPBadRequest` If you are not part of group or the group is a DM.

  get_group_information() → dict[str, Any]

    Gets the group chat information such as about me, avatars, languages etc…

    Returns

      A dict containing info similar to what is shown below:

    Return type

      dict[str, Any]

    Raises

      `PSNAWPNotFound` If group id does not exist or is invalid.

        {
            "groupId": "~25C4C5406FD6D50E.763F9A1EB6AB5790",
            "groupType": 0,
            "modifiedTimestamp": "1663911908531",
            "groupName": {
                "value": "",
                "status": 0
            },
            "groupIcon": {
                "status": 0
            },
            "joinedTimestamp": "1616356026000",
            "isFavorite": false,
            "existsNewArrival": false,
            "mainThread": {
                "threadId": "~25C4C5406FD6D50E.763F9A1EB6AB5790",
                "modifiedTimestamp": "1663911908531",
                "latestMessage": {
                    "messageUid": "1#425961448584099",
                    "messageType": 1,
                    "alternativeMessageType": 1,
                    "body": "Hello World",
                    "createdTimestamp": "1663911908531",
                    "sender": {
                        "accountId": "8520698476712646544",
                        "onlineId": "VaultTec_Trading"
                    }
                },
                "readMessageUid": "1#425961448584099"
            },
            "members": [
                {
                    "accountId": "2721516955383551246",
                    "onlineId": "VaultTec-Co"
                },
                {
                    "accountId": "8520698476712646544",
                    "onlineId": "VaultTec_Trading"
                }
            ],
            "partySessions": [],
            "notificationSetting": {
                "isMute": false
            }
        }

  send_message(message: str) → dict[str, str]

    Sends a message in the group.

    Note

    For now only text based messaging is supported.

    Parameters

      message – Message Body

    Returns

      A dict containing info similar to what is shown below:

    Return type

      dict[str, str]

        {
            "messageUid": "1#425961448584099",
            "createdTimestamp": "1663911908531"
        }

  get_conversation(limit: int = 20) → dict[str, Any]

    Gets the conversations in a group.

    Parameters

      limit (int) – The number of conversations to receive.

    Returns

      A dict containing info similar to what is shown below:

    Return type

      dict[str, Any]

          {
              "messages": [
                  {
                      "messageUid": "1#425961448584099",
                      "messageType": 1,
                      "alternativeMessageType": 1,
                      "body": "Hello World",
                      "createdTimestamp": "1663911908531",
                      "sender": {
                          "accountId": "8520698476712646544",
                          "onlineId": "VaultTec_Trading"
                      }
                  }
              ],
              "previous": "1#425961448584099",
              "next": "1#425961448584099",
              "reachedEndOfPage": false,
              "messageCount": 1
          }

  leave_group() → None

    Leave the current group

    Raises

      `PSNAWPNotFound` If you are not part of the group.

## psnawp_api.models.search module

class Search(request_builder: RequestBuilder)

  Bases: `object`

  __init__(request_builder: RequestBuilder)

    The Search class provides the information and methods for searching resources on playstation network.

    Note

    This class is intended to be interfaced with through PSNAWP.

    Parameters

      request_builder (RequestBuilder) – The instance of RequestBuilder. Used to make HTTPRequests.

  universal_search(search_query: str, limit: int = 20) → dict[str, Any]

    Searches the Playstation Website. Note: It does not work as of now and the endpoints returns whole html page.

    Note

    Pagination not yet supported. The max number of results returned will be 20.

    Parameters

      - search_query (str) – search query

      - limit (int) – Limit of number of results

    Returns

      A dict containing info similar to what is shown below (Not all values are shown because of space limitations):

    Return type

      dict[str, Any]

          {
              "prefix": "GTA",
              "suggestions": [],
              "domainResponses": [
                  {
                      "domain": "ConceptGameMobileApp",
                      "domainTitle": "Results for ConceptGameMobileApp with search term GTA",
                      "domainTitleMessageId": "msgid_null",
                      "domainTitleHighlight": [
                          "Results for ConceptGameMobileApp with search term GTA"
                      ],
                      "zeroState": false,
                      "univexId": "search.no_experiment.non.0.non_",
                      "facetOptions": [],
                      "next": "",
                      "totalResultCount": 33,
                      "results": [
                          {
                              "id": "201930:UP1004-CUSA00419_00-GTAVDIGITALDOWNL",
                              "type": "conceptProduct",
                              "univexId": "search.no_experiment.non.0.non_",
                              "score": 234.40508,
                              "conceptProductMetadata": {}
                          }
                      ]
                  }
              ],
              "fallbackQueried": false
          }

  get_title_id(title_name: str) → tuple[str, str]

    Gets the title id from title name using universal search endpoint.

    Warning

    Make sure to use the official full name of the video game otherwise the returned results may not be accurate. For example: GTA V returns the GTA Vice City since the Vice City shows up above GTA V. However, Grand Theft Auto V returns the correct results.

    Parameters

      title_name (str) – Video Game title name

    Returns

      A tuple containing English Title Name and Title ID

    Return type

      tuple[str, str]

## psnawp_api.models.title_stats module

class PlatformCategory(value)

  Bases: `Enum`

  An enumeration.

  UNKNOWN = 'unknown'
  PS4 = 'ps4_game'
  PS5 = 'ps5_native_game'

platform_str_to_enum(platform_type_str: Optional[str]) → PlatformCategory

class TitleStats(title_id: Optional[str], name: Optional[str], image_url: Optional[str], category: Optional[PlatformCategory], play_count: Optional[int], first_played_date_time: Optional[datetime], last_played_date_time: Optional[datetime], play_duration: Optional[timedelta])

  Bases: `object`

  A class that represents a PlayStation Video Game Play Time Stats.

  title_id: Optional[str]

    Game title name

  name: Optional[str]

    Image URL

  image_url: Optional[str]

    Category/Platform Type

  category: Optional[PlatformCategory]

    Number of times the game has been played

  play_count: Optional[int]

    First time the game was played

  __init__(title_id: Optional[str], name: Optional[str], image_url: Optional[str], category: Optional[PlatformCategory], play_count: Optional[int], first_played_date_time: Optional[datetime], last_played_date_time: Optional[datetime], play_duration: Optional[timedelta]) → None

    Method generated by attrs for class TitleStats.

  first_played_date_time: Optional[datetime]

    Last time the game was played

  last_played_date_time: Optional[datetime]

    Total time the game has been played. Example: PT1H51M21S

  play_duration: Optional[timedelta]
  classmethod from_dict(game_stats_dict: dict[str, Any]) → TitleStats
  classmethod from_endpoint(request_builder: RequestBuilder, account_id: str, limit: Optional[int] = 100) → Iterator[TitleStats]

## psnawp_api.models.user module

class User(request_builder: RequestBuilder, online_id: str, account_id: str)

  Bases: `object`

  This class will contain the information about the PSN ID you passed in when creating object

  classmethod from_online_id(request_builder: RequestBuilder, online_id: str) → User

    Creates the User instance from online ID and returns the instance.

    Parameters

      - request_builder (RequestBuilder) – Used to call http requests.

      - online_id (str) – Online ID (GamerTag) of the user.

    Returns

      User Class object which represents a PlayStation account

    Return type

      User

    Raises

      `PSNAWPNotFound` If the user is not valid/found.

  classmethod from_account_id(request_builder: RequestBuilder, account_id: str) → User

    Creates the User instance from account ID and returns the instance.

    Parameters

      - request_builder (RequestBuilder) – Used to call http requests.

      - account_id (str) – Account ID of the user.

    Returns

      User Class object which represents a PlayStation account

    Return type

      User

    Raises

      `PSNAWPNotFound` If the user is not valid/found.

  __init__(request_builder: RequestBuilder, online_id: str, account_id: str)

    Constructor of Class User.

    Note

    This class is intended to be interfaced with through PSNAWP.

    Parameters

      - request_builder (RequestBuilder) – Used to call http requests.

      - online_id (str) – Online ID (GamerTag) of the user.

      - account_id (str) – Account ID of the user.

    Raises

      `PSNAWPIllegalArgumentError` If both online_id and account_id are not provided.

    Raises

      `PSNAWPNotFound` If the online id or account id is not valid/found.

  profile() → dict[str, Any]

    Gets the profile of the user such as about me, avatars, languages etc…

    Returns

      A dict containing info similar to what is shown below:

    Return type

      dict[str, Any]

          {
            "onlineId": "VaultTec-Co",
            "aboutMe": "r/Fallout76Marketplace Moderator",
            "avatars": [
              {
                "size": "s",
                "url": "[Redacted]"
              },
              {
                "size": "xl",
                "url": "[Redacted]"
              },
              {
                "size": "l",
                "url": "[Redacted]"
              },
              {
                "size": "m",
                "url": "[Redacted]"
              }
            ],
            "languages": [
              "en-US"
            ],
            "isPlus": false,
            "isOfficiallyVerified": false,
            "isMe": false
          }

        user_example = psnawp.user(online_id='VaultTec_Trading')
        print(user_example.profile())

  get_presence() → dict[str, Any]

    Gets the presences of a user. If the profile is private

    Returns

      A dict containing info similar to what is shown below:

    Return type

      dict[str, Any]

          {
            "availability": "availableToPlay",
            "primaryPlatformInfo": {
              "onlineStatus": "online",
              "platform": "ps4",
              "lastOnlineDate": "2022-09-15T22:50:28.012Z"
            }
          }

    Raises

      `PSNAWPForbidden` When the user’s profile is private, and you don’t have permission to view their online status.

        user_example = psnawp.user(online_id='VaultTec_Trading')
        print(user_example.get_presence())

  friendship() → dict[str, Any]

    Gets the friendship status and stats of the user

    Returns

      A dict containing info similar to what is shown below

    Return type

      dict[str, Any]

          {
            "friendRelation": "friend",
            "personalDetailSharing": "none",
            "friendsCount": 419,
            "mutualFriendsCount": 0
          }

        user_example = psnawp.user(online_id='VaultTec_Trading')
        print(user_example.friendship())

  is_blocked() → bool

    Checks if the user is blocked by you

    Returns

      True if the user is blocked otherwise False

    Return type

      bool

        user_example = psnawp.user(online_id='VaultTec_Trading')
        print(user_example.is_blocked())

  trophy_summary() → TrophySummary

    Retrieve an overall summary of the number of trophies earned for a user broken down by

    - type

    - overall trophy level

    - progress towards the next level

    - current tier

    Returns

      Trophy Summary Object containing all information

    Return type

      TrophySummary

    Raises

      `PSNAWPForbidden` If the user’s profile is private

        user_example = psnawp.user(online_id="VaultTec_Trading")
        print(user_example.trophy_summary())

  trophy_titles(limit: Optional[int] = None) → Iterator[TrophyTitle]

    Retrieve all game titles associated with an account, and a summary of trophies earned from them.

    Parameters

      limit (Optional[int]) – Limit of titles returned, None means to return all trophy titles.

    Returns

      Generator object with TitleTrophySummary objects

    Return type

      Iterator[TrophyTitle]

    Raises

      `PSNAWPForbidden` If the user’s profile is private

        user_example = psnawp.user(online_id="VaultTec_Trading")
        for trophy_title in user_example.trophy_titles(limit=None):
            print(trophy_title)

  trophy_titles_for_title(title_ids: list[str]) → Iterator[TrophyTitle]

    Retrieve a summary of the trophies earned by a user for specific titles.

    Note

    `title_id` can be obtained from https://andshrew.github.io/PlayStation-Titles/ or from `psnawp_api.models.search.Search.get_title_id()`

    Parameters

      title_ids (list[str]) – Unique ID of the title

    Returns

      Generator object with TitleTrophySummary objects

    Return type

      Iterator[TrophyTitle]

    Raises

      `PSNAWPForbidden` If the user’s profile is private

        user_example = psnawp.user(online_id="VaultTec_Trading")
        for trophy_title in user_example.trophy_titles_for_title(title_id='CUSA00265_00'):
            print(trophy_title)

  trophies(np_communication_id: str, platform: Literal['PS Vita', 'PS3', 'PS4', 'PS5'], trophy_group_id: str = 'default', limit: Optional[int] = None, include_metadata: bool = False) → Iterator[Trophy]

    Retrieves the earned status individual trophy detail of a single - or all - trophy groups for a title.

    Parameters

      - np_communication_id (str) – Unique ID of the title used to request trophy information

      - platform (Literal) – The platform this title belongs to.

      - trophy_group_id (str) – ID for the trophy group. Each game expansion is represented by a separate ID. all to return all trophies for the title, default for the game itself, and additional groups starting from 001 and so on return expansions trophies.

      - limit (Optional[int]) – Limit of trophies returned, None means to return all trophy titles.

      - include_metadata (bool) – If True, will fetch metadata for trophy such as name and detail

    Warning

    Setting `include_metadata` to `True` will use twice the amount of rate limit since the API wrapper has to obtain metadata from a separate endpoint.

    Returns

      Returns the Trophy Generator object with all the information

    Return type

      Iterator[Trophy]

    Raises

      `PSNAWPNotFound` if you don’t have any trophies for that game.

    Raises

      `PSNAWPForbidden` If the user’s profile is private

  trophy_groups_summary(np_communication_id: str, platform: Literal['PS Vita', 'PS3', 'PS4', 'PS5'], include_metadata: bool = False) → TrophyGroupsSummary

    Retrieves the trophy groups for a title and their respective trophy count.

    This is most commonly seen in games which have expansions where additional trophies are added.

    Parameters

      - np_communication_id (str) – Unique ID of the title used to request trophy information

      - platform (Literal) – The platform this title belongs to.

      - platform – The platform this title belongs to.

      - include_metadata (bool) – If True, will fetch results from another endpoint and include metadata for trophy group such as name and detail

    Warning

    Setting `include_metadata` to `True` will use twice the amount of rate limit since the API wrapper has to obtain metadata from a separate endpoint.

    Returns

      TrophyGroupSummary object containing title and title groups trophy information.

    Return type

      TrophyGroupsSummary

    Raises

      `PSNAWPNotFound` if you don’t have any trophies for that game.

    Raises

      `PSNAWPForbidden` If the user’s profile is private

  title_stats(limit: Optional[int] = 100) → Iterator[TitleStats]

    Retrieve a list of title with their stats and basic meta-data

    Parameters

      limit (Optional[int]) – Limit of titles returned, will default to 100.

    Warning

    Only returns data for PS4 games and above. Don’t put a very high limit as the data returned includes a lot of extra meta data which makes the payload large.

    Returns

      List of Titles with their play times

    Return type

      Iterator[TitleStats]

        user_example = psnawp.user(online_id='jeranther')
        titles = user_example.title_stats()

## Module contents