Automated Action c8eba88591 Configure OpenWeatherMap API key in settings
- Add default OpenWeatherMap API key to enable weather service functionality
- Maintain environment variable override capability
- Ensure weather API endpoints can fetch data properly
2025-05-27 20:57:58 +00:00
2025-05-27 20:09:40 +00:00

Weather Dashboard API

A powerful API for retrieving weather data, forecasts, and managing location bookmarks, built with FastAPI and SQLite.

Features

  • User Authentication: Secure JWT-based authentication
  • Current Weather Data: Get real-time weather information for any location
  • Weather Forecasts: Access 5-day weather forecasts
  • Location Bookmarking: Save and manage your favorite locations
  • Default Location: Set a default location for quick weather checks
  • Caching: Efficient caching to minimize external API calls
  • OpenAPI Documentation: Auto-generated, interactive API documentation

Tech Stack

  • Framework: FastAPI
  • Database: SQLite with SQLAlchemy ORM
  • Migrations: Alembic
  • Authentication: JWT with OAuth2
  • Password Hashing: Bcrypt
  • HTTP Client: HTTPX
  • External API: OpenWeatherMap API
  • Documentation: Swagger UI / ReDoc

Prerequisites

  • Python 3.8+
  • OpenWeatherMap API key (free tier available)

Environment Variables

Create a .env file in the root directory with the following variables:

OPENWEATHER_API_KEY=your_api_key_here
SECRET_KEY=your_secret_key_here

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/weather-dashboard-api.git
cd weather-dashboard-api
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up the database:
alembic upgrade head

Running the Application

Start the development server:

uvicorn main:app --reload

The API will be available at http://localhost:8000

API Documentation

Interactive API documentation is available at:

API Endpoints

Authentication

  • POST /api/v1/users/register - Register a new user
  • POST /api/v1/users/login - Login and get access token
  • GET /api/v1/users/me - Get current user information

Weather Data

  • GET /api/v1/weather/current - Get current weather for specific coordinates
  • GET /api/v1/weather/current/default - Get current weather for default location
  • GET /api/v1/weather/forecast - Get 5-day forecast for specific coordinates
  • GET /api/v1/weather/forecast/default - Get 5-day forecast for default location

Location Management

  • GET /api/v1/locations - Get all saved locations
  • GET /api/v1/locations/default - Get default location
  • POST /api/v1/locations - Create a new location
  • GET /api/v1/locations/{location_id} - Get a specific location
  • PUT /api/v1/locations/{location_id} - Update a specific location
  • DELETE /api/v1/locations/{location_id} - Delete a specific location

Health Check

  • GET /health - Check API health status

Database Models

User

  • ID
  • Email (unique)
  • Username (unique)
  • Hashed Password
  • Is Active
  • Is Superuser
  • Created At
  • Updated At
  • Relationships: Locations

Location

  • ID
  • Name
  • Latitude
  • Longitude
  • Country (optional)
  • Is Default
  • Created At
  • Updated At
  • User ID (foreign key)
  • Relationships: User

Project Structure

weather-dashboard-api/
├── alembic.ini                # Alembic configuration
├── main.py                    # FastAPI application entry point
├── requirements.txt           # Python dependencies
├── app/                       # Application package
│   ├── api/                   # API endpoints
│   │   ├── deps.py            # API dependencies
│   │   └── v1/                # API version 1
│   │       ├── endpoints/     # API route handlers
│   │       └── router.py      # API router
│   ├── core/                  # Core functionality
│   │   ├── config.py          # App configuration
│   │   └── security.py        # Security utilities
│   ├── crud/                  # CRUD operations
│   ├── db/                    # Database setup
│   │   └── session.py         # DB session
│   ├── models/                # SQLAlchemy models
│   ├── schemas/               # Pydantic schemas
│   └── services/              # Business logic services
│       ├── cache_service.py   # Caching service
│       └── weather_service.py # Weather API client
└── migrations/                # Alembic migrations
    ├── env.py                 # Migration environment
    ├── script.py.mako         # Migration template
    └── versions/              # Migration scripts

Error Handling

The API includes comprehensive error handling:

  • Invalid input validation
  • Authentication and authorization errors
  • Resource not found errors
  • External API communication errors
  • Rate limiting and caching errors

Caching Strategy

The API implements a simple in-memory caching strategy to minimize calls to the OpenWeatherMap API:

  • Cache duration is configurable (default: 5 minutes)
  • Separate cache keys for current weather and forecasts
  • Automatic cache invalidation on expiration

Development

To contribute to this project:

  1. Create a feature branch:
git checkout -b feature/your-feature-name
  1. Make your changes and run tests:
pytest
  1. Run code linting:
ruff check --fix
  1. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

Description
Project: Weather Dashboard API
Readme 58 KiB
Languages
Python 99.1%
Mako 0.9%