Skip to main content

PlayStation Logo PlayStation Network API Wrapper Python (PSNAWP)

Retrieve User Information, Trophies, Game and Store data from the PlayStation Network.

PyPI version python-logo Checked with pyright Documentation Status Downloads License: MIT Poetry Ruff

How to install

From PyPI

pip install PSNAWP

PyPI: https://pypi.org/project/PSNAWP/

Read the Docs: https://psnawp.readthedocs.io

Getting Started

To get started you need to obtain npsso <64 character code>. You need to follow the following steps

  1. Login into your My PlayStation account.
  2. In another tab, go to https://ca.account.sony.com/api/v1/ssocookie
  3. If you are logged in you should see a text similar to this
{"npsso":"<64 character npsso code>"}

This npsso code will be used in the api for authentication purposes. The refresh token that is generated from npsso lasts about 2 months. After that you have to get a new npsso token. The bot will print a warning if there are less than 3 days left in refresh token expiration.

Following is the quick example on how to use this library

from os import getenv

from dotenv import load_dotenv

from psnawp_api import PSNAWP
from psnawp_api.models.search import SearchDomain
from psnawp_api.models.trophies import PlatformType

load_dotenv()


psnawp = PSNAWP(getenv("NPSSO_CODE", "NPSSO_CODE"))

# Your Personal Account Info
client = psnawp.me()
print(f"Online ID: {client.online_id}")
print(f"Account ID: {client.account_id}")
print(f"Region: {client.get_region()}")
print(f"Profile: {client.get_profile_legacy()} \n")

# Your Registered Devices
devices = client.get_account_devices()
for device in devices:
    print(f"Device: {device} \n")

# Your Friends List
friends_list = client.friends_list()
for friend in friends_list:
    print(f"Friend: {friend} \n")

# Your Players Blocked List
blocked_list = client.blocked_list()
for blocked_user in blocked_list:
    print(f"Blocked User: {blocked_user} \n")

# Your Friends in "Notify when available" List
available_to_play = client.available_to_play()
for user in available_to_play:
    print(f"Available to Play: {user} \n")

# Your trophies (PS4)
for trophy in client.trophies("NPWR22810_00", PlatformType.PS4):
    print(trophy)

# Your Chat Groups
groups = client.get_groups()
first_group_id = None  # This will be used later to test group methods
for id, group in enumerate(groups):
    if id == 0:  # Get the first group ID
        first_group_id = group.group_id

    group_info = group.get_group_information()
    print(f"Group {id}: {group_info} \n")

# Your Playing time (PS4, PS5 above only)
titles_with_stats = client.title_stats()
for title in titles_with_stats:
    print(
        f" \
        Game: {title.name} - \
        Play Count: {title.play_count} - \
        Play Duration: {title.play_duration} \n"
    )


# Other User's
example_user_1 = psnawp.user(online_id="VaultTec-Co")  # Get a PSN player by their Online ID
print(f"User 1 Online ID: {example_user_1.online_id}")
print(f"User 1 Account ID: {example_user_1.account_id}")
print(f"User 1 Region: {example_user_1.get_region()}")

print(example_user_1.profile())
print(example_user_1.prev_online_id)
print(example_user_1.get_presence())
print(example_user_1.friendship())
print(example_user_1.is_blocked())

# Example of getting a user by their account ID
user_account_id = psnawp.user(account_id="9122947611907501295")
print(f"User Account ID: {user_account_id.online_id}")


# Messaging and Groups Interaction
group = psnawp.group(group_id=first_group_id)  # This is the first group ID we got earlier - i.e. the first group in your groups list
print(group.get_group_information())
print(group.get_conversation(10))  # Get the last 10 messages in the group
group.send_message("Hello World")
group.change_name("API Testing 3")
group.leave_group()

# Create a new group with other users - i.e. 'VaultTec-Co' and 'test'
example_user_2 = psnawp.user(online_id="test")
new_group = psnawp.group(users_list=[example_user_1, example_user_2])
print(new_group.get_group_information())
# You can use the same above methods to interact with the new group - i.e. send messages, change name, etc.

# Searching for Game Titles
search = psnawp.search(search_query="GTA 5", search_domain=SearchDomain.FULL_GAMES)
for search_result in search:
    print(search_result["result"]["invariantName"])

Note: If you want to create multiple instances of psnawp you need to get npsso code from separate PSN accounts. If you generate a new npsso with same account your previous npsso will expire immediately.

Contribution

All bug reposts and features requests are welcomed, although I am new at making python libraries, so it may take me a while to implement some features. Suggestions are welcomes if I am doing something that is an unconventional way of doing it.

Disclaimer

This project was not intended to be used for spam, abuse, or anything of the sort. Any use of this project for those purposes is not endorsed. Please keep this in mind when creating applications using this API wrapper.

Credit

This project contains code from PlayStationNetwork::API and PSN-PHP Wrapper that was translated to Python. Also, special thanks @andshrew for documenting the PlayStation Trophy endpoints. All licenses are included in this repository.

Metadata

Release files for psnawp 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for psnawp 3.1.0
File Size Uploaded Provenance Actions
psnawp-3.1.0.tar.gz 52.0 kB Without provenance Details for psnawp-3.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for psnawp 3.1.0
File Interpreter ABI Platform Actions
psnawp-3.1.0-py3-none-any.whl Python 3 none any Details for psnawp-3.1.0-py3-none-any.whl

Total release size: 122.1 kB

Release files / psnawp-3.1.0.tar.gz

Download URL psnawp-3.1.0.tar.gz
Size 52.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e0f8027ea3b3a2cc253f732e7e4b7f319670d03e10e36a80d8bb87ab70fe3e91
BLAKE2b-256 checksum
How to use checksums
bd2ec4b38e365d0e807f4291c1de170516216ac3bfd4b3e0ec2eda58c32505eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.3 Linux/7.2.11+deb14-amd64

Release files / psnawp-3.1.0-py3-none-any.whl

Download URL psnawp-3.1.0-py3-none-any.whl
Size 70.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
559f0229bd33e8257b3631708b31b3018047bb475ce74dd37241f19db37690f8
BLAKE2b-256 checksum
How to use checksums
e6690b7eb14a376ac45d93cc49718afab530fba02caf213ffd3a16866bc48699
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.3 Linux/7.2.11+deb14-amd64

Security for psnawp 3.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page