Skip to main content

Official Python SDK for the BuyWhere Product Catalog API

Project description

BuyWhere Python SDK

Official Python SDK for the BuyWhere Product Catalog API — the agent-native product search API for Singapore.

Installation

pip install buywhere-sdk

Or from source:

pip install -e sdk/python/

Quickstart

from buywhere import BuyWhereClient

client = BuyWhereClient(api_key="key_xxx", base_url="http://143.198.87.39:8000")

# Search products in Singapore
results = client.products.search(q="iphone 15", country="sg", limit=10)
for r in results.results:
    print(r.title, r.price.amount, r.price.currency)

Usage

Sync client

from buywhere import BuyWhereClient

client = BuyWhereClient(api_key="key_xxx")

# Search products
results = client.products.search(q="iphone 15", country="sg", limit=10)

# Get product by ID
product = client.products.get(product_id="abc123")

# Compare prices across merchants
prices = client.products.compare_prices(product_id="abc123")
print(prices.best_price)

# List categories
categories = client.categories.list()

# Category detail
electronics = client.categories.get("electronics")
print(electronics.subcategories)

Async client

import asyncio
from buywhere import AsyncBuyWhereClient

async def main():
    async with AsyncBuyWhereClient(api_key="key_xxx") as client:
        results = await client.products.search(q="airfryer", country="sg")
        for r in results.results:
            print(r.title, r.price.amount)

asyncio.run(main())

Pagination

results = client.products.search(q="laptop", limit=10)
while results.has_more:
    results = client.products.search(q="laptop", limit=10, cursor=results.next_cursor)
    for r in results.results:
        print(r.title)

Filtering and sorting

results = client.products.search(
    q="headphones",
    category="electronics/audio",
    price_min=50.0,
    price_max=300.0,
    platform="shopee",
    sort="price_asc",
    limit=20,
)

Error handling

from buywhere import BuyWhereClient, NotFoundError, AuthenticationError, RateLimitError

client = BuyWhereClient(api_key="key_xxx")

try:
    product = client.products.get("does-not-exist")
except NotFoundError:
    print("Product not found")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError:
    print("Rate limited — retry later")

Configuration

Parameter Default Description
api_key (required) Your BuyWhere API key
base_url https://api.buywhere.io Override for staging/local
timeout 30.0 Request timeout in seconds

LangChain integration

BuyWhere ships a first-class LangChain tool so your agents can search the catalog in natural language.

pip install buywhere-sdk[langchain]
from buywhere import BuyWhereClient, BuyWhereTool
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, AgentType

client = BuyWhereClient(api_key="bw_...")
tool = BuyWhereTool(client=client, country="sg")
agent = initialize_agent([tool], ChatOpenAI(model="gpt-4o-mini"), agent=AgentType.OPENAI_FUNCTIONS, verbose=True)
agent.run("Find me noise-cancelling headphones under SGD 200 on Shopee")

The tool exposes structured inputs so the LLM can pass filters (category, price range, platform) directly:

# Use the tool directly without an agent
result = tool.run("wireless earbuds")
print(result)
# Found 48 products for 'wireless earbuds' (showing 5):
# 1. Sony WF-1000XM5
#    Price: SGD 279.00 (was 349.00)
#    Platform: shopee | Merchant: Sony Official Store
#    ...

Requirements

  • Python 3.9+
  • httpx >= 0.25
  • pydantic >= 2.0
  • langchain-core >= 0.1 (optional — only for BuyWhereTool)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

buywhere-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

buywhere-0.1.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file buywhere-0.1.0.tar.gz.

File metadata

  • Download URL: buywhere-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for buywhere-0.1.0.tar.gz
Algorithm Hash digest
SHA256 18acc461fe6b239cc933383a76b97902466547f07aa80b9c7ee907f6ceee2b0d
MD5 266dbe1c87e8ad55a105d34b7903f266
BLAKE2b-256 e0c9cef1c16290f597758aeaca495a3afb3b6453ff32c9c84f5dbd592ae440f3

See more details on using hashes here.

File details

Details for the file buywhere-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: buywhere-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for buywhere-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 afdcf5136b83555c8ad90306af7ec67e312a5326cd2baac3819ad76bdcf5fc0a
MD5 2d23fdc336637344785112ddfbbadf3b
BLAKE2b-256 e4ea8f746cb4b7b88f0a56f8eb88f525fc180d159765aa10aba4542999364684

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page