pressbooks.bulk_import

Attributes

PRESSBOOKS_DIRECTORY_URL

BOOKS_API_URL

DEFAULT_PER_PAGE

logger

plugin

here

Functions

_parse_page(...)

Validate raw API items into PressbooksBook records.

_fetch_page(...)

Fetch and parse a single page of books from the Pressbooks Directory API.

fetch_all_books(...)

Fetch all matching books from the Pressbooks Directory.

bulk_translate(...)

Translate a list of raw Pressbooks book dicts to OME EducationResource cards.

bulk_import_search(→ list[dict])

Fetch Pressbooks books by search query and cache results locally.

bulk_import_institution(→ list[dict])

Fetch Pressbooks books by institution filter and cache results locally.

Module Contents

pressbooks.bulk_import.PRESSBOOKS_DIRECTORY_URL = 'https://pressbooks.directory'
pressbooks.bulk_import.BOOKS_API_URL = 'https://pressbooks.directory/wp-json/pressbooks/v2/books'
pressbooks.bulk_import.DEFAULT_PER_PAGE = 100
pressbooks.bulk_import.logger
pressbooks.bulk_import.plugin
pressbooks.bulk_import._parse_page(items: list) list[server.plugins.pressbooks.pressbooks_models.PressbooksBook]

Validate raw API items into PressbooksBook records.

Uses a Python 3.13+ ExceptionGroup to gather and report all validation errors at once rather than stopping at the first malformed record. Valid records are returned even when some items fail validation.

async pressbooks.bulk_import._fetch_page(client: httpx.AsyncClient, params: dict[str, str | int]) list[server.plugins.pressbooks.pressbooks_models.PressbooksBook]

Fetch and parse a single page of books from the Pressbooks Directory API.

async pressbooks.bulk_import.fetch_all_books(*, search: str = '', institution: str = '', per_page: int = DEFAULT_PER_PAGE) list[server.plugins.pressbooks.pressbooks_models.PressbooksBook]

Fetch all matching books from the Pressbooks Directory.

Fetches the first page to discover the total page count from the X-WP-TotalPages response header, then gathers all remaining pages concurrently using asyncio.gather().

Args:

search: Full-text search query (maps to the ?q= UI parameter). institution: Institution name filter (maps to the ?inst= UI parameter).

Multiple institutions can be joined with && (e.g. "University at Buffalo&&University of Rochester").

per_page: Number of results per page (max 100).

Returns:

A flat list of all PressbooksBook records.

pressbooks.bulk_import.bulk_translate(books: list[dict]) collections.abc.Iterator[server.plugins.ome_plugin.EducationResource]

Translate a list of raw Pressbooks book dicts to OME EducationResource cards.

Fetch Pressbooks books by search query and cache results locally.

Args:

search: Search term to pass to the API. cache_path: Path to the local JSON cache file.

Returns:

A list of serialised EducationResource dicts.

pressbooks.bulk_import.bulk_import_institution(institution: str, cache_path: pathlib.Path) list[dict]

Fetch Pressbooks books by institution filter and cache results locally.

Args:

institution: Institution name(s) joined with &&. cache_path: Path to the local JSON cache file.

Returns:

A list of serialised EducationResource dicts.

pressbooks.bulk_import.here