compsapi.com / guides python

eBay sold listings API in Python

Two short scripts and an error table: a first call with requests, then paging into a pandas table of monthly medians. Each script was run before it was published.

Short answer: install requests, put your key in the COMPSAPI_KEY environment variable, and send one GET to https://api.compsapi.com/v1/sold. Each request returns up to 240 completed eBay sales as JSON. A free key is 100 requests a month with no card.

A first call

import os
import requests

API = "https://api.compsapi.com/v1/sold"
HEADERS = {"Authorization": f"Bearer {os.environ['COMPSAPI_KEY']}"}

r = requests.get(API, headers=HEADERS, params={"q": "lego 75192", "days": 90, "size": 240}, timeout=60)
r.raise_for_status()
data = r.json()

print(data["count"], "sales, more pages:", data["next_page"])
for item in data["items"][:5]:
    print(item["last_sold"][:10], item["price"], item["format"], item["title"][:50])

Output on 27 November 2026:

234 sales, more pages: True
2026-11-27 821.12 FIXED_PRICE Lego 75192 Star Wars UCS Millennium Falcon | NEW S
2026-11-27 698.33 FIXED_PRICE LEGO Star Wars UCS Millennium Falcon 75192 BRAND N
2026-11-27 229.99 FIXED_PRICE 75192 UCS Millennium Falcon READ DESCRIPTION Star
2026-11-27 767.08 FIXED_PRICE LEGO Star Wars 75192 UCS Millenium Falcon NEU & OV
2026-11-27 42.68 FIXED_PRICE Lego UCS Millennium Falcon 75192 - Horizontal Wall

The fifth row is a wall mount, and the third says read the description. A plain keyword search returns everything with those words in the title, which is why the next script filters.

Paging into pandas

This one asks for new sets above $300 between January and October 2026, reads three pages and prints a median by month.

import os
import time
import pandas as pd
import requests

API = "https://api.compsapi.com/v1/sold"
HEADERS = {"Authorization": f"Bearer {os.environ['COMPSAPI_KEY']}"}


def sold(q, max_pages=3, **params):
    rows = []
    for page in range(1, max_pages + 1):
        r = requests.get(API, headers=HEADERS, params={"q": q, "size": 240, "page": page, **params}, timeout=120)
        if r.status_code == 429:
            time.sleep(int(r.headers.get("Retry-After", 5)))
            r = requests.get(API, headers=HEADERS, params={"q": q, "size": 240, "page": page, **params}, timeout=120)
        r.raise_for_status()
        data = r.json()
        rows += data["items"]
        if not data["next_page"]:
            break
        time.sleep(1)
    return pd.DataFrame(rows)


df = sold("lego 75192", condition="new", start="2026-01-01", end="2026-10-31", min_price=300)
df["last_sold"] = pd.to_datetime(df["last_sold"])

monthly = df.set_index("last_sold")["price"].resample("MS").agg(["count", "median"])
print(len(df), "sales")
print(monthly)

Output on 27 November 2026:

389 sales
                           count  median
last_sold
2026-08-01 00:00:00+00:00     40   700.0
2026-09-01 00:00:00+00:00    154   730.0
2026-10-01 00:00:00+00:00    195   750.0

Results come newest first, so three pages reached back from October to August. Raise max_pages to go further, or move start and end to the months you want and keep the page count low.

Parameters you will use most

ParameterWhat it does
qSearch words. Every word must be in the title. -case leaves a word out
days, or start and endHow far back, 1 to 1095, or a fixed window written YYYY-MM-DD
size, pageUp to 240 sales a page, then the next page while next_page is true
conditionnew, open_box, refurbished, used or parts
min_price, max_pricePrice range in USD
siteOne eBay site: US, UK, DE, FR, IT, ES, CA or AU
best_offer=1Flags sales that closed on an accepted offer
match=strict, exclude=junkLeave out the wrong model, lots and accessories

Errors worth handling

StatusMeaningWhat to do
400A missing or invalid parameter, or a search too broad to runFix the request or narrow the words
401Missing or invalid keyCheck the header
403Key expired, or the request had no User-AgentSend a User-Agent header
429Monthly quota used, or too many requests in a minuteOn a rate limit, wait the seconds in Retry-After
503A temporary problem on our sideRetry after a second or two

Every error body is JSON with "ok": false and a message. Failed searches do not count towards your quota.

requests sends its own User-Agent, so the 403 case does not come up with the scripts above. Keep the key in an environment variable, on your server, and out of the repository.

If a price is all you need

/v1/comps returns the median and the spread in one request, with no dataframe. The JavaScript guide covers the same ground with fetch.

Questions developers ask

How do I get eBay sold listings in Python? Call CompsAPI /v1/sold with requests: one GET with your key in the Authorization header and the search in q. The JSON answer has an items list with price, last_sold, title and url on each sale.

Is there a Python package to install? No package is needed. The API is one GET request, so requests is enough, and the pandas example on this page is about 30 lines.

How do I page through results? Send page=2, page=3 and so on while next_page is true. Each page holds up to 240 sales.

Can I still use ebaysdk findCompletedItems in Python? No. eBay switched the Finding API off in February 2025, so ebaysdk's findCompletedItems call no longer returns data.

Price from what things
actually sold for

100 free requests a month · every filter on · no card

eBay plus 12 more marketplaces on the same key

Get a free key