
- Implemented FastAPI application structure - Added OpenWeatherMap API integration - Created SQLite database with SQLAlchemy - Setup Alembic for database migrations - Added health check endpoint - Created comprehensive README generated with BackendIM... (backend.im)
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
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
- Run the application:
uvicorn main:app --reload
API Endpoints
Weather Endpoints
GET /api/v1/weather/current/{city_name}
- Get current weather for a cityPOST /api/v1/weather/current
- Get current weather using request bodyGET /api/v1/weather/cities
- List all citiesGET /api/v1/weather/cities/{city_id}
- Get city detailsGET /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
Languages
Python
97.2%
Mako
2.8%