Metadata-Version: 2.5
Name: pkmnprices
Version: 5.0.0
Summary: Python client for the Pkmn Prices API
Project-URL: Homepage, https://pkmnprices.com
Project-URL: Repository, https://github.com/preaverage/pkmnprices-py
Project-URL: Issues, https://github.com/preaverage/pkmnprices-py/issues
Author: Pkmn Prices
License-Expression: MIT
License-File: LICENSE
Keywords: api-client,cardmarket,ebay,pokemon,pricing,sdk,tcg,tcgplayer
Classifier: Programming Language :: Python :: 3
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Description-Content-Type: text/markdown

# pkmnprices

Python client for the [Pkmn Prices API](https://pkmnprices.com). Pokemon TCG card pricing from TCGPlayer, Cardmarket, and eBay.

Sync and async clients, both built on httpx. Typed responses, typed errors, and iterators that page through results for you. Python 3.10+.

## Install

```bash
pip install pkmnprices
```

## Usage

```python
from pkmnprices import PkmnPrices

client = PkmnPrices("pk_your_key_here")

page = client.cards.list(name="charizard", per_page=10)

card = client.cards.get(page.data[0].id)
for price in card.prices:
    symbol = "€" if price.currency == "EUR" else "$"
    print(f"{price.source}: {symbol}{price.market_price}")

client.close()
```

The client is also a context manager:

```python
with PkmnPrices("pk_...") as client:
    health = client.health()
```

### Async

```python
import asyncio
from pkmnprices import AsyncPkmnPrices

async def main():
    async with AsyncPkmnPrices("pk_...") as client:
        page = await client.cards.list(name="charizard")
        async for card in client.cards.iterate(name="charizard"):
            print(card.name)

asyncio.run(main())
```

Get an API key from <https://pkmnprices.com/dashboard>.

## Options

```python
PkmnPrices(
    "pk_...",         # API key, sent as the x-api-key header
    max_retries=2,    # retries on 429 rate limits and 5xx/network errors
    timeout=30.0,     # per-request timeout in seconds
)
```

Rate-limit `429`s are retried with backoff. Credit-limit `429`s (`credit_limit_exceeded`) are not, since they don't reset until the next day.

## Pagination

List endpoints return a `Page` (`.data`, `.pagination`). Listing endpoints (eBay, Cardmarket, and TCGplayer) return a `CursorPage`. Both resources expose iterators so you don't track pages or cursors:

```python
for card in client.cards.iterate(name="charizard"):
    print(card.name)

all_sets = client.sets.list_all(language="english")

for sale in client.cards.listings.iterate_ebay(789, graded=True, grader="PSA", grade="10"):
    print(sale.title, sale.price)

for offer in client.cards.listings.iterate_cardmarket(789, condition="Near Mint", variant="Reverse Holo"):
    print(offer.seller, offer.price, offer.language)

for offer in client.cards.listings.iterate_tcgplayer(789, condition="Near Mint"):
    print(offer.seller_name, offer.price, offer.shipping_price)
```

TCGplayer offers default to `price_asc`, item price alone, so the first row can
be a low-price, high-shipping offer that is not the cheapest to buy. `total_asc`
and `total_desc` order by `price + shipping_price`, which is how TCGplayer's own
site orders offers:

```python
for offer in client.cards.listings.iterate_tcgplayer(789, sort="total_asc"):
    print(offer.price + (offer.shipping_price or 0), offer.seller_name)
```

A cursor is bound to the sort family it was issued under, so do not reuse a
`total_*` cursor with a `price_*` sort or the reverse. `min_price` and
`max_price` filter item price under every sort.

The set, card and sealed lists also page by keyset. Each page carries
`pagination.next_cursor`, and passing it back as `cursor` reads the next page
without an offset, so page 500 costs what page 1 does and a card added mid-walk
is neither repeated nor skipped. `iterate()` and `list_all()` follow the cursor
for you. To do it by hand:

```python
page = client.cards.list(set_id=123, per_page=100)
while page.pagination.next_cursor:
    page = client.cards.list(set_id=123, per_page=100, cursor=page.pagination.next_cursor)
```

Send `cursor` or `page`, not both. Lists filtered or sorted by price
(`min_price`, `max_price`, `condition`, `variant`, `sort`) have no cursor:
`next_cursor` is `None` there and the iterators page by number.

Sealed products carry the same three listing sources, under `client.sealed.listings`:

```python
for offer in client.sealed.listings.iterate_tcgplayer(5678):
    print(offer.seller_name, offer.price, offer.quantity)

for offer in client.sealed.listings.iterate_cardmarket(5678):
    print(offer.seller, offer.price, offer.opened)

for sale in client.sealed.listings.iterate_ebay(5678, sort="price_desc"):
    print(sale.title, sale.price, sale.sold_at)
```

Sealed Cardmarket offers take no `variant`: every sealed row is written with an
empty one, so the filter could only ever exclude everything. They are also
single-language: the offers returned are the ones in the set's own language, so
a Cardmarket product page showing offers in other languages lists more than this
endpoint does.

Sealed TCGplayer offers are normally condition `"Unopened"` with an empty
`printing`, so those two filters rarely narrow anything. Sealed eBay sales are
never graded, so `graded`, `grader`, and `grade` aren't accepted there and
`grader`/`grade` come back `None`. The async client mirrors all of these on
`AsyncPkmnPrices`.

## Card markers

Some printings differ from the base card only by a foil pattern, a stamp, or
how the copy was handed out. Cards carry those as `pattern`, `stamp`,
`stamp_number`, `distribution` and `placement`, each `None` on a card without
one, and the card list filters on four of them:

```python
staff = client.cards.list(distribution="Staff")
poke_ball = client.cards.list(set_id=123, pattern="Poke Ball Pattern")
```

The filters match exactly as the values are spelled in responses.
`client.cards.markers()` returns every value each filter accepts, with how many
cards carry it:

```python
markers = client.cards.markers()
print(markers.stamps[0].value, markers.stamps[0].cards)
```

The card list also filters on `artist` (a case-insensitive substring) and `hp`.

## Which card a comp is really about

A variant and its base card can map to one source product page. When that
happens, both serve the same sales, and the titles describe whichever printing
the seller actually sold. Every eBay comp says which case it is:

```python
for sale in client.cards.listings.iterate_ebay(17679):
    if sale.attribution == "shared":
        continue  # another card's evidence
    print(sale.variant, sale.title, sale.price)
```

`exact` means the source page belongs to this card alone. `shared` means the
sale appears under at least one other card too, so it prices the group rather
than this entity. `unknown` means no printing is recorded for the comp: it was
collected before printings were recorded, or its title did not narrow the sale
to one printing. A feed that is entirely `shared` is not evidence about
the card you asked for.

`variant` also works as a filter, so a card mapped for more than one printing
can be read one printing at a time:

```python
holo = client.cards.listings.all_ebay(789, variant="Holofoil")
```

## Two grades can print the same number

A CGC Pristine 10 and a CGC Gem Mint 10 both carry `grade == "10"`, and so do
a BGS Black Label 10 and a plain BGS 10. The higher tier sells well above the
lower one, so `grade_qualifier` tells them apart: `"Pristine"`, `"Black Label"`,
or `None` for the tier with no name of its own, which is nearly every comp.
Filtering `grade="10"` returns every tier. To get one tier, add
`grade_qualifier`:

```python
black_labels = client.cards.listings.all_ebay(
    789, grader="BGS", grade="10", grade_qualifier="black_label",
)
plain_tens = client.cards.listings.all_ebay(
    789, grader="BGS", grade="10", grade_qualifier="none",
)
```

`"none"` also returns comps whose tier was never recorded.

## Comp currency, seller country and sale type

eBay comps carry their own `currency`. Card comps from ebay.com are USD, and
German and Spanish card comps from ebay.de and ebay.es are EUR, so read it per
row rather than assuming dollars. Sealed comps are always USD.

`seller_country` is the seller's location as an ISO 3166-1 alpha-2 code
(`"US"`, `"JP"`, `"GB"`), or `None` when it isn't known. Cardmarket offers
carry it too, read from the offer's item-location flag. Both listing feeds
accept the same two filters, as a list or a comma-separated string of up to
30 codes:

```python
domestic = client.cards.listings.all_ebay(789, seller_country=["US", "PR"])
no_china = client.cards.listings.all_cardmarket(789, exclude_seller_country="CN,HK")
```

`seller_country` leaves out rows with no known country; `exclude_seller_country`
keeps them. A malformed code raises `BadRequestError`.

`sale_type` says how an eBay comp sold: `"auction"`, `"fixed_price"` or
`"best_offer_accepted"`. For an accepted offer, `price` is what the buyer paid,
not the list price. It is `None` on older comps, comps mirrored from
PriceCharting and sealed comps, and some older accepted offers still carry the
list price with nothing marking them. Any `sale_type` filter drops the `None`
rows, so passing all three values keeps only comps whose sale type is known:

```python
auctions = client.cards.listings.all_ebay(789, sale_type="auction")
known = client.cards.listings.all_ebay(
    789, sale_type=["auction", "fixed_price", "best_offer_accepted"],
)
```

## Polling for new comps

Credits are charged per row returned, so re-reading a page of comps you already
hold to find out that nothing changed is the expensive way to stay current.
`since` returns only what arrived after a point you name:

```python
checkpoint = "2026-09-01T02:40:15.126147Z"

page = client.cards.listings.ebay(789, since=checkpoint)
for sale in page.data:
    print(sale.title, sale.price)
if page.data:
    checkpoint = page.data[0].ingested_at
```

Checkpoint on `ingested_at`, not `sold_at`. They are different: `sold_at` is
when the sale happened, `ingested_at` is when we collected it, and a collection
run regularly brings in sales that are weeks old. A sale-date bound would step
over those permanently.

The bound is exclusive, so passing back the `ingested_at` you were given never
repeats that row. `since` also accepts a bare `YYYY-MM-DD` (midnight UTC),
which suits a backfill more than a poll: re-running it the same day returns the
same rows, and pays for them again.

A card with nothing new returns an empty `data` list.

### Corrections

Comps are sometimes fixed after they go in: a slab regraded because the title
was misread, an accepted offer's list price replaced with what the buyer paid,
a sale moved to the card it was really for. A fix does not move `ingested_at`,
so `since` never returns it. If you store comps, poll `updated_since` as well
and replace your copy by `id`:

```python
fixed = client.cards.listings.all_ebay(789, updated_since="2026-11-01T00:00:00Z")
```

`updated_at` on each row says when it changed. It is `None` on comps that
haven't changed since 2026-10-20, when corrections began being recorded, and on
every sealed comp. Removed comps aren't reported: a deleted comp stops
appearing.

### `period` is for pricing

`period="90d"` returns comps that sold in the last 90 days, under any sort, so
this is the cheapest recent PSA 10:

```python
page = client.cards.listings.ebay(
    789, grader="PSA", grade="10", period="90d", sort="price_asc",
)
```

Don't poll on `period`. Comps often arrive days after the sale, and a late one
would fall outside your next window. Use `since` to sync and `period` to price;
the two combine.

## eBay sales volume

`sales_volume()` counts the same eBay comps by day, which is cheaper than
listing them when you only need to know how often a card trades:

```python
for day in client.cards.sales_volume(789, period="90d", graded=False).data:
    print(day.date, day.sales, day.median)
```

A row is one day, currency, variant and graded group, newest day first, so a
card sold both raw and graded has two rows for a day. `sales` counts every
comp. `priced_sales` and `median` leave out accepted Best Offers. `variant` is
`None` when the title did not narrow the sale to one printing.

This is eBay only. TCGplayer and Cardmarket sales are not recorded, so a day
with no row means no eBay comp that day. Pro plan and up.

## Graded population

`population()` returns how many copies of a card PSA, BGS, SGC and CGC have
graded, per variant:

```python
for pop in client.cards.population(12927).variants:
    print(pop.variant, pop.total_population, pop.grades.get("10"), pop.gem_rate)
    psa = pop.graders.get("PSA")
    print(psa.total if psa else 0, pop.percent_higher.get("8.5"))
```

`grades` is keyed `"1"` to `"10"` with halves as `"8.5"`. Pristine and Black
Label tens are separate fields above `"10"`. `percent_higher["8.5"]` is the
share of graded copies that came back a 9 or better, the usual input to a
grading ROI estimate.

A variant that could not be tied to its population records is left out, so
`variants` can be shorter than the card's variant list, or empty. An empty list
is not a population of zero. One credit per request, Pro plan and up.

## Catalog export

On Scale and Business, `export()` downloads the whole price catalog as one
gzipped CSV, so a job that needs every card doesn't have to page the card list:

```python
export = client.cards.export("cards.csv.gz")
print(export.path, export.downloads_remaining)
```

Leave the path off and the file takes the server's name, such as
`pkmnprices-cards-2026-10-26.csv.gz`, in the working directory.

One row per card, currency, condition and variant, with the current raw market
price. Columns: `card_id, tcgplayer_id, name, number, set_number, rarity,
set_id, set, language, currency, condition, variant, market_price`.

The export is not charged in credits. Each account can download it twice per
UTC day, so the client never retries it for you, and `downloads_remaining` says
how many downloads are left. Prices update once a day, so a second download the
same day returns the same numbers.

## TCGplayer freshness

`updated_at` on a TCGplayer offer is not a freshness signal. It moves only when
that listing's own price, quantity or seller details change, so an offer that
has been live and unchanged for a month keeps a month-old `updated_at` however
recently it was confirmed.

`snapshot_at` is the freshness field: when that product's listings were last
confirmed against TCGplayer. It is the same for every row in a response, since
a snapshot replaces a product's listings wholesale. Listings refresh daily, so
a `snapshot_at` well over a day old means that product's last fetch did not
succeed and you are looking at the previous snapshot.

One thing `snapshot_at` cannot tell you: listings are collected from a US
vantage point with no shipping-destination filter, so a response can contain
offers TCGplayer's own site hides from you when you browse it from elsewhere.

## Cardmarket special attributes

Cardmarket sells more than one kind of good under a single card. Every
Cardmarket offer carries four booleans, and they are always present:

```python
for offer in client.cards.listings.iterate_cardmarket(789):
    if offer.graded:
        print(offer.grader, offer.grade)  # "PSA", "10"
    if offer.signed or offer.altered:
        continue  # not a clean card
```

A `signed`, `altered`, `graded` or `opened` offer is real, and it is returned,
but it does **not** contribute to the market price. A signed and altered Near
Mint copy at EUR 200 must not set the Near Mint price of a card whose clean
copies sell for EUR 3,800, and a slab is priced for the slab rather than for the
card.

The practical consequence: **the cheapest row you get back is not necessarily
the `market_price`.** Filter these out before deriving a price yourself, or let
the API do it:

```python
clean = client.cards.listings.all_cardmarket(789, graded=False, signed=False, altered=False)
slabs = client.cards.listings.all_cardmarket(789, grader="PSA", grade="10")
```

Each of `graded`, `signed` and `altered` takes `True` for only those offers and
`False` to leave them out. Sealed products add `opened`.

`grader` and `grade` are named to match the graded eBay sale shape, so "PSA 10"
reads the same whichever source it came from. Both are `None` unless `graded`
is true, and can be `None` even then: Cardmarket flags a slab without always
naming the grader, and the details are read from free-text seller comments.

`opened` is the sealed-product member of the set: the seller's own comment says
the item is not sealed. It is always `False` on a card. A Jungle booster pack
whose every other offer sits between EUR 799 and EUR 950 carries one at
EUR 10.00 reading *"Not Sealed (open, just the booster)"*. That is a real price
for an opened pack, not a EUR 10 Jungle booster pack.

## `sell_count`

The other reason the cheapest row may not be the price. `sell_count` is the
seller's completed sales, and an offer from a seller with no completed sales
does not set a price.

```python
for offer in client.sealed.listings.iterate_cardmarket(1430):
    if offer.opened:
        continue  # not the sealed product
    if offer.sell_count == 0:
        continue  # no completed sales; sets no price
    # offer.sell_count is None means no count was recorded, which is not zero sales
```

**`None` is not zero.** `None` means no count was recorded for that row; `0`
means Cardmarket reports the seller as having sold nothing. Treat only `0` as
disqualifying. `if not offer.sell_count` catches both, which is the mistake
this distinction exists to prevent.

`min_sell_count` filters on this field. It cannot tell an unrecorded count from
a low one, so it leaves the `None` rows out.

## Languages

A card's language comes from its set, and it decides what pricing that card can
ever have.

| Language | Cards | Pricing | Plan |
|----------|-------|---------|------|
| English | 28,383 | USD (TCGplayer) + EUR (Cardmarket) | Free |
| Japanese | 30,001 | USD + EUR | Pro+ |
| German | 17,462 | EUR (Cardmarket) only | Pro+ |
| Spanish | 15,543 | EUR (Cardmarket) only | Pro+ |

Counted on 2026-11-01. `tcg_player_id` is `None` on German and Spanish cards
and sets, which have no TCGplayer product.

```python
german = client.cards.list(language="German", currency="eur")
```

Spelling is normalised: `"German"`, `"german"`, `"de"` and `"DE"` all resolve to
the same thing, and responses come back in the canonical form (`"German"`).
Spanish takes `"Spanish"`, `"Español"`, `"espanol"`, `"spa"` and `"es"`.

**German and Spanish cards have no USD price and never will**, because
TCGplayer sells neither. Asking for either with `currency="usd"` returns an
empty list rather than an error, so reach for `"eur"`.

The same rule scopes Cardmarket listings. `cardmarket()` returns offers in the
card's set language only, so an English card never returns German or Spanish
offers.
cardmarket.com shows every language on one product page, so the cheapest offer
here is usually higher than the "From" price a browser shows you. That is this
feed being narrower, not a different product.

A free key is limited to English. Asking for Japanese, German or Spanish raises
`ForbiddenError`, and omitting `language` returns English only rather than the
whole catalogue.

German coverage runs from Base Set (1999) to current sets, and Spanish from
Black & White (2011). Spanish price history only goes back to when
Spanish pricing started, so it is shorter than the other languages'. A Spanish
card with no Cardmarket offer in Spanish yet has no price, which is missing
data, not a zero.

## Currency

Every price has a `currency` field. Pass `currency="usd"` or `currency="eur"` to filter, or leave it off to get everything your plan allows. EUR (Cardmarket) prices need a Pro plan; a free key asking for `eur` raises `ForbiddenError`.

```python
card = client.cards.get(789, currency="usd")
box = client.sealed.get(5678, currency="eur")
```

Cardmarket current prices are condition- and printing-specific marketplace
prices. Each EUR row has one `market_price` for its exact `condition` and
`variant`; for example, a Near Mint Reverse Holofoil price is distinct from a
Mint or Normal price. The retired Price Guide `low`, `trend`, and `avg` fields
are not returned. Live Cardmarket listings are automatically restricted to the
card's language.

## Cardmarket Mapping

Card and sealed detail responses expose Cardmarket's stable product identifiers
when a mapping is available:

```python
card = client.cards.get(789)
print(card.cardmarket_url)
print(card.cardmarket_product_id)

box = client.sealed.get(5678)
print(box.cardmarket_url)
print(box.cardmarket_product_id)
```

Both fields are `None` until the product has been mapped.

## Errors

Everything raised subclasses `PkmnPricesError`, which carries `status`, `code`, `docs_url`, `rate_limit`, and `retry_after`. `docs_url` is the docs page for that class of error as sent by the API, so a 401 points at authentication, a 403 at pricing and a 429 at rate limits; it is `None` when the response had no body to read it from.

A 429 also says which limit it hit. `limit_type` is `"per_minute"` or `"daily"`,
`retry_after` is the seconds until a retry can succeed, and `resets_at` is that
instant as an RFC 3339 timestamp. A per-minute limit clears within 60 seconds
and is retried for you. A daily one does not clear until 00:00 UTC, so it is
raised straight away as a `CreditLimitError`, with `upgrade_url` pointing at
the dashboard page for changing plan or adding prepaid credits.

`rate_limit` holds the credit and rate headers of the failed response:
`credits_charged`, `credits_limit`, `credits_remaining`, `credits_reset`,
`credits_balance` (only while the account holds prepaid credits), `rate_limit`,
`rate_remaining` and `rate_reset`.

```python
from pkmnprices import ForbiddenError, NotFoundError, RateLimitError

try:
    client.cards.get(789, currency="eur")
except ForbiddenError:
    ...  # needs a higher plan
except NotFoundError:
    ...  # no such card
except RateLimitError:
    ...  # ran out of retries
```

A 401 comes back with `code` set to `missing_api_key` when no key was sent and
`invalid_api_key` when the key doesn't match one, both as `UnauthorizedError`.

Subclasses: `BadRequestError` (400), `UnauthorizedError` (401), `ForbiddenError` (403), `NotFoundError` (404), `ConflictError` (409), `CreditLimitError` and `RateLimitError` (429), `InternalServerError` (5xx), `APIConnectionError` (network/timeout).

## Upgrading from 4.x

5.0.0 changes type hints only, to match what the API sends:

- `tcg_player_id` is `int | None` on cards, sets and sealed products.
- `market_price` on a price and `avg`, `low` and `high` on a price history row
  are `float | None`. `card_count` on a set is `int | None`.
- `PriceSource` is `Literal["tcgplayer", "cardmarket"]`. eBay was never a price
  source.

## License

MIT
