db_api_handler module

exception core.db_api_handler.APIError

Bases: Exception

Custom exception for local SRD API-related errors.

class core.db_api_handler.LocalAPIHandler(base_path: str = 'core/data/rulebook_json')

Bases: object

Loads 5e SRD JSON files from disk and provides a local API-like interface.

Automatically maps file names like ‘5e-SRD-Classes.json’ to categories such as ‘classes’.

Parameters:

base_path (str) – Path to the directory containing 5e-SRD JSON files.

get(category: str, params: Dict[str, Any] | None = None) Any

Load all entries from a given SRD category.

Parameters:
  • category (str) – Category name, e.g. ‘spells’, ‘monsters’

  • params (dict, optional) – (Unused, for compatibility)

Returns:

List or dict of entries

Return type:

Any

get_monster(name: str) Dict[str, Any] | None

Fetch a monster entry by name.

Parameters:

name (str) – Name of the monster (e.g., “Goblin”)

Returns:

Monster data dict if found

Return type:

dict or None

get_raw(endpoint: str, params: Dict[str, Any] | None = None) Dict[str, Any] | None

Simulates fetching a single object by slug from a category, like /api/spells/fireball.

Parameters:
  • endpoint (str) – API-like path string

  • params (dict, optional) – (Unused)

Returns:

Matching dictionary entry if found

Return type:

dict or None

Raises:

APIError – If the endpoint is malformed

get_spell(name: str) Dict[str, Any] | None

Fetch a spell entry by name.

Parameters:

name (str) – Name of the spell (e.g., “Fireball”)

Returns:

Spell data dict if found

Return type:

dict or None

list_available(category: str) Any

Return all objects in a category.

Parameters:

category (str) – Category name

Returns:

JSON-parsed list or dict

Return type:

Any

list_categories() List[str]

Return all available auto-detected SRD categories.

Returns:

List of available category keys (e.g., ‘spells’, ‘races’)

Return type:

list[str]