A simple Flask-based web application that fetches real-time weather data from the OpenWeatherMap API and provides it in multiple formats — JSON, CSV, Excel, and XML. Easily configurable and extendable, ideal for learning REST APIs, file conversion, and basic Flask routing.
-
Fetch real-time weather data for any city
-
Convert and export weather data in:
- JSON (default)
- CSV
- Excel (XLSX)
- XML
-
Modular structure with separate modules for fetching, processing, and converting data
-
Clean and simple Flask API endpoints
weather_flask/
│
├── app.py # Main Flask app
├── fetch_data.py # Fetch data from OpenWeatherMap API
├── process_data.py # Clean and extract relevant data
├── convert_data.py # Convert data to CSV, Excel, and XML
├── config.py # Configuration file (API key, default city, etc.)
├── templates/ # HTML templates (if needed)
└── README.md # Project documentation
-
Clone the repository:
git clone https://github.com/your-username/weather_flask.git cd weather_flask -
Install dependencies:
pip install -r requirements.txt
-
Add your API key and configuration:
- Edit
config.pywith your OpenWeatherMap API key and optionally set a default city.
API_KEY = 'your_api_key_here' CITY = 'Mumbai' # Default city
- Edit
-
Run the Flask app:
python app.py
| Endpoint | Method | Description |
|---|---|---|
/get_weather_data?city=CityName |
GET | Fetches and returns weather data in JSON |
/download_csv?city=CityName |
GET | Downloads weather data as a CSV file |
/download_excel?city=CityName |
GET | Downloads weather data as an Excel file |
/download_xml?city=CityName |
GET | Downloads weather data as an XML file |
🔍 Replace
CityNamewith your desired location.
Request:
GET /get_weather_data?city=Delhi
Response:
{
"city": "Delhi",
"temperature": "34°C",
"humidity": "56%",
"description": "Clear sky"
}- Python 3.x
- Flask
- Requests
- Pandas
- xml.etree.ElementTree
This project is licensed under the MIT License. See the LICENSE file for details.
- OpenWeatherMap API — for providing weather data
- Flask documentation — https://flask.palletsprojects.com/