Sign inSign up

mohammed237/weather-api

By mohammed237

•Updated 11 months ago

Image
0

326

mohammed237/weather-api repository overview

⁠🌤️ Django Weather API (with Redis Cache)

A high-performance, containerized Weather API built with Django REST Framework.
This image is self-contained, running both the Django application and a Redis cache server inside a single container using Supervisor.

It fetches live weather data from Visual Crossing⁠ (or your provider) and caches the results in Redis to minimize latency and external API usage.


⁠🚀 Features

  • Real-time Weather: Fetches current weather data for any city.
  • Smart Caching: Uses Redis to cache responses for 1 hour (configurable), reducing external API costs.
  • Self-Contained: No need for a separate Redis container. Supervisor manages both Django and Redis processes internally.
  • Production Ready: Tuned for deployment on services like Railway, Render, or AWS.

⁠🛠️ Environment Variables

To run this container, you must provide the following environment variables:

VariableDescriptionRequiredDefault
WEATHER_API_KEYYour API Key from the weather providerYesNone
SECRET_KEYA random string for Django securityYesNone
DEBUGSet to False for productionNoFalse
REDIS_HOSTHostname for RedisNo127.0.0.1
REDIS_PORTPort for RedisNo6379

⁠🐳 Quick Start

Run the container exposing port 8000. You must pass your API key:

docker run -d \
  --name weather-api \
  -p 8000:8000 \
  -e WEATHER_API_KEY="YOUR_ACTUAL_API_KEY" \
  -e SECRET_KEY="change-me-to-something-random" \
  mohammed237/weather-api

⁠📡 API Usage

Once the container is running, you can access the API at:

  • Get Weather by City
    GET http://localhost:8000/weather/{city}/

Example:

curl http://localhost:8000/weather/london/

⁠🏗️ Architecture

This image uses a monolithic process approach for simplicity in deployment:

  • Base: Python 3.11 Alpine (Lightweight)
  • Process Manager: supervisord
  • Processes:
    • redis-server (starts first, listens on 127.0.0.1:6379)
    • django runserver (starts after Redis, listens on 0.0.0.0:8000)

⁠💾 Persistence (Optional)

If you want the Redis cache to survive container restarts, mount a volume:

docker run -d \
  -p 8000:8000 \
  -e WEATHER_API_KEY="YOUR_KEY" \
  -v weather_cache:/var/lib/redis \
  mohammed237/weather-api

⁠📌 Notes

  • Designed for easy deployment on container platforms.
  • Redis cache TTL is configurable (default: 1 hour).
  • Works with Visual Crossing or any weather provider with a REST API.

Tag summary

Content type

Image

Digest

sha256:ad62891eb…

Size

51.9 MB

Last updated

11 months ago

docker pull mohammed237/weather-api