WikipediaClient

WikipediaClient(language: str = 'en', tool_name: str = 'wikipedia-client')

Client for interacting with the Wikipedia API.
Supports searching and page retrieval on a specified language edition.
Public methods:
search(query: str, limit: int) -> list[dict[str, Any]] get_page(title: str) -> Optional[wikipediaapi.WikipediaPage]

Attributes:
base_url (str): URL of the MediaWiki API endpoint.
headers (dict[str, str]): HTTP headers, including User-Agent.
wiki (wikipediaapi.Wikipedia): Low-level Wikipedia API client.
Initialize the WikipediaClient.

Parameters:
NameDescription
languageType: str

Default: ‘en’
tool_nameType: str

Default: ‘wikipedia-client’

Instance Methods

get_page

get_page(self, title: str) -> Any | None

Retrieve a WikipediaPage object by title.

Parameters:
NameDescription
titleTitle of the Wikipedia page.

Type: str
Returns:
TypeDescription
Any | Nonewikipediaapi.WikipediaPage | None: The page object if it exists, otherwise None.

search(
    self,
    query: str,
    limit: int = 3
) -> Any

Search Wikipedia for pages matching a query string.

Parameters:
NameDescription
queryThe search keywords.

Type: str
limitMax number of results to return.

Type: int

Default: 3
Returns:
TypeDescription
Anylist[dict[str, Any]]: Each dict has keys: - ‘title’ (str) - ‘size’ (int) - ‘wordcount’ (int) - ‘timestamp’ (str)