Python script for Amazon price monitoring

Building a Python Script for Amazon Competitor Price Monitoring

By Michael Chen | July 16, 2025

Building a Python Script for Amazon Competitor Price Monitoring

In today's dynamic e-commerce landscape, staying ahead of the competition on Amazon requires diligent monitoring of competitor pricing strategies. A custom Python script, leveraging the power of SellerMagnet's Amazon data API ( https://sellermagnet-api.com ), offers a robust solution for automating this process. This post guides you through building such a script for competitive analysis, inventory management, and informed market research.

Why Use a Python Script for Price Monitoring?

Automating price monitoring with Python provides several advantages:

  • Real-time Data: Access up-to-date pricing information directly from Amazon.
  • Customization: Tailor the script to track specific products and competitors relevant to your business.
  • Efficiency: Eliminate manual price checks, saving time and resources.
  • Data-Driven Decisions: Use collected data to optimize pricing strategies and improve profitability.

Prerequisites

Before you begin, ensure you have the following:

  • Python 3.6+ installed.
  • A SellerMagnet API key (available at Try Free).
  • Required Python libraries: requests. Install it using pip install requests.

Step-by-Step Guide

1. Setting Up Your Python Environment

Create a new Python file (e.g., amazon_price_monitor.py) and import the necessary libraries:


import requests
import json

2. Defining the Core Function to Fetch Product Data

We'll use the Amazon Product Statistics endpoint to retrieve pricing data. This endpoint requires the product's ASIN and marketplace ID.


def get_product_stats(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)
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")
        return None

Example Request:


curl --request GET \
  --url 'https://sellermagnet-api.com/amazon-product-statistics?asin=B08N5WRWNW&marketplaceId=A1PA6795UKMFR9&api_key=YOUR_API_KEY'

Example Response:


{
  "success": true,
  "data": {
    "asin": "B08N5WRWNW",
    "amazonPrice": 2999,
    "bestSellerRank": 1234,
    "buyBoxPrice": 2899,
    "buyBoxFulfillment": "FBA",
    "buyBoxSellerIdHistory": [
      [
        "2024-01-01T00:00:00",
        "A1234567890ABC"
      ]
    ],
    "salesRankHistory": [
      [
        "2024-01-01T00:00:00",
        1234
      ]
    ],
    "trackingSince": "2023-01-01"
  }
}

3. Implementing the Price Monitoring Logic

Now, let's add the logic to monitor prices and trigger alerts if a competitor's price changes significantly.


def monitor_price(asin, marketplace_id, api_key, threshold=0.05):
    """Monitors the price of a product and alerts if it changes by more than the threshold.
    """
    previous_price = None
    while True:
        data = get_product_stats(asin, marketplace_id, api_key)
        if data and data['success']:
            current_price = data['data']['buyBoxPrice'] #Price in cents
            if current_price is not None:
              current_price_usd = current_price/100 #price in dollars
            else:
              print(f"No Buy Box Price Available for ASIN: {asin}")
              continue #skip to next iteration of loop if buybox price is unavailable


            if previous_price is not None:
                price_change = abs(current_price_usd - previous_price) / previous_price
                if price_change > threshold:
                    print(f"Price change detected for ASIN: {asin}")
                    print(f"Previous Price: ${previous_price:.2f}, Current Price: ${current_price_usd:.2f}")

            previous_price = current_price_usd
        else:
            print(f"Failed to retrieve data for ASIN: {asin}")

        time.sleep(60)  # Check every 60 seconds

4. Running the Script

Finally, call the monitor_price function with the ASIN, marketplace ID, and your API key:


if __name__ == "__main__":
    import time
    asin = "B08N5WRWNW"  # Replace with the ASIN of the product you want to monitor
    marketplace_id = "A1PA6795UKMFR9"  # Replace with the appropriate marketplace ID (e.g., Germany)
    api_key = "YOUR_API_KEY"  # Replace with your SellerMagnet API key

    monitor_price(asin, marketplace_id, api_key)

Advanced Use Cases

1. Monitoring Multiple Products

Modify the script to monitor multiple ASINs by storing them in a list and iterating through them.

2. Using DataPipeline for Scheduled Monitoring

Schedule the script to run automatically at specific intervals using SellerMagnet's DataPipeline feature.

3. Integrating with Other APIs

Combine the price monitoring script with other SellerMagnet APIs like Amazon Product Offers to get a comprehensive view of competitor strategies. Furthermore you can combine product pricing with the Amazon Seller Review to see the sellers rating.

4. Converting ASIN

Sometimes you need to convert data id from product listing. Use Amazon ASIN/ISBN/EAN Converter


def get_asin_converter(asin, marketplace_id, conversion_direction, api_key):
    url = "https://sellermagnet-api.com/amazon-asin-converter"
    params = {
        "asin": asin,
        "marketplaceId": marketplace_id,
        "conversion_direction": conversion_direction,
        "api_key": api_key
    }
    try:
        response = requests.get(url, params=params)
        response.raise_for_status()  # Raise HTTPError for bad responses (4xx or 5xx)
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")
        return None

if __name__ == "__main__":
    asin = "B0CLTBHXWQ"
    marketplace_id = "A1PA6795UKMFR9"
    conversion_direction = "asin-to-ean"
    api_key = "YOUR_API_KEY"

    data = get_asin_converter(asin, marketplace_id, conversion_direction, api_key)
    if data and data['success']:
        print(json.dumps(data, indent=4))
    else:
        print("Failed to retrieve data.")

Example Response:


{
    "data": {
        "asin": "B0CLTBHXWQ",
        "eanList": [
            "0711719577294"
        ],
        "listedSince": "2023-12-30 01:00:00",
        "productTitle": "Playstation 5 Console Edizione Digital Slim"
    },
    "success": true
}

5. Estimating sales based on ASIN

You can estimate sales for the product using Amazon Product Estimate Sales. Here is a sample code to get an estimated monthly sales:


import requests

def get_estimated_sales(asin, marketplace_id, api_key):
    url = "https://sellermagnet-api.com/amazon-product-search-estimated-sells"
    params = {
        "asin": asin,
        "marketplaceId": marketplace_id,
        "api_key": api_key
    }

    try:
        response = requests.get(url, params=params)
        response.raise_for_status()  # Raises HTTPError for bad responses (4XX or 5XX)
        return response.json()
    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")
        return None

if __name__ == "__main__":
    asin = "B08N5WRWNW"
    marketplace_id = "A1PA6795UKMFR9"
    api_key = "YOUR_API_KEY"

    data = get_estimated_sales(asin, marketplace_id, api_key)
    if data and data['success']:
        print(f"Estimated Monthly Sales: {data['data']['estimated_monthly_sales']}")
    else:
        print("Failed to retrieve data.")

Example Response:


{
    "data": {
        "asin": "B08N5WRWNW",
        "estimated_monthly_sales": 121
    },
    "success": true
}

Key Considerations

  • API Usage Limits: Be mindful of your SellerMagnet API usage limits to avoid service disruptions. See Pricing
  • Error Handling: Implement robust error handling to gracefully manage API request failures.
  • Marketplace IDs: Ensure you use the correct Marketplace IDs for accurate data retrieval.

Conclusion

Building a Python script for Amazon competitor price monitoring empowers businesses with real-time data and automated insights. By leveraging SellerMagnet’s Amazon data API, you can streamline your competitive analysis, optimize pricing strategies, and gain a significant edge in the e-commerce market. Visit Documentation and Code Examples for more information and additional resources.

Back to Blog