Skip to main content

themetpy

The Python Package for The MET Museum. TheMetPy is designed to provide a user-friendly interface to The Metropolitan Museum of Art’s Open Access API. By abstracting the complexities of API interactions, TheMetPy enables developers, researchers, and enthusiasts to effortlessly retrieve and analyze data from The Met's vast collection. Whether you're building data visualizations, conducting research, or developing applications, TheMetPy streamlines the process of accessing museum data.

Installation

You can install TheMetPy via PyPI using pip:

$ pip install themetpy

Usage

TheMetPy offers a simple and intuitive interface to interact with The Met’s Open Access API. Below are examples demonstrating how to utilize its core functionalities.

Quick Start

After installation, you can start using TheMetPy to interact with The Met’s Open Access API.

from themetpy import get_all_object_ids, get_object, get_departments, search

# 1. List all Object IDs in Department 6 (Asian Art)
object_ids = get_all_object_ids(departmentIds=6)
print(f"Total Object IDs in Department 6: {len(object_ids)}")

# 2. Retrieve details of a specific object (objectID: 45734)
object_data = get_object(45734, handle_missing='replace', replace_value='Unknown', verbose=True)
print(object_data)

# 3. List all departments
departments = get_departments()
for dept in departments:
    print(f"ID: {dept['departmentId']}, Name: {dept['displayName']}")

# 4. Perform an advanced search
search_results = search(
    query="sunflowers",
    isHighlight=True,
    medium="Paintings",
    hasImages=True,
    dateBegin=1800,
    dateEnd=1900
)
print(f"Found {len(search_results)} objects matching the search criteria.")

Detailed Usage

  1. Fetching A List of All Valid Object IDs

Fetch a list of all valid Object IDs from The Met’s collection. You can optionally filter by metadataDate and departmentIds.

  • Parameters:

    • metadataDate (str, optional): Return objects with updated data after this date (format: YYYY-MM-DD).
    • departmentIds (list or int, optional): Filter by department ID(s).
  • Returns:

    • list: A list of Object IDs.
from themetpy import get_all_object_ids

# Fetch all object IDs
all_object_ids = get_all_object_ids()
print(all_object_ids)

# Fetch object IDs updated after a specific date
recent_object_ids = get_all_object_ids(metadataDate="2021-01-01")
print(recent_object_ids)

# Fetch object IDs from specific departments (using department's ID)
department_object_ids = get_all_object_ids(departmentIds=[1, 3, 6])
print(department_object_ids)
  1. Fetching Object Records

Fetch detailed information about a specific artwork using its Object ID. You can specify how to handle missing data.

  • Parameters:

    • objectID (int): The Object ID of the artwork.
    • handle_missing (str): Strategy for handling missing data. Options:
    • 'log': Log a warning for missing fields.
    • 'filter': Exclude records with missing data.
    • 'replace': Replace missing fields with a specified value.
    • replace_value (str): Value to replace missing fields with (used when handle_missing='replace').
    • verbose (bool): If True, prints warnings about missing data fields.
    • raw (bool): If True, returns the raw JSON data without processing.
  • Returns:

    • dict or None: Return the object’s data as a dictionary, or None if filtered out.
from themetpy import get_object

# Fetch object data with missing fields replaced by 'Unknown'
object_data = get_object(
    objectID=45734,
    handle_missing='replace',
    replace_value='Unknown',
    verbose=True
)
print(object_data)
  1. Listing All Departments

Fetch a list of all departments within The Met, including their IDs and display names.

  • Parameters: None

  • Returns:

    • list: A list of dictionaries containing departmentId and displayName.
from themetpy import get_departments

# List all departments
departments = get_departments()
for dept in departments:
    print(f"ID: {dept['departmentId']}, Name: {dept['displayName']}")
  1. Advanced Search

Perform complex searches across The Met’s collection using various parameters to filter results.

  • Parameters:

    • query (str): Search term.
    • isHighlight (bool, optional): Filter by highlighted artworks.
    • title (bool, optional): Search within titles.
    • tags (bool, optional): Search within subject keyword tags.
    • departmentId (int, optional): Filter by department ID.
    • isOnView (bool, optional): Filter by objects currently on view.
    • artistOrCulture (bool, optional): Search within artist name or culture fields.
    • medium (str, optional): Filter by medium or object type (multiple values separated by |).
    • hasImages (bool, optional): Filter by objects that have images.
    • geoLocation (str, optional): Filter by geographic location (multiple values separated by |).
    • dateBegin (int, optional): Start year for date range.
    • dateEnd (int, optional): End year for date range.
  • Returns:

    • list: A list of Object IDs matching the search criteria.
from themetpy import search

# Perform an advanced search
# Example
search_results = search(
    query="impressionism",
    isHighlight=True,
    medium="Paintings",
    hasImages=True,
    dateBegin=1850,
    dateEnd=1900
)
print(f"Found {len(search_results)} objects matching the search criteria.")

Dependencies

TheMetPy currently relies on the following Python packages:

  • requests: For making HTTP requests to The Met’s API.

These dependencies are automatically installed when you install TheMetPy via pip.

Contributing

Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms. Contributions are welcome in various forms, including bug reports, feature requests, and pull requests.

License

themetpy was created by Yuxi Sun. It is licensed under the terms of the MIT license.

Credits

themetpy was created with cookiecutter and the py-pkgs-cookiecutter template.

Release files for themetpy 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for themetpy 1.0.2
File Size Uploaded
themetpy-1.0.2.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for themetpy 1.0.2
File Interpreter ABI Platform
themetpy-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / themetpy-1.0.2.tar.gz

Download URL themetpy-1.0.2.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1b97bbf2d77b43d695c8b180adfc03a60bd606f439ed41755eeb1fbec277f86c
BLAKE2b-256 checksum
How to use checksums
bb313f08f7396902ccaeab4e0e73c59312729c66073ad6aea3c64283aab2eb6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.9.6 Darwin/24.0.0

Release files / themetpy-1.0.2-py3-none-any.whl

Download URL themetpy-1.0.2-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
688201a3b37291bd45bbf908f7a76140d40f17aebbc25a9ba4b783891a1037ef
BLAKE2b-256 checksum
How to use checksums
ac828c227055802d00149956aa9b417f68313dd9776bf08d621ca48732490481
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.9.6 Darwin/24.0.0

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page