This is a FastAPI-based implementation that interacts with the OpenWeatherMap API. It provides a modern, efficient, and user-friendly way to fetch and serve weather data using FastAPI's robust web framework.
Before you begin, ensure you have the following:
- Python >= 3.13 installed on your system.
- An API key from OpenWeatherMap.
Follow these steps to set up the project:
-
Clone the repository:
git clone https://github.com/Simatwa/weather-api.git cd weather-api -
Install the required dependencies:
# Create a virtual environment python -m venv venv # Activate the virtual environment # On Windows venv\Scripts\activate # On *nix source venv/bin/activate # Install the required dependencies pip install -r requirements.txt
To use the API, you need to configure your OpenWeatherMap API key:
- Obtain your API key from OpenWeatherMap.
- Create a
.envfile in the project root (you can use the provided.env.exampleas a template). - Add your API key to the
.envfile using the keyOPEN_WEATHER_MAP_API_KEY.
Once configured, you can start the server by running:
$ fastapi run appThe server will start on http://localhost:8000.
The Weather-API provides interactive documentation for its endpoints:
| Documentation Type | URL |
|---|---|
| Swagger UI | http://localhost:8000/api/docs |
| ReDoc | http://localhost:8000/api/redoc |
Important:
The/forecastendpoint has periodic request limitations for non-premium OpenWeatherMap accounts. Consider upgrading your account for higher request limits.
This project is licensed under MIT License