The Python SDK
A fully typed Python SDK for the TCGdex API that lets you access Pokémon Trading Card Game data with both async and sync options.
from tcgdexsdk import TCGdex, Extension
# Init the SDKtcgdex = TCGdex()
# Fetch a card in one linecard = await tcgdex.card.get("swsh3-136")# Or use the sync versioncard = tcgdex.card.getSync("swsh3-136")
print(f"Found: {card.name} ({card.localId}/{card.set.cardCount.total})")
Installation and Basic Setup
Section titled “Installation and Basic Setup”-
Install the SDK using pip:
Terminal window pip install tcgdex-sdk -
Import and initialize:
from tcgdexsdk import TCGdex, Languagetcgdex = TCGdex() # Initialize with default language (English)# Initialize with language as stringtcgdex = TCGdex("en")# Or using the Language enumtcgdex = TCGdex(Language.EN) -
Start making requests:
# Async usagecard = await tcgdex.card.get("swsh3-136")# Sync usagecard = tcgdex.card.getSync("swsh3-136")
Key Features
Section titled “Key Features”- Type Safety: All models are fully typed for better IDE integration
- Dual API: Both asynchronous and synchronous interfaces
- Flexible Querying: Powerful query builder to filter and sort results
- Multi-Language Support: Access card data in multiple languages
- Comprehensive Models: Detailed data models for cards, sets, series, and more
- Image Access: Direct access to card images and set symbols
Endpoints
Section titled “Endpoints”The SDK provides specialized endpoints for different data types:
sdk = TCGdex()
# Base card endpointsdk.card # Full card information
# Collection endpointssdk.set # Card sets (e.g., "Darkness Ablaze")sdk.serie # Card series (e.g., "Sword & Shield")
# Card data endpointssdk.rarity # Card raritiessdk.hp # HP valuessdk.illustrator # Card illustrators
# Game mechanics endpointssdk.type # Pokémon typessdk.energyType # Energy typessdk.retreat # Retreat costssdk.stage # Evolution stages
# Card details endpointssdk.variant # Card variants (holo, reverse, etc.)sdk.suffix # Card suffixessdk.regulationMark # Regulation markssdk.dexId # Pokédex IDs
Query Examples
Section titled “Query Examples”The SDK includes a powerful query builder to filter and sort results:
from tcgdexsdk import TCGdex, Query
sdk = TCGdex()
# Find all cards with specific namefurrets = await sdk.card.list(Query().equal("name", "Furret"))
# Find cards with 'ban' in illustrator name (case-insensitive)ban_cards = await sdk.card.list(Query().contains("illustrator", "ban"))
# Find high HP Pokémon, sorted by HPtanks = await sdk.card.list( Query() .greaterThan("hp", 200) .sort("hp", "desc"))
# Find cards with no attacks but with abilitiesbasics = await sdk.card.list( Query() .isNull("attacks") .notNull("abilities"))
# Pagination supportpage2 = await sdk.card.list( Query().paginate(page=2, itemsPerPage=20))
Language Support
Section titled “Language Support”The SDK supports multiple languages for card data:
from tcgdexsdk import TCGdex, Language
# Using string codesen_sdk = TCGdex("en") # Englishfr_sdk = TCGdex("fr") # Frenchde_sdk = TCGdex("de") # German
# Using enum for type safetyen_sdk = TCGdex(Language.EN) # default to english if not set
# Change language on existing instancesdk = TCGdex()sdk.setLanguage(Language.FR)
Working with Images
Section titled “Working with Images”Cards, sets, and series often include images that can be accessed:
from tcgdexsdk.enums import Quality, Extension
# Get a cardcard = await sdk.card.get("swsh3-136")
# Get image URL with quality and formatimage_url = card.get_image_url(quality="high", extension="png")# Or using enumsimage_url = card.get_image_url(Quality.HIGH, Extension.PNG)
# Download image directlyimage_data = card.get_image(Quality.HIGH, Extension.PNG)
# Sets and series also have image methodsset_data = await sdk.set.get("swsh3")
logo_url = set_data.get_logo_url(Extension.PNG)logo = set_data.get_logo(Extension.PNG)
symbol_url = set_data.get_symbol_url(Extension.WEBP)symbol = set_data.get_symbol(Extension.WEBP)