A RESTful API built with FastAPI to serve weather data, including minimum, maximum, average temperatures, and humidity for a given city and date. This service fetches weather data from the https://www.weatherapi.com/ API and caches it using an SQLite database to reduce redundant API calls.
- Weather Data API: Fetch minimum, maximum, average temperature, and humidity for a specified city and date.
- Data Caching: Weather data is cached in an SQLite database to avoid duplicate API calls.
- Docker Support: Containerized application using Docker for easy deployment.
- CI/CD: Automated testing and deployment via GitHub Actions.
- Unit Testing: Includes unit test using pytest to ensure functionality.
- Python 3.10 or higher
- Docker (optional, for containerized setup)
-
Clone the Repository
git clone https://github.com/Parissai/fastapi-weather-service.git cd fastapi-weather-service
-
Create a Virtual Environment (Optional but recommended)
python -m venv venv
-
Activate the Virtual Environment
On Windows:
venv\Scripts\activate
On macOS/Linux:
source venv/bin/activate
-
Install Dependencies
pip install -r requirements.txt
Before running the service, you'll need to configure your environment. Rename .env.example file to .env in the project root and add your API key.
To start the FastAPI weather service, run the following command:
uvicorn app.main:app --reload
- Host: http://127.0.0.1:8000 Documentation: Access the interactive
- API documentation at http://127.0.0.1:8000/docs.
Description:
Retrieve historical weather data for a specified city on a given date.
Query Parameters:
- city (string): The name of the city you want to get the historical weather for.
- date (string): The specific date for which you want to retrieve historical weather, formatted as YYYY-MM-DD.
pytest