This API provides access to global public health statistics, allowing users to retrieve and compare health data for different countries and years. It utilizes a CSV file ("Global Health Statistics.csv") from Kaggle as its data source.
Returns health data for a specific country and year, presented in an HTML table. Data can be aggregated by disease.
- country (string, required): The name of the country.
- year (integer, required): The year for which to retrieve data.
- aggregate (boolean, optional, default: true): If true, aggregates data by disease, showing mean values for numerical columns.
The data is pulled from the CSV file: Global Health Statistics.csv.
An HTML table displaying health data, including the following columns:
- Disease Name
- Prevalence Rate (%)
- Mortality Rate (%)
- Availability of Vaccines/Treatment
- Healthcare Access (%)
- Average Treatment Cost (USD)
- Recovery Rate (%)
-
Get health data for the United States for the year 2020:
GET /health_data?country=Italy&year=2020
-
Get health data for Japan for the year 2019 without aggregation:
GET /health_data?country=Japan&year=2019&aggregate=false
Compares health data between two specified countries for a given year, presenting the results in two separate HTML tables. Data can be aggregated by disease.
- country1 (string, required): The name of the first country.
- country2 (string, required): The name of the second country.
- year (integer, required): The year for comparison.
- aggregate (boolean, optional, default: true): If true, aggregates data by disease, showing mean values for numerical columns.
The data is pulled from the CSV file: Global Health Statistics.csv.
An HTML page with two tables, one for each country, displaying health data. Each table contains the following columns:
- Disease Name
- Prevalence Rate (%)
- Mortality Rate (%)
- Availability of Vaccines/Treatment
- Healthcare Access (%)
- Average Treatment Cost (USD)
- Recovery Rate (%)
-
Compare health data between Canada and Mexico for the year 2021:
GET /health_compare?country1=Canada&country2=Mexico&year=2021
-
Compare health data between Germany and France for the year 2022 without aggregation:
GET /health_compare?country1=Germany&country2=France&year=2022&aggregate=false
- Installation:
- Ensure you have Python 3.7+ installed.
- Install the required packages:
pip install fastapi uvicorn pandas tabulate
- Running the API:
- Place the
Global Health Statistics.csvfile in the same directory as the Python script. - Run the API using Uvicorn:
uvicorn app:app --reload(replaceappwith your script's filename if different).
- Place the
- Accessing the API:
- Open your browser or use a tool like
curlor Postman to access the API endpoints. - View the API documentation at
/docsfor interactive exploration.
- Open your browser or use a tool like
The dataset is hosted externally and can be downloaded from the following link: https://www.kaggle.com/datasets/malaiarasugraj/global-health-statistics
- Data is loaded into a Pandas DataFrame upon application startup.
- The API returns HTML responses, making it easy to view data in a web browser.
- Error handling is implemented to catch and display issues such as missing data or invalid parameters.
- The code includes logging for debugging and error tracking.