This repository contains the exercises for the Skill Boost session on consuming APIs. It contains the code for running and deploying a simple FastAPI application that exposes two endpoints:
/measurements/page
: a paginated endpoint that returns a list of measurements.
/measurements/very-reliable
: an endpoint that, despite its name, is not very reliable and returns sometimes a 500 error.
For a full description of the endpoints and the query parameters, there is an OpenAPI specification available at /docs
. You can run the API either locally via make run-api
, or deploy it in the Dataminded Playground AWS account by applying the Terraform configuration in the infra
directory. This will create an ECS service that is available at skillboost.playground.dataminded.cloud
.
There are two exercises you can complete:
- Make the
tests/test_very_reliable.py
test pass. It uses theingest_measurements
function frommain_sync.py
to fetch measurements from the/measurements/very-reliable
endpoint. The test is currently failing because the endpoint is not very reliable and returns sometimes a 500 error. You can modify theingest_measurements
function to handle these errors. Tip: some tenacity can help! - Implement the
ingest_measurements
functions inmain_async_measurements.py
andmain_multithreaded_measurements.py
using theasyncio
andmultithreading
libraries, respectively. Then run the benchmark tests withmake benchmark
to see which implementation is faster. Can you explain the results?