A Fast API project to manage Aston University's fleet of air quality sensors and handle batch data ingestion tasks.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
This project is a Fast API application that provides a RESTful API to manage Aston University's fleet of air quality sensors and handle batch data ingestion tasks. The API is hosted on AWS Lambda and is connected to a PostGreSQL database hosted on AWS RDS. The API is secured using JWT authentication and is documented using Swagger UI. The API is also connected to a cron job that runs every 24 hours to ingest data from the Plume Labs API, the Zephyr API and the SensorCommunity API.
To get a local copy up and running follow these simple steps.
- Setup a firebase project
- Enable Authentication and Realtime database services
- Copy the admin sdk into the app/config directory in the project files.
- You may choose to run the project locally or using docker by following the relevant setup instructions below.
- Docker Desktop - install from here
- Python 3.9.6+ - install from here
The following steps are requried for both local and docker setups.
-
Clone the repo
git clone AstonAirQuality/AirQuality-API
-
Enter your enviornment variables in
.env-template
PLUME_EMAIL= YOUR_PLUME_EMAIL PLUME_PASSWORD= YOUR_PLUME_PASSWORD JWT_SECRET= YOUR_JWT_SECRET ZEPHYR_USERNAME = YOUR_ZEPHYR_USERNAME ZEPHYR_PASSWORD = YOUR_ZEPHYR_PASSWORD SC_USERNAME = YOUR_SC_USERNAME SC_PASSWORD = YOUR_SC_PASSWORD CRON_JOB_TOKEN= YOUR_CRON_JOB_TOKEN
-
Copy
.env-template
to.env
and enter your enviornment variablescp .env-template .env
-
Now follow the setup instructions for your chosen setup method.
- From the project root directory, run the command
docker-compose up
- After the containers have been built visit http://localhost:8000/docs to view the API documentation
- From the project root directory, run the command below to install the project dependencies
pip install -r requirements.txt
- From the project root directory, run the command below to start the API
uvicorn app.main:app --reload
- After the API has started visit http://localhost:8000/docs to view the API documentation
- From the project root directory, run the command below to start the test container
docker-compose -f docker-compose-testenv.yml -p test up -d
- Choose one of the following methods to run the tests
- Using VSCode, open the project root directory and run the tests using the test explorer
- From the project root directory, run the command below to run the tests using Docker
docker exec -it test_app_ python -m unittest discover -s testing -p test_*.py
- From the project root directory, run the command below to run the tests with coverage in a local terminal (Python installation required)
Then run the command below to view the coverage report
python -m coverage run -m unittest discover -s testing -p test_*.py
Or run the command below to export the coverage report in htmlpython -m coverage report --omit="*/testing*
python -m coverage html --omit="*/testing*"
- To delete the container, run the command
docker-compose -f docker-compose-testenv.yml -p test down --volumes
Twitter (X): @dev_riyad
Email: [email protected]
Project Link: https://github.com/AstonAirQuality/AirQuality-API