Skip to content

feat(client): add get_many() and get_many_by_isbn() bulk fetch#440

Open
mekarpeles wants to merge 1 commit into
masterfrom
impa/get-many
Open

feat(client): add get_many() and get_many_by_isbn() bulk fetch#440
mekarpeles wants to merge 1 commit into
masterfrom
impa/get-many

Conversation

@mekarpeles

Copy link
Copy Markdown
Member

Summary

Adds two new methods to OpenLibrary for bulk entity fetching:

ol.get_many(olids)

Fetches any mix of Works, Editions, and Authors in a single /api/get_many.json call. Returns a list of typed objects in response order. Documents not found in OL are silently skipped.

results = ol.get_many(['OL45804W', 'OL1526129M', 'OL26170A'])
# → [Work, Edition, Author]

ol.get_many_by_isbn(isbns)

Resolves ISBNs → OLIDs via one /api/books.json call, then fetches full Edition data via get_many(). Two total HTTP calls regardless of batch size.

editions = ol.get_many_by_isbn(['0374202915', '9780525521198'])

Why

Single-entity fetches (Work.get(), Edition.get()) make one HTTP request per entity. For import pipelines and bulk enrichment, this is prohibitive. The /api/get_many.json endpoint already exists on OL and supports hundreds of keys per request.

Testing

pytest tests/ -x -v
55 passed in 0.17s
  • 9 new unit tests in TestGetMany covering: empty input, Work/Edition/Author dispatch, null-doc skipping, URL construction, and get_many_by_isbn ISBN→OLID resolution
  • pre-commit run --files clean

Related

Part of a series making openlibrary-client production-ready for local Docker dev and bulk operations:

Closes #440

Add two new methods to OpenLibrary for batch fetching entities:

- ol.get_many(olids): fetches any mix of Works, Editions, Authors in
  a single /api/get_many.json call. Returns typed objects; null/missing
  entries are silently skipped.

- ol.get_many_by_isbn(isbns): resolves ISBNs to OLIDs via one
  /api/books.json call, then fetches full Edition data via get_many().
  Two total HTTP calls regardless of batch size.

Both methods are tested (9 new unit tests, 55 total passing).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant