Tutorial

How to Build a Price Comparison Tool for Amazon and Walmart

Build a cross-platform price comparison tool in Python that queries both Amazon and Walmart via the Scavio API and returns the best price for any product.

Price comparison tools help shoppers and resellers find the best deal across multiple retailers. Building one requires querying multiple platforms, normalizing price formats, and ranking results by value. The Scavio API covers both Amazon and Walmart with a unified endpoint, making it straightforward to query both platforms and compare results side by side. This tutorial builds a comparison function that accepts a product name, queries both platforms in parallel, and returns a sorted list of offers.

Prerequisites

  • Python 3.10 or higher
  • requests and concurrent.futures (stdlib) available
  • A Scavio API key
  • Basic understanding of async or concurrent programming

Walkthrough

Step 1: Query both platforms concurrently

Use concurrent.futures.ThreadPoolExecutor to query Amazon and Walmart at the same time, reducing total latency.

Python
from concurrent.futures import ThreadPoolExecutor, as_completed

def search_platform(platform: str, query: str) -> list[dict]:
    r = requests.post(
        "https://api.scavio.dev/api/v1/search",
        headers={"x-api-key": API_KEY},
        json={"platform": platform, "query": query, "marketplace": "US"}
    )
    r.raise_for_status()
    return r.json().get("products", [])

def fetch_both(query: str) -> dict:
    with ThreadPoolExecutor(max_workers=2) as ex:
        futures = {ex.submit(search_platform, p, query): p for p in ["amazon", "walmart"]}
        return {futures[f]: f.result() for f in as_completed(futures)}

Step 2: Normalize prices across platforms

Both platforms return price as a string like "$29.99". Parse them into floats for comparison.

Python
def normalize(product: dict, source: str) -> dict:
    price_str = product.get("price", "")
    price = float(price_str.replace("$", "").replace(",", "")) if price_str else None
    return {"source": source, "title": product.get("title"), "price": price, "raw": price_str}

Step 3: Merge and sort results

Combine results from both platforms into one list and sort by price ascending.

Python
def compare(query: str) -> list[dict]:
    results = fetch_both(query)
    items = []
    for source, products in results.items():
        items.extend(normalize(p, source) for p in products[:5])
    return sorted(items, key=lambda x: x["price"] or float("inf"))

Step 4: Display the comparison table

Print a formatted table showing the best price for the product across both platforms.

Python
offers = compare("Sony WH-1000XM5")
print(f"{'Source':<10} {'Price':<10} {'Title'}")
for o in offers[:6]:
    print(f"{o['source']:<10} {o['raw']:<10} {o['title'][:50]}")

Python Example

Python
import os
import requests
from concurrent.futures import ThreadPoolExecutor, as_completed

API_KEY = os.environ.get("SCAVIO_API_KEY", "your_scavio_api_key")
ENDPOINT = "https://api.scavio.dev/api/v1/search"

def search(platform: str, query: str) -> list[dict]:
    r = requests.post(ENDPOINT, headers={"x-api-key": API_KEY},
                      json={"platform": platform, "query": query, "marketplace": "US"})
    r.raise_for_status()
    return r.json().get("products", [])

def compare(query: str) -> list[dict]:
    with ThreadPoolExecutor(max_workers=2) as ex:
        futs = {ex.submit(search, p, query): p for p in ["amazon", "walmart"]}
        all_items = []
        for f in as_completed(futs):
            src = futs[f]
            for p in f.result()[:5]:
                price_str = p.get("price", "")
                price = float(price_str.replace("$", "").replace(",", "")) if price_str else None
                all_items.append({"source": src, "price": price, "raw": price_str, "title": p.get("title", "")})
    return sorted(all_items, key=lambda x: x["price"] or float("inf"))

if __name__ == "__main__":
    for o in compare("Sony WH-1000XM5")[:6]:
        print(f"{o['source']:<10} {o['raw']:<10} {o['title'][:50]}")

JavaScript Example

JavaScript
const API_KEY = process.env.SCAVIO_API_KEY || "your_scavio_api_key";
const ENDPOINT = "https://api.scavio.dev/api/v1/search";

async function searchPlatform(platform, query) {
  const res = await fetch(ENDPOINT, {
    method: "POST",
    headers: { "x-api-key": API_KEY, "Content-Type": "application/json" },
    body: JSON.stringify({ platform, query, marketplace: "US" })
  });
  const data = await res.json();
  return (data.products || []).slice(0, 5).map(p => ({ source: platform, ...p }));
}

async function compare(query) {
  const [amazon, walmart] = await Promise.all([
    searchPlatform("amazon", query),
    searchPlatform("walmart", query)
  ]);
  const all = [...amazon, ...walmart];
  return all.sort((a, b) => {
    const pa = parseFloat((a.price || "").replace(/[$,]/g, "")) || Infinity;
    const pb = parseFloat((b.price || "").replace(/[$,]/g, "")) || Infinity;
    return pa - pb;
  });
}

compare("Sony WH-1000XM5").then(results => {
  results.slice(0, 6).forEach(r => console.log(`${r.source}: ${r.price} — ${r.title?.slice(0, 50)}`));
}).catch(console.error);

Expected Output

JSON
amazon     $279.00    Sony WH-1000XM5 Wireless Noise Canceling Headphones
amazon     $289.99    Sony WH-1000XM5 Wireless Headphones (Midnight Black)
walmart    $279.00    Sony WH1000XM5 Bluetooth Headphones
walmart    $299.00    Sony WH-1000XM5 Premium Wireless Headphones

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Python 3.10 or higher. requests and concurrent.futures (stdlib) available. A Scavio API key. Basic understanding of async or concurrent programming. A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

Build a cross-platform price comparison tool in Python that queries both Amazon and Walmart via the Scavio API and returns the best price for any product.