Price comparison across Amazon and Walmart helps shoppers save money and helps sellers identify pricing opportunities. Querying both platforms manually is slow and the data goes stale quickly. This tutorial builds an automated price comparison tool using the Scavio API that searches both Amazon and Walmart for the same product, normalizes prices, matches similar items across platforms, and outputs a side-by-side comparison showing which platform offers the better deal.
Prerequisites
- Python 3.10 or higher
- requests library installed
- A Scavio API key
- Products to compare across platforms
Walkthrough
Step 1: Query both platforms concurrently
Search Amazon and Walmart for the same product query simultaneously to minimize latency.
from concurrent.futures import ThreadPoolExecutor
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 compare(query: str) -> dict:
with ThreadPoolExecutor(max_workers=2) as ex:
a_fut = ex.submit(search_platform, "amazon", query)
w_fut = ex.submit(search_platform, "walmart", query)
return {"amazon": a_fut.result(), "walmart": w_fut.result()}Step 2: Parse and normalize prices
Extract prices from both platforms and convert to float values for comparison.
def parse_price(price_str: str) -> float | None:
if not price_str:
return None
return float(price_str.replace("$", "").replace(",", ""))
def normalize_product(product: dict, platform: str) -> dict:
return {
"platform": platform,
"title": product.get("title", ""),
"price": parse_price(product.get("price", "")),
"price_raw": product.get("price", ""),
"rating": product.get("rating"),
"url": product.get("url", product.get("link", "")),
}Step 3: Find the best price across platforms
Merge normalized results from both platforms and sort by price to find the best deal.
def best_deals(query: str, top_n: int = 10) -> list[dict]:
data = compare(query)
items = []
for p in data["amazon"][:10]:
items.append(normalize_product(p, "amazon"))
for p in data["walmart"][:10]:
items.append(normalize_product(p, "walmart"))
return sorted(items, key=lambda x: x["price"] or float("inf"))[:top_n]Step 4: Output comparison table
Print a formatted comparison table showing the best prices from each platform.
def print_comparison(query: str) -> None:
deals = best_deals(query)
print(f"Price comparison: {query}\n" + "-" * 60)
print(f"{'Platform':<10} {'Price':<10} {'Rating':<8} {'Title'}")
for d in deals:
price = f"${d['price']:.2f}" if d['price'] else 'N/A'
print(f"{d['platform']:<10} {price:<10} {d['rating'] or 'N/A':<8} {d['title'][:40]}")Python Example
import os
import requests
from concurrent.futures import ThreadPoolExecutor
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) -> None:
with ThreadPoolExecutor(max_workers=2) as ex:
a = ex.submit(search, "amazon", query)
w = ex.submit(search, "walmart", query)
items = []
for p in a.result()[:5]:
price = float(p.get("price", "0").replace("$", "").replace(",", "") or 0)
items.append({"src": "amazon", "price": price, "title": p.get("title", ""), "rating": p.get("rating")})
for p in w.result()[:5]:
price = float(p.get("price", "0").replace("$", "").replace(",", "") or 0)
items.append({"src": "walmart", "price": price, "title": p.get("title", ""), "rating": p.get("rating")})
items.sort(key=lambda x: x["price"] or float("inf"))
print(f"{'Source':<10} {'Price':<10} {'Rating':<8} {'Title'}")
for i in items:
print(f"{i['src']:<10} ${i['price']:<9.2f} {i['rating'] or 'N/A':<8} {i['title'][:40]}")
if __name__ == "__main__":
compare("AirPods Pro")JavaScript Example
const API_KEY = process.env.SCAVIO_API_KEY || "your_scavio_api_key";
const ENDPOINT = "https://api.scavio.dev/api/v1/search";
async function search(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 => ({
src: platform,
title: p.title,
price: p.price ? parseFloat(p.price.replace(/[$,]/g, "")) : null,
rating: p.rating
}));
}
async function compare(query) {
const [amazon, walmart] = await Promise.all([
search("amazon", query), search("walmart", query)
]);
const all = [...amazon, ...walmart].sort((a, b) => (a.price || Infinity) - (b.price || Infinity));
console.log(`Price comparison: ${query}`);
all.forEach(i => console.log(`${i.src.padEnd(10)} $${i.price?.toFixed(2) || 'N/A'.padEnd(9)} ${i.title?.slice(0, 40)}`));
}
compare("AirPods Pro").catch(console.error);Expected Output
Source Price Rating Title
amazon $189.00 4.7 Apple AirPods Pro (2nd Generation)
walmart $189.00 4.7 Apple AirPods Pro 2nd Gen with USB-C
amazon $199.99 4.6 Apple AirPods Pro with MagSafe Case
walmart $199.00 4.5 Apple AirPods Pro 2 Wireless Earbuds
amazon $234.99 4.8 Apple AirPods Pro Premium Bundle