TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/invvd/mtg-cheaper-deck/llms.txt
Use this file to discover all available pages before exploring further.
moxfield_client module is the entry point for retrieving deck data from Moxfield. It handles URL parsing, HTTP communication, JSON validation, and conversion of the raw API response into a flat list of card dicts that the rest of the pipeline can consume. All failures — network errors, blocked requests, unexpected response shapes — are surfaced as a single MoxfieldError exception so that callers never need to inspect raw HTTP status codes.
Constant
{deck_id} is substituted at request time by fetch_deck_raw(). A browser-like User-Agent header is sent with every request to reduce the chance of a Cloudflare 403.
MoxfieldError
MoxfieldError is the single exception type raised by every function in this module. It inherits directly from Exception and is used for any failure condition: network timeouts, HTTP errors (403, 404, other non-2xx), and responses that cannot be decoded as JSON.
MoxfieldError at the top of your pipeline to handle all Moxfield-related failures in one place.
extract_deck_id
Extracts the deck ID string from a full Moxfield URL, or passes a bare ID through unchanged.A full Moxfield deck URL such as
https://moxfield.com/decks/XyZ-abc123 or a bare deck ID such as XyZ-abc123. Leading and trailing whitespace is stripped automatically.str — the deck ID portion of the URL (the segment that follows /decks/), or the input itself when it contains no / or spaces and is non-empty.
Raises MoxfieldError if the input looks like a URL but no deck ID can be found with the pattern moxfield.com/decks/{id}, or if the input is an empty string.
fetch_deck_raw
Calls the Moxfield API for a given deck and returns the raw, unparsed JSON response as a Python dict.A full Moxfield deck URL or a bare deck ID. Passed to
extract_deck_id() internally.Request timeout in seconds. Raise for slow connections; lower for interactive use where a fast failure is preferable.
dict — the complete decoded JSON body from the Moxfield API. The exact shape depends on Moxfield’s current response format; use this return value with parse_deck() or inspect it directly when debugging.
Raises MoxfieldError in the following situations:
| Condition | Message |
|---|---|
| Request times out | "Timeout llamando a Moxfield (…)" |
| Any other network error | "Error de red llamando a Moxfield: …" |
| HTTP 403 | Probable Cloudflare / anti-bot block |
| HTTP 404 | Deck not found or not public |
| Any other non-2xx | Status code + first 300 chars of body |
| Response is not valid JSON | "La respuesta de Moxfield no es JSON válido" |
parse_deck
Converts a raw Moxfield JSON dict (as returned byfetch_deck_raw()) into a flat list of card entry dicts.
The raw JSON dict returned by
fetch_deck_raw(). The function handles two known response shapes: a top-level commanders / mainboard / companion dict-of-dicts, and a nested boards.{board_name}.cards dict-of-dicts.list[dict] — a list where each element represents one card entry:
Card name as returned by Moxfield (e.g.
"Sol Ring").The Scryfall printing ID. Tried from
card.scryfall_id, then card.scryfallId, then card.id. May be None if the field is absent.Number of copies in the deck. Defaults to
1 if the field is missing.The board the card belongs to:
"commanders", "mainboard", or "companion" (for the top-level shape), or whatever key appears under boards in the nested shape.get_moxfield_deck
Convenience wrapper that fetches, parses, and validates a Moxfield deck in a single call. This is the function you should use in most situations.A full Moxfield deck URL or bare deck ID. Forwarded to
fetch_deck_raw().Request timeout in seconds, forwarded to
fetch_deck_raw().list[dict] — the same structure as parse_deck(), guaranteed to be non-empty.
Raises MoxfieldError for all the same reasons as fetch_deck_raw(), plus one additional case: if parse_deck() returns an empty list (indicating that the response was valid JSON but its shape was not recognised), a MoxfieldError is raised with a message advising you to call fetch_deck_raw() and inspect the response manually.