A FastAPI-based microservice for weather data aggregation and prediction, integrating with the Finnish Meteorological Institute (FMI) Open Data API.
- Fetch current weather data for locations in Finland
- Historical weather data retrieval
- Weather forecast data
- Built with FastAPI and PostgreSQL
- Containerized with Docker
- Asynchronous API endpoints
- OpenAPI documentation
- Docker and Docker Compose
- Python 3.9+
- PostgreSQL 13+
- FMI Open Data API key (optional for development)
-
Clone the repository:
git clone https://github.com/tinosingh/weather_service_api.git cd weather_service_api
-
Copy the example environment file and update with your configuration:
cp .env.example .env # Edit .env with your settings
-
Build and start the services:
docker-compose up --build
-
Access the API documentation:
- Swagger UI: http://localhost:8101/docs
- ReDoc: http://localhost:8101/redoc
Create a .env
file with the following variables:
# Application
APP_NAME="Weather Service"
APP_ENV=development
DEBUG=True
# Database
POSTGRES_SERVER=db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=weather
DATABASE_URL=postgresql+asyncpg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_SERVER}:5432/${POSTGRES_DB}
# FMI API
FMI_API_KEY=your_api_key_here
FMI_API_BASE_URL=https://opendata.fmi.fi/wfs
# Server
HOST=0.0.0.0
PORT=8101
WORKERS=1
GET /api/v1/health
- Health check endpointGET /api/v1/weather/current/{location_id}
- Get current weather for a locationGET /api/v1/weather/forecast/{location_id}
- Get weather forecast for a locationGET /api/v1/weather/history/{location_id}
- Get historical weather data
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install development dependencies:
pip install -r requirements-dev.txt
-
Run the development server:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8101
pytest
# Linting
ruff check .
# Formatting
black .
# Type checking
mypy .
This service integrates with the FMI Open Data API. To use this feature:
- Get an API key from FMI Open Data
- Add it to your
.env
file asFMI_API_KEY=your_api_key_here
Build and run using Docker Compose:
docker-compose up --build
Example Kubernetes deployment files are provided in the k8s/
directory.
MIT