API Reference
MetroSearch
- class mets.MetroSearch[source]
Bases:
objectHandle interactions with the Metropolitan Museum of Art API.
- search_url = 'https://collectionapi.metmuseum.org/public/collection/v1/search'
- obj_url = 'https://collectionapi.metmuseum.org/public/collection/v1/objects/'
- static client()[source]
Create an HTTP client.
- Returns:
An instance of httpx Client.
- Return type:
httpx.Client
- static search(term='sunflowers', img=True, mode=0)[source]
Search for objects using Metro REST API.
- Parameters:
term (str) – The search term. Defaults to “sunflowers”.
img (bool) – If True, only return objects with images. Defaults to True.
mode (int) – The search mode. 0 to search everywhere, 1 for title only, 2 for tags only. Defaults to 0.
- Returns:
A list of object IDs matching the search criteria.
- Return type:
List[int]
- static retrieve(oids: List[int], max_num=80, sort=0, delay=0.001) List[source]
Retrieve given Object IDs data from Metro API.
- Parameters:
oids (List[int]) – A list of object IDs to retrieve.
max_num (int) – The maximum number of objects to retrieve. Defaults to 80.
sort (int) – The sorting order. 0 for ascending, 1 for descending. Defaults to 0.
delay (float) – The delay between API requests in seconds. Defaults to 0.001.
- Returns:
A list of dictionaries containing object details.
- Return type:
List[dict]
- async static get_img(client, url, fpn)[source]
Download an image from the given URL and save it to the specified path.
- Parameters:
client (httpx.AsyncClient) – Async client for the HTTP request.
url (str) – Image URL
fpn (str) – Destination file path.
- Returns:
True if the download was successful, False otherwise.
- Return type:
bool
- async static download_async(json_data, dst, batch_size=20)[source]
Download object images in batches. On large number of files API bugs out, we need to split large number of files
- Parameters:
json_data (List[dict]) – Objects as JSON data
dst (str or Path) – Destination folder
batch_size (int) – batch size
- Returns:
A list of boolean values indicating the success status of each download.
- Return type:
List[bool]
MetroCLI
- class mets.MetroCLI[source]
Bases:
objectCommand-line interface using MetroSearch backend.
- static search(args)[source]
Main search function
- Parameters:
args (argparse.Namespace) – Parsed args