Weather Data API

A FastAPI application that retrieves weather data from OpenWeatherMap and stores it in a SQLite database.

Features

  • Fetch current weather data from OpenWeatherMap
  • Store weather data in a SQLite database
  • Track weather history for cities
  • RESTful API with FastAPI
  • Database migrations with Alembic
  • Health check endpoint

Setup

  1. Clone the repository
  2. Install dependencies:
pip install -r requirements.txt
  1. Run the application:
uvicorn main:app --reload

API Endpoints

Weather Endpoints

  • GET /api/v1/weather/current/{city_name} - Get current weather for a city
  • POST /api/v1/weather/current - Get current weather using request body
  • GET /api/v1/weather/cities - List all cities
  • GET /api/v1/weather/cities/{city_id} - Get city details
  • GET /api/v1/weather/history/{city_id} - Get weather history for a city

Health Check

  • GET /health - Check application health

Database

The application uses SQLite with SQLAlchemy. The database is stored in /app/storage/db/db.sqlite.

Migrations

Database migrations are managed with Alembic:

# Apply migrations
alembic upgrade head

# Create a new migration
alembic revision -m "description"

Environment Variables

  • OPENWEATHERMAP_API_KEY - Your OpenWeatherMap API key (default: bd5e378503939ddaee76f12ad7a97608)

Documentation

The API documentation is available at:

  • Swagger UI: /docs
  • ReDoc: /redoc
Description
Project: Weather Data API
Readme 42 KiB
Languages
Python 97.2%
Mako 2.8%