Building a Python Script for Amazon Review Sentiment Analysis with SellerMagnetAPI
In today's data-driven marketplace, understanding customer sentiment is crucial for Amazon businesses. Analyzing product reviews can provide invaluable insights into customer satisfaction, product strengths and weaknesses, and overall brand perception. This blog post will guide you through building a Python script to perform sentiment analysis on Amazon reviews using the SellerMagnetAPI, a powerful tool for extracting and analyzing Amazon data.
SellerMagnetAPI ( https://sellermagnet-api.com ) offers enterprise-grade access to Amazon data, enabling businesses to perform competitive analysis, optimize inventory management, and conduct comprehensive market research. We'll leverage the API's capabilities to retrieve review data and perform sentiment analysis.
Why Sentiment Analysis for Amazon Reviews?
Sentiment analysis helps businesses:
- Identify Product Strengths and Weaknesses: Understand what customers love and dislike about your products.
- Monitor Brand Reputation: Track overall sentiment towards your brand and identify potential issues early.
- Improve Customer Service: Address negative feedback promptly and improve customer satisfaction.
- Gain Competitive Intelligence: Analyze competitor reviews to identify opportunities and threats.
Setting Up Your Python Environment
Before we begin, ensure you have Python installed along with the necessary libraries. We'll need requests
for making API calls and a sentiment analysis library like nltk
or TextBlob
. Install them using pip:
pip install requests nltk textblob
You'll also need an API key from SellerMagnetAPI. Try Free to get started.
Retrieving Amazon Reviews with SellerMagnetAPI
We'll use the Amazon Seller Review endpoint to retrieve customer reviews. This endpoint requires a sellerId
and marketplaceId
.
Here's a Python function to fetch reviews:
import requests
import json
def get_seller_reviews(seller_id, marketplace_id, api_key):
url = "https://sellermagnet-api.com/amazon-seller-review"
params = {
"sellerId": seller_id,
"marketplaceId": marketplace_id,
"api_key": api_key
}
try:
response = requests.get(url, params=params)
response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
data = response.json()
return data
except requests.exceptions.RequestException as e:
print(f"Error fetching reviews: {e}")
return None
# Example usage
seller_id = "A1CWSGXIR635I6" # Replace with a valid Seller ID
marketplace_id = "ATVPDKIKX0DER" # Replace with a valid Marketplace ID
api_key = "YOUR_API_KEY" # Replace with your actual API key
reviews_data = get_seller_reviews(seller_id, marketplace_id, api_key)
if reviews_data and reviews_data["success"]:
print(json.dumps(reviews_data, indent=4))
else:
print("Failed to retrieve reviews.")
Here's an example of a successful response:
{
"data": {
"marketplace": {
"ATVPDKIKX0DER": {
"last5Reviews": [
{
"dateRated": "By gary kraus on June 5, 2025.",
"reviewText": "great",
"starRating": "5 out of 5 stars"
},
{
"dateRated": "By Amazon Customer on June 5, 2025.",
"reviewText": "Ok",
"starRating": "5 out of 5 stars"
},
{
"dateRated": "By Graciela Casta\u00f1eda on May 21, 2025.",
"reviewText": "Excelente",
"starRating": "5 out of 5 stars"
}
],
"sellerFeedback": {
"30": {
"rating": "3.3",
"reviewsCount": "7"
},
"90": {
"rating": "3.6",
"reviewsCount": "30"
},
"365": {
"rating": "3.9",
"reviewsCount": "114"
},
"lifetime": {
"rating": "4.5",
"reviewsCount": "1,535"
}
}
}
},
"sellerId": "A1CWSGXIR635I6"
},
"success": true
}
Performing Sentiment Analysis
Now that we have the review data, let's perform sentiment analysis using TextBlob. This library provides a simple way to determine the sentiment polarity of a text.
from textblob import TextBlob
def analyze_sentiment(text):
analysis = TextBlob(text)
return analysis.sentiment.polarity
def process_reviews(reviews_data):
if not reviews_data or not reviews_data["success"]:
print("No reviews data to process.")
return
marketplace_data = list(reviews_data["data"]["marketplace"].values())[0]
reviews = marketplace_data["last5Reviews"]
for review in reviews:
review_text = review["reviewText"]
sentiment_score = analyze_sentiment(review_text)
if sentiment_score > 0:
sentiment = "Positive"
elif sentiment_score < 0:
sentiment = "Negative"
else:
sentiment = "Neutral"
print(f"Review: {review_text}\nSentiment: {sentiment} (Score: {sentiment_score:.2f})\n")
# Example usage with reviews_data from previous step
if reviews_data:
process_reviews(reviews_data)
This script iterates through each review, analyzes its sentiment, and prints the review text along with its sentiment (Positive, Negative, or Neutral) and the sentiment score. A score close to 1 indicates strong positive sentiment, a score close to -1 indicates strong negative sentiment, and a score around 0 indicates neutral sentiment.
Enhancing Your Analysis with SellerMagnetAPI
SellerMagnetAPI provides a suite of other powerful endpoints that can augment your sentiment analysis:
- Amazon Product Statistics: Get detailed product information, including sales rank and review counts, to correlate sentiment with product performance.
- Amazon Product Lookup: Retrieve product details, such as descriptions and bullet points, to understand the context of reviews.
- Amazon Product Offers: Analyze pricing and seller information alongside reviews to identify potential impacts on customer sentiment.
For example, you could use the Amazon Product Statistics endpoint to track changes in review sentiment over time and correlate them with changes in sales rank or pricing. Here's how to call the API:
import requests
import json
def get_product_statistics(asin, marketplace_id, api_key):
url = "https://sellermagnet-api.com/amazon-product-statistics"
params = {
"asin": asin,
"marketplaceId": marketplace_id,
"api_key": api_key
}
try:
response = requests.get(url, params=params)
response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
data = response.json()
return data
except requests.exceptions.RequestException as e:
print(f"Error fetching product statistics: {e}")
return None
# Example usage
asin = "B0CLTBHXWQ" # Replace with a valid ASIN
marketplace_id = "APJ6JRA9NG5V4" # Replace with a valid Marketplace ID
api_key = "YOUR_API_KEY" # Replace with your actual API key
product_stats = get_product_statistics(asin, marketplace_id, api_key)
if product_stats and product_stats["success"]:
print(json.dumps(product_stats, indent=4))
else:
print("Failed to retrieve product statistics.")
And here's example response:
{
"data": {
"asin": "B0CLTBHXWQ",
"productTitle": "Playstation 5 Console Edizione Digital Slim",
"buyBoxPrice": 41800,
"buyBoxFulfillment": "FBM",
"buyBoxSellerIdHistory": [
[
"2025-06-14 17:08:00",
"A2I59UVTUWUFH0"
]
],
"categoryTree": [
{
"catId": 412603031,
"name": "Videogiochi"
},
{
"catId": 20904349031,
"name": "PlayStation 5"
},
{
"catId": 20904364031,
"name": "Console"
}
],
"graphs": {
"amazonAsSellerPriceHistory": "https://sellermagnet-api-webspace.s3.eu-central-1.amazonaws.com/amazon/api/charts/B0CLTBHXWQ/1749913774/B0CLTBHXWQ_amazon_price_1749913773.png",
"lowestFBAPriceHistory": "https://sellermagnet-api-webspace.s3.eu-central-1.amazonaws.com/amazon/api/charts/B0CLTBHXWQ/1749913776/B0CLTBHXWQ_fba_price_1749913773.png",
"lowestFBMPriceHistory": "https://sellermagnet-api-webspace.s3.eu-central-1.amazonaws.com/amazon/api/charts/B0CLTBHXWQ/1749913775/B0CLTBHXWQ_fbm_price_1749913773.png",
"monthlySoldHistory": "https://sellermagnet-api-webspace.s3.eu-central-1.amazonaws.com/amazon/api/charts/B0CLTBHXWQ/1749913778/B0CLTBHXWQ_monthly_sold_1749913773.png",
"productRatingHistory": "https://sellermagnet-api-webspace.s3.eu-central-1.amazonaws.com/amazon/api/charts/B0CLTBHXWQ/1749913777/B0CLTBHXWQ_rating_1749913773.png"
},
"listedSince": "2023-12-30 01:00:00",
"lowestFBAPrice": 44999,
"lowestFBMPrice": 41700,
"marketplaceId": "APJ6JRA9NG5V4",
"marketplaceNewPriceHistory": [
[
"2025-06-14",
41700
]
],
"offers": {
"A11IL2PNWYJU7H": {
"isFBA": true,
"lastUpdated": "2025-06-14 17:08:00",
"priceHistory": [
[
"2025-06-14 06:22:00",
44999,
0
]
],
"stockHistory": [
[
"2025-05-29 11:32:00",
1
]
]
},
"A12FLY25DT7QO0": {
"isFBA": false,
"lastUpdated": "2025-06-14 17:08:00",
"priceHistory": [
[
"2025-06-09 15:32:00",
41800,
0
]
],
"stockHistory": [
[
"2025-06-14 13:34:00",
49
]
]
},
"A18KSDUE00UP6J": {
"isFBA": false,
"lastUpdated": "2025-06-14 17:08:00",
"priceHistory": [
[
"2025-05-29 11:32:00",
42890,
0
]
],
"stockHistory": [
[
"2025-05-30 18:30:00",
3
]
]
}
},
"productReviewAverage": 4.7,
"productTotalReviews": 3129,
"rootCategory": {
"id": 412603031,
"name": "Videogiochi"
},
"stats": {
"amazonAsSellerPriceHistory": [
[
"2025-06-14",
44999
]
],
"buyBoxPriceHistory": [
[
"2025-06-13",
41700
]
],
"monthlySoldHistory": [
[
"2025-06",
1000
]
],
"productRatingCountHistory": [
[
"2025-06-14 15:28:00",
3129
]
],
"productRatingHistory": [
[
"2025-02-02 01:30:00",
4.7
]
],
"salesRankHistory": [
[
"2025-06-14 01:58:00",
15
]
]
}
},
"success": true
}
Scaling Your Sentiment Analysis
For large-scale analysis, consider these optimizations:
- Asynchronous Requests: Use
asyncio
andaiohttp
for concurrent API calls. - Data Storage: Store review data and sentiment scores in a database for efficient analysis and reporting.
- Advanced NLP Techniques: Explore more sophisticated NLP models for improved sentiment accuracy.
Conclusion
By combining Python with the power of SellerMagnetAPI, you can build a robust solution for Amazon review sentiment analysis. This provides actionable insights to improve your products, brand reputation, and overall business performance. Start leveraging the SellerMagnetAPI today and unlock the potential of Amazon data. Explore our Pricing to find the plan that fits your needs.