tools.tools.toolkits.openlibrary_toolkit

OpenLibrary toolkit for searching books, authors, and retrieving cover images.

This module provides a set of tools for interacting with the OpenLibrary API (https://openlibrary.org). These tools allow users to search for books by title or key, search for authors by name, and retrieve cover images.

The module includes three main tools: 1. search_books_tool: Search for books by title, keywords, or other query terms 2. search_authors_tool: Search for authors by name 3. get_cover_image_tool: Get the URL for a book or author cover image

Typical usage:

from haive.tools.toolkits.openlibrary_toolkit import open_library_tools

# Use in an agent agent = Agent(tools=open_library_tools) agent.run(“Find books by J.K. Rowling”)

Attributes

Classes

AuthorSearchInput

Input schema for the author search tool.

BookSearchInput

Input schema for the book search tool.

CoverInput

Input schema for the cover image retrieval tool.

Functions

get_cover_image_url(→ str)

Get the cover image URL for a book or author.

search_authors(→ dict)

Search for authors on OpenLibrary by name.

search_books(→ dict)

Search for books on OpenLibrary by title, key, or subject.

Module Contents

class tools.tools.toolkits.openlibrary_toolkit.AuthorSearchInput(/, **data: Any)

Bases: pydantic.BaseModel

Input schema for the author search tool.

name

Name of the author to search for.

name: str = None
class tools.tools.toolkits.openlibrary_toolkit.BookSearchInput(/, **data: Any)

Bases: pydantic.BaseModel

Input schema for the book search tool.

query

The book title, keywords, or search query to use.

page

Page number of results to retrieve, starting from 1.

page: int = None
query: str = None
class tools.tools.toolkits.openlibrary_toolkit.CoverInput(/, **data: Any)

Bases: pydantic.BaseModel

Input schema for the cover image retrieval tool.

olid

The OpenLibrary ID for a book or author.

is_author

Boolean flag indicating if the OLID is for an author.

is_author: bool = None
olid: str = None
tools.tools.toolkits.openlibrary_toolkit.get_cover_image_url(olid: str, is_author: bool = False) str

Get the cover image URL for a book or author.

This function constructs the URL for an OpenLibrary cover image based on the provided OpenLibrary ID.

Parameters:
  • olid – The OpenLibrary ID for a book or author.

  • is_author – Boolean indicating if the OLID is for an author (default: False).

Returns:

A URL string for the medium-sized cover image.

tools.tools.toolkits.openlibrary_toolkit.search_authors(name: str) dict

Search for authors on OpenLibrary by name.

This function queries the OpenLibrary author search API and returns a list of matching authors with their details.

Parameters:

name – The name of the author to search for.

Returns:

A dictionary containing a list of authors with their name, birth date, top work, work count, and OpenLibrary ID.

Raises:

requests.HTTPError – If the API request fails.

tools.tools.toolkits.openlibrary_toolkit.search_books(query: str, page: int = 1) dict

Search for books on OpenLibrary by title, key, or subject.

This function queries the OpenLibrary search API and returns a list of matching books with their details.

Parameters:
  • query – The book title, keywords, or search query.

  • page – The page number of results to retrieve (default: 1).

Returns:

A dictionary containing the number of results and a list of books with their title, author, first publish year, and OpenLibrary ID.

Raises:

requests.HTTPError – If the API request fails.

tools.tools.toolkits.openlibrary_toolkit.BASE_URL = 'https://openlibrary.org'
tools.tools.toolkits.openlibrary_toolkit.get_cover_image_tool
tools.tools.toolkits.openlibrary_toolkit.open_library_tools
tools.tools.toolkits.openlibrary_toolkit.search_authors_tool
tools.tools.toolkits.openlibrary_toolkit.search_books_tool