Skip to main content

Python client and CLI for the BoardGameGeek XML API

Project description

bgg-search

bgg-search is a Python package and command-line tool for querying the BoardGameGeek XML API. It lets you search for board games by name and retrieve full game details — player counts, play time, weight, BGG rating, and more — from the command line or from your own Python code.

Installation

pip install bgg-search

Requires Python ≥ 3.13.

A BGG API token is required to make requests. Obtain one by registering your application at https://boardgamegeek.com/applications, then expose it as the BGG_TOKEN environment variable.

Quickstart

CLI

export BGG_TOKEN=<your-token>

# Search for games matching a query
bgg-search search "Catan"
#       13  Catan
#   396790  Catan: New Energies
#      ...

# Fetch full details for a game by its BGG ID
bgg-search details 13
# id:            13
# name:          Catan
# year:          1995
# min_players:   3
# max_players:   4
# ...

Python API

import os
from bgg_search import BggClient, search_games, get_game

client = BggClient(token=os.environ["BGG_TOKEN"])

results = search_games("Catan", client)
for game in results:
    print(game.id, game.name)

details = get_game(13, client)
print(details.name, details.bgg_rating)

Python API reference

Use-case functions

search_games(query: str, client: BggClientProtocol) -> list[GameSummary]

Search BGG for board games matching query. Returns results in BGG API order. Returns an empty list when no games match.

get_game(game_id: int, client: BggClientProtocol) -> GameDetails

Fetch full details for the game identified by game_id. Raises BggNotFoundError when the ID does not exist on BGG.

BggClientProtocol

A typing.Protocol defining the client contract. Pass any object that implements search(query: str) -> list[GameSummary] and get_game(game_id: int) -> GameDetails. The bundled BggClient satisfies this protocol.

from bgg_search import BggClient
client = BggClient(token="<your-token>")

Models

GameSummary

Field Type Description
id int BGG game ID
name str Primary game title

GameDetails

Field Type Description
id int BGG game ID
name str Primary game title
year_published int | None Year of first publication
min_players int | None Minimum number of players
max_players int | None Maximum number of players
min_playtime int | None Minimum play time in minutes
max_playtime int | None Maximum play time in minutes
weight float | None BGG complexity weight (1.0 – 5.0)
bgg_rating float | None BGG community rating (1.0 – 10.0)

Exceptions

Exception Inherits from Raised when
BggSearchError Exception Base class for all package exceptions
BggApiError BggSearchError BGG API returns an HTTP error
BggNotFoundError BggSearchError Requested game ID does not exist
BggParseError BggSearchError BGG API response cannot be parsed

CLI reference

All commands read the BGG token from the BGG_TOKEN environment variable and exit with code 1 (printing an error to stderr) if it is not set or if the BGG API returns an error.

bgg-search search <query>

Search for board games by name.

bgg-search search <query>
Argument Description
query Free-text search term

Output: one line per result, formatted as {id:>8} {name}. No output when no games match.

bgg-search details <id>

Fetch and display full details for a game.

bgg-search details <id>
Argument Description
id BGG game ID (integer)

Output: labeled key-value block, one field per line:

id:            13
name:          Catan
year:          1995
min_players:   3
max_players:   4
min_playtime:  60
max_playtime:  120
weight:        2.3
bgg_rating:    7.1

Exits with code 1 and prints an error to stderr when the game ID is not found.

Development

Run the quality gate (lint, type-check, security scan, unit tests):

tox

Run integration tests against the real BGG API:

BGG_TOKEN=<your-token> tox -e integ

A BGG API token is required. Obtain one by registering your application at https://boardgamegeek.com/applications. Tests are skipped automatically when BGG_TOKEN is not set.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bgg_search-0.4.0.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bgg_search-0.4.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file bgg_search-0.4.0.tar.gz.

File metadata

  • Download URL: bgg_search-0.4.0.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bgg_search-0.4.0.tar.gz
Algorithm Hash digest
SHA256 4544779bc847b907e490de90362b852bc34efb3244a19f1326acd5b2ed1c33f4
MD5 63511d8f23f8a385b09e28bb73570278
BLAKE2b-256 7306b15635748d227deb8990220c1faa0d41d7cb740d437b36fdac7565112775

See more details on using hashes here.

Provenance

The following attestation bundles were made for bgg_search-0.4.0.tar.gz:

Publisher: publish.yml on arnauldvm/bgg-search

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bgg_search-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: bgg_search-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bgg_search-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12cb4bcd547187babbc78bc4c11ae3f10b23f45758fd138b7701f76f28b02e4b
MD5 e59a674023144dc03cba20bf7e1cad25
BLAKE2b-256 78ab12e6a11d0d378a0a3531037ecfdae6390a435280aa1fb2847659033ccf2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for bgg_search-0.4.0-py3-none-any.whl:

Publisher: publish.yml on arnauldvm/bgg-search

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page