🛍️ Amazon Product Search Library 📦
Overview
Tired of manually browsing Amazon for the best deals? 🌐 Meet Amazon Product Search — your trusty Python library to scrape product listings and detail pages from Amazon with just a few lines of code. Powered by curl_cffi browser impersonation (so Amazon's bot filter doesn't return a 503 error page) and BeautifulSoup4 (bs4) for parsing, with optional async requests for speed. 🎉
Key Features
- Product Search: Search for products by name, type, brand, and price range. 📱💻
- Detailed Data: Scrape titles, prices (+currency), reviews (+count), images, and URLs. 🎯
- Deep Scrape: Fetch a product detail page for brand, rating, availability, feature bullets, specs, gallery images, and variations through a stable, generalized schema. 🕵️
- Pagination: Navigate Amazon pages via
pageparam and getcurrent_page/total_pagesfromdata-csa-c-content-id="pagination-button". 📄 - Fast and Efficient: Session reuse (keep-alive),
SoupStrainerpartial parsing, and optionalasync_search()for overlapping network I/O. - Anti-bot: Ships
curl_cffiTLS/HTTP2 browser impersonation with automatic profile rotation and retry, so Amazon's "Sorry! Something went wrong!" 503 page doesn't reach you. 🛡️ - Easy-to-use: Simple API + context-manager + backward-compatible iteration. ✨
- Lightweight & Compatible: Python 3.9–3.14, relaxed deps (
beautifulsoup4>=4.11,curl_cffi>=0.13,lxml>=4.9). No heavy frameworks.
Setup 🛠️
1. Install via PyPI (Recommended) 🧑💻
pip install amazon-product-search-v2
Installs the latest stable release. Package name on PyPI is amazon-product-search-v2.
2. Install via GitHub (For Developers) 🦸♂️
git clone --depth 1 https://github.com/ManojPanda3/amazon-product-search
cd amazon-product-search
pip install -e .
# or with venv: python -m pip install -e .
Usage 📚
Import
from amazon_product_search import (
Amazon,
AmazonProduct,
AmazonProductDetails,
AmazonResult,
)
# Package is amazon-product-search-v2 on PyPI, but import stays amazon_product_search
Basic Search
from amazon_product_search import Amazon
# Session is reused across searches (keep-alive). Use as context manager to auto-close.
with Amazon() as amazon:
result = amazon.search("thinkpad", productType="electronics", page=1)
# or: amazon = Amazon(); result = amazon.search(...); amazon.close()
print(result.current_page, "/", result.total_pages)
for prod in result.products:
print(prod.title, prod.price, prod.currency)
print(prod.get()) # dict with title/link/review/review_numbers/currency/price/image
Or one-off:
amazon = Amazon(is_debuging=False, workers=4)
result = amazon.search(productName="iPhone", productType="electronics", brand="Apple", priceRange="80000-100000", page=2)
# result is AmazonResult — also iterable/len-compatible
print(len(result)) # == len(result.products)
for product in result: # iterates products directly
print(product.get())
Deep-scrape a product page 🕵️
AmazonProduct.deep_scrape() fetches a product detail page and returns an
AmazonProductDetails object. Amazon renders different widgets for different
products, so the result uses one generalized schema: missing scalars are
None, missing lists are [], and missing mappings are {} — the keys are
always present.
from amazon_product_search import AmazonProduct
product = AmazonProduct(link="https://www.amazon.com/dp/B073CWSQ51")
details = product.deep_scrape()
print(details.title, details.brand, details.rating)
print(details.price, details.price_value, details.currency)
print(details.availability)
print(details.features)
print(details.specifications) # {"Brand Name": "COLOR WOW", ...}
print(details.product_details) # {"Item model number": "CW527", ...}
print(details.images)
print(details.variations) # size/colour options with ASIN + price
print(details.get()) # JSON-serialisable dict
Fields:
| Group | Fields |
|---|---|
| Identity | asin, title, brand, link, breadcrumbs |
| Offer | price (display string), price_value (float), currency, availability |
| Social proof | rating, review_count, best_sellers_rank |
| Content | features, specifications, product_details |
| Media | main_image, images |
| Variations | variations (dimension, value, asin, selected, available, price, price_value, image, url) |
Notes:
priceis the display string Amazon rendered (for example"$1,299.99"); useprice_valuewhen you need a float. A page can provide a currency symbol without a buy-box price, socurrencymay be set while both price fields areNone.specificationsandproduct_detailsare free-form key/value maps because every category uses different labels. Common keys includeBrand Name,Item model number,Product Dimensions, andBest Sellers Rank.get()always returns the same keys, so the result can be serialized directly to JSON.
Saved HTML and local files are supported, which is handy for tests:
details = product.deep_scrape(html=saved_html)
# or point the product at a file
details = AmazonProduct(link="/path/to/product.html").deep_scrape()
Async Search (overlapping network I/O) 🐍
Searching Amazon is dominated by network wait, so async_search() lets you run several searches at once. It performs one search per call; batch them yourself with asyncio.gather() or a task group.
import asyncio
from amazon_product_search import Amazon
async def main():
async with Amazon() as amazon:
results = await asyncio.gather(
amazon.async_search("thinkpad", productType="electronics"),
amazon.async_search("macbook air"),
amazon.async_search("dell xps"),
)
for result in results:
print(result.current_page, len(result.products))
asyncio.run(main())
Notes:
async_search()takes the same parameters and returns the sameAmazonResultassearch().- Parsing runs off the event loop, so one large page won't stall your other searches.
- Non-200 responses and network failures are logged and raise
ValueError, matchingsearch().
Parameters for search()
productName(str, required): Search term (e.g."thinkpad","laptop").productType(str, optional):ifilter (e.g."electronics","books").brand(str, optional): Brand filter.priceRange(str, optional):"min-max"(e.g."100-200").page(int, optional, default0): New in v0.1.2 — 1-indexed page.0or1= first page (nopageparam sent),2→?page=2.
Returns
AmazonResult dataclass:
@dataclass
class AmazonResult:
products: list[AmazonProduct]
current_page: int
total_pages: int
def get() -> dict: ... # {products: [...], current_page, total_pages}
Each AmazonProduct:
@dataclass
class AmazonProduct:
title: str | None
link: str | None # https://www.amazon.com/dp/...
review: str | None # "4.5 out of 5 stars" (None when missing)
review_numbers: int | None # 1234 (parentheses stripped; k/m/b suffixes converted)
price: float | None # 12.99 (commas stripped)
currency: str | None # "$" / "₹" etc. (split on \u00a0)
image: str | None
def get() -> dict: ...
Backward compat: for p in result, len(result), result[i] all proxy to result.products.
AmazonProduct.deep_scrape() returns AmazonProductDetails:
@dataclass
class AmazonProductDetails:
asin: str | None
title: str | None
brand: str | None
link: str | None
breadcrumbs: list[str]
price: str | None # display text, e.g. "$1,299.99"
price_value: float | None # parsed numeric value
currency: str | None
availability: str | None
rating: float | None
review_count: int | None
best_sellers_rank: list[str]
features: list[str]
specifications: dict[str, str]
product_details: dict[str, str]
main_image: str | None
images: list[str]
variations: list[dict]
def get() -> dict: ... # same keys for every product
Examples
Paginated search (new syntax)
from amazon_product_search import Amazon
import json
with Amazon() as amazon:
# Page 1
r1 = amazon.search("thinkpad", productType="electronics", page=1)
print(f"Page {r1.current_page} of {r1.total_pages} — {len(r1)} products")
# Page 2
r2 = amazon.search("thinkpad", productType="electronics", page=2)
print(json.dumps(r2.get(), indent=2))
Iterate all pages
amazon = Amazon()
page = 1
all_products = []
while True:
res = amazon.search("laptop", page=page)
all_products.extend(res.products)
if res.current_page >= res.total_pages:
break
page += 1
print(f"Collected {len(all_products)} across {res.total_pages} pages")
amazon.close()
Old-style loop (still works)
res = amazon.search("iPhone")
for product in res: # or res.products
d = product.get()
print(f"Title: {d['title']}")
print(f"Price: {d['currency']}{d['price']}")
print(f"Review: {d['review']} ({d['review_numbers']})")
print(f"Link: {d['link']}")
print("-" * 40)
How It Works 🔍
- URL building:
urllib.parse.urlencodesafely encodesk,i,brand,price,page. - Request:
curl_cffiwith browser impersonation (real TLS/HTTP2 fingerprint), session reuse (keep-alive), 20s timeout. A blocked attempt is retried under a different browser fingerprint with exponential backoff. - Parse products:
SoupStrainer("div", {"data-component-type":"s-search-result"})+lxml— only product divs are parsed. - Parse pagination:
SoupStrainer("div", {"data-csa-c-content-id":"pagination-button"})→ readsspan.s-pagination-selected(current) and maxa/span.s-pagination-itemnumeric (total, e.g.260). - Extract: runs
extract_data(title/link/review/price/image) per div. Extraction is single-threaded on purpose: parsing holds the GIL, and a thread pool measured slower than a plain loop. - Return:
AmazonResult(products, current_page, total_pages).
Deep-scrape pipeline
AmazonProduct.deep_scrape(html=None) handles the much larger, variable
product-detail document separately:
- Source: explicit
html=wins. Otherwiselinkis read from disk when it is a file, or fetched once withcurl_cffi(chrome124, 20s timeout, redirects,Accept-Language) and checked withraise_for_status(). - Base URL: an HTTP(S)
linkis kept; otherwise the canonical/OG URL is used, falling back tohttps://www.amazon.com, so relative image and variation URLs become absolute. - Sections: identity (title, ASIN, brand, breadcrumbs), offer
(price/currency/availability), social proof (
#acrPopover, review count), content (#feature-bullets, detail bullets, spec tables), media (#landingImage+ gallery JSON), and variations (desktop-twister-sort-filter-data). - Projection: always returns
AmazonProductDetailswith every key present. Missing sections becomeNone,[], or{}; absent markup never raises.pricekeeps Amazon's display text whileprice_valueis numeric. - Return:
.get()is anasdict()view, ready forjson.dumps().
Unlike search(), deep_scrape() makes a single direct request and does
not go through Transport's fingerprint rotation/retry loop.
What's New in v0.1.3
- Deep scrape:
AmazonProduct.deep_scrape()now returns an exportedAmazonProductDetailswith a generalized detail-page schema (identity, offer, social proof, features/specs, media, variations). Missing sections stayNone/[]/{}; saved HTML and local files are supported throughhtml=or a file path inlink. - Anti-bot fix:
requests/httpxreplaced bycurl_cffibrowser impersonation, which is what stops Amazon serving the503"Sorry! Something went wrong!" page. Adds block detection by body markers (catches the200interstitial challenge), fingerprint rotation with exponential backoff, and a per-loop async session. Breaking-ish: transport deps changed (requests/httpx→curl_cffi); publicAmazonAPI is unchanged apart from the new optionaltimeout/max_attempts/backoffargs. - Typed fields:
priceis nowfloat | None(commas stripped,0.0fallback — never raises) andreview_numbersisint | None(k/m/bsuffixes converted, e.g."1.2K"→1200; missing count →0). - Workers: default is now
(os.cpu_count() or 4) // 2instead of fixed4. - Version: 0.1.2 → 0.1.3.
- See
docs/ARCHITECTURE.mdanddocs/SELECTORS.mdfor the full contract, anddocs/TESTING.mdfor the test suite.
What's New in v0.1.2
- Pagination:
Amazon.search(..., page=N)+AmazonResult.current_page / total_pagesviadata-csa-c-content-id="pagination-button". - Performance: session keep-alive,
SoupStrainerpartial parsing, early-exit on empty results, cachedfind()inget_title. - Robustness: Broader
RequestExceptioncatch, NBSP-safe price split,image.get("src")type-safe,review_numbersparen-stripping. - Compatibility & Lightweight:
from __future__ import annotationsfor Python 3.7–3.14; deps relaxed tobeautifulsoup4>=4.11,requests>=2.28,lxml>=4.9(was pinned==). Superseded: these were later replaced bycurl_cffi— see v0.1.3.* - DX:
AmazonResultiterable/len/indexable,.get()dict,Amazoncontext manager (with Amazon() as a:+close()), version bump 0.1.1→0.1.2.
Anti-bot transport 🛡️
Amazon blocks scrapers on the TLS/HTTP2 fingerprint, not just headers. A
plain requests/httpx call gets a 503 "Sorry! Something went wrong!" page
(or a 200 interstitial containing bm-verify) that parses to zero products.
This library uses curl_cffi to impersonate a real browser, which is the fix.
On top of impersonation it:
- detects challenge pages by body markers, not just status code — the
bm-verifyinterstitial arrives as200; - rotates browser fingerprints across attempts (blocks follow the fingerprint, not the URL) with exponential backoff;
- sends no hand-written
User-Agent, since one that disagrees with the TLS fingerprint is itself a detection signal.
Tunable via the constructor:
Amazon(timeout=20, max_attempts=4, backoff=0.4)
max_attempts is capped at the number of profiles (6). When all attempts fail
you get ValueError: Error while geting data from Amazon; TransportError is
exported if you want to catch the underlying cause.
Important Notes ⚠️
- Rate Limiting: heavy concurrent scraping can still get you blocked, and no fingerprint trick makes that impossible. Add delays / proxies for bulk work.
- ToS: Scraping may violate Amazon ToS — personal/educational use only.
- Site Changes: Search-result selectors (
data-cy="title-recipe",data-component-type="s-product-image", etc.) and detail-page selectors (#productTitle,#feature-bullets,#detailBullets_feature_div, etc.) may need updates if Amazon changes markup. Seedocs/SELECTORS.md.
Troubleshooting 🛠️
ValueError: Error product Name is required— provideproductName.ValueError: Error while geting data from Amazon— every attempt was blocked or errored. Run withAmazon(is_debuging=True)to see which fingerprint was rejected per attempt, then tryAmazon(max_attempts=6)for a wider rotation.- Empty
products— no match or HTML changed; check pagination (total_pages) and try differentpage. Nonefields — normal (Amazon varies per product).ModuleNotFoundError: No module named 'amazon_product_search'—pip install amazon-product-search-v2in correct venv.ValueError: link is not validfromdeep_scrape()— pass a product URL, a readable local HTML file path, orhtml=....deep_scrape()returns mostlyNone/ empty fields — the page may be a bot challenge, an unavailable product, or saved HTML without detail markup. Compare againstdocs/SELECTORS.md.priceisNonebutcurrencyis set — Amazon rendered a currency symbol but no buy-box price for that location/session;price_valueis alsoNone.
Contributing 🤝
PRs welcome! Open an issue or submit a pull request.
License 📜
MIT — see LICENSE.
Metadata
Release files for amazon-product-search-v2 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| amazon_product_search_v2-0.1.3.tar.gz | 43.2 kB | With provenance | Details for amazon_product_search_v2-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| amazon_product_search_v2-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for amazon_product_search_v2-0.1.3-py3-none-any.whl |
Total release size: 70.4 kB
Release files / amazon_product_search_v2-0.1.3.tar.gz
| Download URL | amazon_product_search_v2-0.1.3.tar.gz |
|---|---|
| Size | 43.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ffc96f83fc16acf41edde371167a54488ccb4054f9b2fc9555fd9b68c922e62e
|
|
BLAKE2b-256 checksum How to use checksums |
072e42e882fd3b24b162fd4c88d5a901745fce9be73dcba33693b9c0f0ab3d3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logRelease files / amazon_product_search_v2-0.1.3-py3-none-any.whl
| Download URL | amazon_product_search_v2-0.1.3-py3-none-any.whl |
|---|---|
| Size | 27.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f77f76cb76d2f11e9ef6f162c6f3da12c18d9d5dd59649e51066c277468f3e3
|
|
BLAKE2b-256 checksum How to use checksums |
02786c4838c6ae53cb7ce641e600cda8f4500ec6d3fe1fb377ea0fd65c8b5dd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logSecurity for amazon-product-search-v2 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for amazon_product_search_v2-0.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.