
generated with BackendIM... (backend.im)
Weather Data API
A FastAPI application that fetches and stores weather data from OpenWeatherMap.
Features
- Retrieve current weather data by city name or coordinates
- Store weather data in a SQLite database
- Query historical weather data for specific locations
- RESTful API with automatic OpenAPI documentation
- Health check endpoint
Requirements
- Python 3.8+
- OpenWeatherMap API key
Installation
- Clone this repository:
git clone <repository-url>
cd weatherdataapi
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install the dependencies:
pip install -r requirements.txt
- Set up environment variables:
export OPENWEATHERMAP_API_KEY=your_api_key_here
Or create a .env
file in the root directory:
OPENWEATHERMAP_API_KEY=your_api_key_here
- Run the database migrations:
alembic upgrade head
Usage
Start the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000
API Endpoints
GET /api/v1/weather/current
- Get current weather (query parameters: city, country, lat, lon)GET /api/v1/weather/history/{location_id}
- Get weather history for a locationGET /health
- Health check endpoint
API Documentation
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Project Structure
├── alembic/ # Database migration files
├── app/ # Application code
│ ├── api/ # API endpoints
│ │ ├── endpoints/ # Endpoint implementations
│ │ └── routes.py # API router
│ ├── core/ # Core application code
│ │ ├── config.py # Configuration settings
│ │ └── database.py # Database setup
│ ├── models/ # SQLAlchemy models
│ ├── schemas/ # Pydantic schemas
│ └── services/ # Business logic
├── main.py # Application entry point
├── requirements.txt # Python dependencies
└── README.md # Project documentation
License
This project is licensed under the MIT License - see the LICENSE file for details.
Description
Languages
Python
97.2%
Mako
2.8%