How to get the personalized rankings using the AWS Python SDK?

Today lesson is how we will connect to AWS personalize campaign using the Python script and get the personalized rankings list. We are using Python (Latest: Python 3.8.2) and boto3 plugin to achieve this.

1. Install the Python
– Download the latest version of Python 3.8.2

2. Download and install boto3 library

$ pip install boto3

3. Get Personalized Rankings from AWS Personalize

# importing the boto3 library 
import boto3
# connect to Personalize using boto3 client
personalizeRt = boto3.client('personalize-runtime')
# Get rankings data by each campaign ARN
response = personalizeRt.get_personalized_ranking(
    campaignArn = "Campaign ARN",
    userId = "UserID",
    inputList = ['ItemID1','ItemID2'])
# Output ranking data 
print("Personalized Ranking")
for item in response['personalizedRanking']:
    print (item['itemId'])

Note: You need to replace the “Campaign ARN” text with your actual Campaign ARN.

That’s it. I hope this will help. ?
Photo: https://www.brandeps.com

Leave a Reply

Your email address will not be published. Required fields are marked *