Complete API reference for all modules and functions in the BGG Extractor library.
High-level synchronous functions that handle async operations internally.
search(query, **kwargs)Search for board games by name.
Parameters:
query (str): Search query stringtype (str, optional): Filter by item typeexact (bool, optional): Exact match only**kwargs: Additional BGG API parametersReturns:
SearchSchema: Search results containing list of itemsExample:
from bgg_extractor import search
results = search("Wingspan")
results = search("Pandemic", type="boardgame", exact=True)
get_things(ids, **kwargs)Get detailed information about specific games.
Parameters:
ids (list[int]): List of game IDs (max 20 per request)type (str, optional): Filter by thing typestats (bool, optional): Include ranking and rating stats (default: True)versions (bool, optional): Include version infovideos (bool, optional): Include videoshistorical (bool, optional): Include historical datamarketplace (bool, optional): Include marketplace datacomments (bool, optional): Include commentsratingcomments (bool, optional): Include rating commentspage (int, optional): Page number for commentspagesize (int, optional): Page size for comments (10-100)**kwargs: Additional BGG API parametersReturns:
ThingSchema: Game details containing list of itemsExample:
from bgg_extractor import get_things
# Get single game
game = get_things([174430], stats=True)
# Get multiple games
games = get_things([13, 174430, 266192], stats=True, videos=True)
get_collection(username, **kwargs)Get a user’s game collection.
Parameters:
username (str): BGG usernameversion (bool, optional): Include version infosubtype (str, optional): Item subtype (default: “boardgame”)excludesubtype (str, optional): Subtype to excludestats (bool, optional): Include ratings and stats (default: True)brief (bool, optional): Return abbreviated resultsshowprivate (bool, optional): Include private infominrating (float, optional): Filter by min user ratingrating (float, optional): Filter by exact user ratingminbggrating (float, optional): Filter by min BGG ratingbggrating (float, optional): Filter by exact BGG ratingminplays (int, optional): Filter by min playsmaxplays (int, optional): Filter by max playscollectionid (int, optional): Restrict to specific collection IDmodifiedsince (str, optional): Return items modified since date (YY-MM-DD)**kwargs: Additional BGG API parametersReturns:
CollectionSchema: Collection data containing list of itemsExample:
from bgg_extractor import get_collection
collection = get_collection("eekspider", stats=True)
owned_games = get_collection("username", stats=True, minrating=7)
get_plays(username=None, **kwargs)Get play history for a user or game.
Parameters:
username (str, optional): Username to fetch plays forid (int, optional): ID of the item to fetch plays fortype (str, optional): Type of item (thing, family)mindate (str, optional): Min date (YYYY-MM-DD)maxdate (str, optional): Max date (YYYY-MM-DD)subtype (str, optional): Subtype filter (default: “boardgame”)page (int, optional): Page number**kwargs: Additional BGG API parametersReturns:
PlaysSchema: Play data containing list of play itemsExample:
from bgg_extractor import get_plays
plays = get_plays(username="eekspider")
recent_plays = get_plays(username="eekspider", mindate="2024-01-01")
get_user(name, **kwargs)Get user profile information.
Parameters:
name (str): BGG usernamebuddies (bool, optional): Include buddies listguilds (bool, optional): Include guilds listhot (bool, optional): Include hot listtop (bool, optional): Include top listdomain (str, optional): Domain for hot/top lists (default: “boardgame”)page (int, optional): Page number for buddies/guilds**kwargs: Additional BGG API parametersReturns:
UserSchema: User profile dataExample:
from bgg_extractor import get_user
user = get_user("eekspider")
user_with_top = get_user("eekspider", top=True, domain="boardgame")
get_family(ids, **kwargs)Get details for specific game families.
Parameters:
ids (list[int]): List of family IDstype (str, optional): Filter by family type**kwargs: Additional BGG API parametersReturns:
FamilySchema: Family data containing list of itemsExample:
from bgg_extractor import get_family
family = get_family([2651], type="boardgamefamily")
Direct async client for advanced use cases.
BGGClientAsync context manager for BGG API operations.
Constructor Parameters:
base_url (str): Base URL for the API (default: “https://api.geekdo.com/xmlapi2”)min_delay (float): Minimum seconds between requests (default: 2.0)timeout (int): Request timeout in seconds (default: 30)max_poll_attempts (int): Max attempts to poll for 202 responses (default: 12)token (str, optional): BGG API token (reads from BGG_API_TOKEN env var if not provided)Methods: All methods are async and must be awaited. They have the same parameters as their synchronous counterparts.
async search(query, **kwargs) -> SearchSchemaasync get_thing(ids, **kwargs) -> ThingSchemaasync get_collection(username, **kwargs) -> CollectionSchemaasync get_plays(username=None, **kwargs) -> PlaysSchemaasync get_user(name, **kwargs) -> UserSchemaasync get_family(ids, **kwargs) -> FamilySchemaExample:
import asyncio
from bgg_extractor import BGGClient
async def fetch_data():
async with BGGClient(token="your_token") as client:
results = await client.search("Gloomhaven")
games = await client.get_thing([174430], stats=True)
return games
games = asyncio.run(fetch_data())
save_json(data, filepath)Save data to JSON file.
Parameters:
data: Data to save (list of Pydantic models or dicts)filepath (str): Output file pathExample:
from bgg_extractor import get_things, save_json
games = get_things([13, 174430])
save_json(games.items, "games.json")
save_csv(data, filepath)Save data to CSV file.
Parameters:
data: Data to save (list of Pydantic models or dicts)filepath (str): Output file pathExample:
from bgg_extractor import get_things, save_csv
games = get_things([13, 174430])
save_csv(games.items, "games.csv")
model_to_dict(model)Convert a single Pydantic model to dictionary.
Parameters:
model (BaseModel): Pydantic model instanceReturns:
dict: Dictionary representationExample:
from bgg_extractor import get_things
from bgg_extractor.transform import model_to_dict
games = get_things([13])
game_dict = model_to_dict(games.items[0])
models_to_list(models)Convert a sequence of Pydantic models to list of dictionaries.
Parameters:
models (Sequence[BaseModel]): Sequence of Pydantic modelsReturns:
list[dict]: List of dictionary representationsExample:
from bgg_extractor import get_things
from bgg_extractor.transform import models_to_list
import pandas as pd
games = get_things([13, 174430, 266192])
games_dict = models_to_list(games.items)
df = pd.DataFrame(games_dict)
Fields:
total (int): Total number of resultstermsofuse (str): Terms of use URLitems (list[SearchItem]): List of search resultstype (str): Item typeid (int): Item IDname (str): Item nameyearpublished (int, optional): Year publishedFields:
termsofuse (str): Terms of use URLitems (list[ThingItem]): List of game detailsid (int): Game IDtype (str): Game typename (str): Game namedescription (str, optional): Game descriptionyearpublished (int, optional): Year publishedminplayers (int, optional): Minimum playersmaxplayers (int, optional): Maximum playersplayingtime (int, optional): Playing time in minutesminage (int, optional): Minimum recommended ageusersrated (int, optional): Number of user ratingsaverage (float, optional): Average ratingrank (int, optional): BGG rankcategories (list[str]): Game categoriesmechanics (list[str]): Game mechanicsdesigners (list[str]): Game designersartists (list[str]): Game artistspublishers (list[str]): Game publishersFields:
totalitems (int): Total items in collectiontermsofuse (str): Terms of use URLpubdate (str): Publication dateitems (list[CollectionItem]): List of collection itemsobjecttype (str): Object typeobjectid (int): Object IDsubtype (str): Subtypecollid (int): Collection IDname (str): Game nameyearpublished (int, optional): Year publishedimage (str, optional): Image URLthumbnail (str, optional): Thumbnail URLstatus (dict): Ownership statusnumplays (int): Number of playsFields:
username (str): Usernameuserid (int): User IDtotal (int): Total playspage (int): Current pagetermsofuse (str): Terms of use URLplays (list[Play]): List of playsid (int): Play IDdate (str): Play datequantity (int): Quantitylength (int): Play length in minutesincomplete (bool): Incomplete flagnowinstats (bool): Include in stats flaglocation (str, optional): Play locationitem (dict): Game informationFields:
id (int): User IDname (str): Usernamefirstname (str, optional): First namelastname (str, optional): Last nameavatar (str, optional): Avatar URLregistered (str): Registration datebuddies (list): Buddies listguilds (list): Guilds listhot (list): Hot listtop (list): Top listThe library raises standard Python exceptions:
ValueError: Raised when BGG_API_TOKEN is not providedRuntimeError: Raised for BGG API errors (4xx, 5xx responses)httpx.TimeoutException: Raised on request timeoutfrom bgg_extractor import get_things
try:
games = get_things([999999]) # Invalid ID
except RuntimeError as e:
print(f"API Error: {e}")
except ValueError as e:
print(f"Configuration Error: {e}")
The BGG API has the following limits:
get_thingsHandling 202 Responses:
The library automatically polls for up to 12 attempts (configurable) with exponential backoff.
from bgg_extractor import BGGClient
# Increase polling attempts
async with BGGClient(max_poll_attempts=20) as client:
results = await client.search("Catan")
Increasing Delay:
# Increase delay between requests to 5 seconds
async with BGGClient(min_delay=5.0) as client:
results = await client.search("Catan")