psnawp_api package — PSNAWP 1.1.0 documentation

# psnawp_api package

## Subpackages

- psnawp_api.core package
  - Submodules
  - psnawp_api.core.authenticator module
    - `Authenticator`
      - `Authenticator.__init__()`
      - `Authenticator.obtain_fresh_access_token()`
      - `Authenticator.oauth_token()`
  - psnawp_api.core.psnawp_exceptions module
    - `PSNAWPException`
    - `PSNAWPAuthenticationError`
    - `PSNAWPBadRequest`
    - `PSNAWPIllegalArgumentError`
    - `PSNAWPUnauthorized`
    - `PSNAWPForbidden`
    - `PSNAWPNotFound`
    - `PSNAWPNotAllowed`
    - `PSNAWPServerError`
  - Module contents
- psnawp_api.models package
  - Subpackages
    - psnawp_api.models.trophies package
      - Submodules
      - psnawp_api.models.trophies.trophy module
      - psnawp_api.models.trophies.trophy_constants module
      - psnawp_api.models.trophies.trophy_group module
      - psnawp_api.models.trophies.trophy_summary module
      - psnawp_api.models.trophies.trophy_titles module
      - psnawp_api.models.trophies.utility_functions module
      - Module contents
  - Submodules
  - psnawp_api.models.client module
    - `Client`
      - `Client.__init__()`
      - `Client.online_id`
      - `Client.account_id`
      - `Client.get_profile_legacy()`
      - `Client.get_account_devices()`
      - `Client.friends_list()`
      - `Client.available_to_play()`
      - `Client.blocked_list()`
      - `Client.get_groups()`
      - `Client.trophy_summary()`
      - `Client.trophy_titles()`
      - `Client.trophy_titles_for_title()`
      - `Client.trophies()`
      - `Client.trophy_groups_summary()`
      - `Client.title_stats()`
  - psnawp_api.models.game_title module
    - `GameTitle`
      - `GameTitle.__init__()`
      - `GameTitle.get_details()`
      - `GameTitle.trophies()`
      - `GameTitle.trophy_groups_summary()`
  - psnawp_api.models.group module
    - `Group`
      - `Group.__init__()`
      - `Group.change_name()`
      - `Group.get_group_information()`
      - `Group.send_message()`
      - `Group.get_conversation()`
      - `Group.leave_group()`
  - psnawp_api.models.search module
    - `Search`
      - `Search.__init__()`
      - `Search.universal_search()`
      - `Search.get_title_id()`
  - psnawp_api.models.title_stats module
    - `PlatformCategory`
      - `PlatformCategory.UNKNOWN`
      - `PlatformCategory.PS4`
      - `PlatformCategory.PS5`
    - `platform_str_to_enum()`
    - `TitleStats`
      - `TitleStats.title_id`
      - `TitleStats.name`
      - `TitleStats.image_url`
      - `TitleStats.category`
      - `TitleStats.play_count`
      - `TitleStats.__init__()`
      - `TitleStats.first_played_date_time`
      - `TitleStats.last_played_date_time`
      - `TitleStats.play_duration`
      - `TitleStats.from_dict()`
      - `TitleStats.from_endpoint()`
  - psnawp_api.models.user module
    - `User`
      - `User.from_online_id()`
      - `User.from_account_id()`
      - `User.__init__()`
      - `User.profile()`
      - `User.get_presence()`
      - `User.friendship()`
      - `User.is_blocked()`
      - `User.trophy_summary()`
      - `User.trophy_titles()`
      - `User.trophy_titles_for_title()`
      - `User.trophies()`
      - `User.trophy_groups_summary()`
      - `User.title_stats()`
  - Module contents
- psnawp_api.utils package
  - Submodules
  - psnawp_api.utils.endpoints module
  - psnawp_api.utils.misc module
    - `create_logger()`
    - `iso_format_to_datetime()`
    - `play_duration_to_timedelta()`
  - psnawp_api.utils.request_builder module
    - `response_checker()`
    - `RequestBuilder`
      - `RequestBuilder.__init__()`
      - `RequestBuilder.get()`
      - `RequestBuilder.patch()`
      - `RequestBuilder.post()`
      - `RequestBuilder.multipart_post()`
      - `RequestBuilder.delete()`
  - Module contents

## Submodules

## psnawp_api.psnawp module

class PSNAWP(npsso_cookie: str)

  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)

    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.

    Raises

      `PSNAWPAuthenticationError` If npsso code is expired or is incorrect.

  me() → Client

    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
  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: Optional[str] = None) → GameTitle

    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

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

    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
  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

    Creates a new search object

    Returns

      Search Object

## Module contents