Pokémon TCG Python SDK

repository·master·Indexed 41 days ago

https://github.com/pokemontcg/pokemon-tcg-sdk-python

A Python SDK wrapper for the Pokémon TCG API (pokemontcg.io) providing object-oriented access to cards, sets, types, and TCG metadata. Includes classes for querying and filtering cards and sets, and supports API key configuration via environment variables or the RestClient.

Tokens
911
Snippets
5
Records
6
Agent score
1%

What's inside Pokémon TCG SDK

  1. Configure your API Key

    master

    To use an API Key from dev.pokemontcg.io, you can either set an environment variable or configure the static RestClient instance in your code.

    Option 1: Environment Variable

    export POKEMONTCG_IO_API_KEY='12345678-1234-1234-1234-123456789ABC'

    Option 2: RestClient Configuration

    from pokemontcgsdk import RestClient
    RestClient.configure('12345678-1234-1234-1234-123456789ABC')
  2. Query and filter Sets

    master

    The Set class allows you to interact with Pokémon TCG expansion sets.

    • Find by code: Use Set.find(code).
    • Filter with queries: Use Set.where(q='...') (e.g., legalities.standard:legal).
    • Retrieve all: Use Set.all().
    from pokemontcgsdk import Set
    
    # Find a set by code
    set = Set.find('base1')
    
    # Filter sets via query parameters
    sets = Set.where(q='legalities.standard:legal')
    
    # Get all Sets
    sets = Set.all()
  3. Retrieve Types, Subtypes, Supertypes, and Rarities

    master

    You can retrieve all available entries for various Pokémon TCG classifications using the .all() method on their respective classes.

    from pokemontcgsdk import Type, Subtype, Supertype, Rarity
    
    types = Type.all()
    subtypes = Subtype.all()
    supertypes = Supertype.all()
    rarities = Rarity.all()
  4. Query and filter Cards

    master

    The Card class is the primary interface for interacting with Pokémon cards. You can find specific cards by ID, filter them using query parameters, or retrieve all cards.

    • Find by ID: Use Card.find(id).
    • Filter with queries: Use Card.where(q='...') with query parameters (e.g., set.name:generations supertype:pokemon).
    • Pagination: Use Card.where(page=X, pageSize=Y) to fetch specific pages of data.
    • Retrieve all: Use Card.all() (Note: this may take a long time).
    from pokemontcgsdk import Card
    
    # Find a card by id
    card = Card.find('xy1-1')
    
    # Filter Cards via query parameters
    cards = Card.where(q='set.name:generations supertype:pokemon')
    
    # Get all cards, but only a specific page of data
    cards = Card.where(page=5, pageSize=250)
    
    # Find all cards (will take awhile)
    cards = Card.all()
  5. Card and Set properties reference

    master

    The following properties are available on the Card and Set objects:

    Card Properties:

    • abilities, artist, ancientTrait, attacks, convertedRetreatCost, evolvesFrom, flavorText, hp, id, images, legalities, regulationMark, name, nationalPokedexNumbers, number, rarity, resistances, retreatCost, rules, set, subtypes, supertype, tcgplayer, types, weaknesses

    Set Properties:

    • id, images, legalities, name, printedTotal, ptcgoCode, releaseDate, series, total, updatedAt