Skip to content

A sample python-api service that retrieves data from The Metropolitan Museum of Art Collection API about objects on display in the museum.

Notifications You must be signed in to change notification settings

kkalesnikava/met-proxy-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sample Python Api Setup

A sample python-api service that retrieves data from The Metropolitan Museum of Art Collection API about objects on display in the museum.

Repo structure

  • app - Flask app module
  • helm - Helm charts for python-api deployment (via skaffold)

Basic usage

Available endpoints:

/ or /index - returns information about a default object on display in the museum - Japanese Hanging scroll "Quail and Millet" created by Kiyohara Yukinobu

Example output:

{
  "remote_endpoint_url": "https://collectionapi.metmuseum.org/public/collection/v1/objects/45734",
  "remote_entity": "Metropolitan Museum of Art",
  "result": {
    "GalleryNumber": "",
    "accessionNumber": "36.100.45",
    "accessionYear": "1936",
    "additionalImages": [
      "https://images.metmuseum.org/CRDImages/as/original/DP251138.jpg",
      "https://images.metmuseum.org/CRDImages/as/original/DP251120.jpg"
    ],
    "artistAlphaSort": "Kiyohara Yukinobu",
    "artistBeginDate": "1643",
    "artistDisplayBio": "Japanese, 1643\u20131682",
    "artistDisplayName": "Kiyohara Yukinobu",
    "artistEndDate": "1682",
    "artistGender": "Female",
    "artistNationality": "Japanese",
    ...
    "title": "Quail and Millet"
  },
  "status_code": 200
}

/object/{id} - returns information about the object with id {id} on display in the museum

Example output for the endpoint /object/10101:

{
  "remote_endpoint_url": "https://collectionapi.metmuseum.org/public/collection/v1/objects/10101",
  "remote_entity": "Metropolitan Museum of Art",
  "result": {
    "GalleryNumber": "774",
    "accessionNumber": "1978.513.7",
    "accessionYear": "1978",
    "additionalImages": [],
    "artistAlphaSort": "Ball, Thomas",
    "artistBeginDate": "1819",
    "artistDisplayBio": "American, Charlestown, Massachusetts 1819\u20131911 Montclair, New Jersey",
    "artistDisplayName": "Thomas Ball",
    "artistEndDate": "1911",
    "artistGender": "",
    "artistNationality": "American",
    ...
    "title": "La Petite Pens\u00e9e"
  },
  "status_code": 200
}

How to run the app locally with venv

Create and activate virtual environment and install dependecies:

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Run the following command to start Flask app:

flask run

Open your browser at http://localhost:8080 and browse the app webpage.

After the job is complete, run the following command to stop venv:

deactivate

How to run the app locally with Docker

On the repo root run the following command to build an image:

docker build -t localhost:python-api .

Run docker image:

docker run --rm -p 8080:8080 -d --name api localhost:python-api

Open your browser at http://localhost:8080 and browse the app webpage.

You can check the app logs by running:

docker logs api

After the job is complete, run the following command to stop docker container (it will be removed, since the container was launched with --rm flag):

docker stop api

How to deploy the app locally

Local deployment is done using minikube and skaffold for deploying helm charts to the cluster

Setup

Start minikube with a custom profile and configure skaffold:

minikube start --profile custom
skaffold config set --global local-cluster true
eval $(minikube -p custom docker-env)

Run the following command to use Skaffold:

skaffold dev

Run on a separate terminal (Do not close the terminal window!):

minikube tunnel -p custom

Open your browser at http://localhost:8080 and browse the app webpage:

alt text

Or run curl command on your terminal:

curl -s http://localhost:8080/object/10101 | jq

alt text

Additionally you can test the helm release:

helm test python-api -n app

After the job is complete, press Ctrl+C to stop skaffold and press Ctrl+C to stop minikube tunnel.

Stop minikube:

minikube stop -p custom

About

A sample python-api service that retrieves data from The Metropolitan Museum of Art Collection API about objects on display in the museum.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published