Building on APIs
Let’s take the weather API from the previous page and create something useful. We’ll get weather data for the past 7 days, analyze it, visualize it, and save it. This brings together everything you’ve learned: APIs, data processing, file handling, and visualization.Project Setup
Before writing any code, let’s set up a clean, isolated project environment usinguv and organize our files.
1. Initialize the Project
Create a new directory for your project and initialize it withuv:
2. Project Structure
A clean project structure helps keep your code, data, and output organized. Organize your folder structure like this:3. Install Dependencies
Install the required packages for API requests, data analysis, and plotting usinguv add:
.venv) and lock exact versions in uv.lock for reproducibility.
Get 7 days of weather
The Open-Meteo API can give us historical data:Load into pandas
Now let’s organize this data:Visualize the data
Create a simple line chart:Save to CSV
Let’s save our data for later use:Complete example
Here’s everything together:What you’ve accomplished
Look at what you just did:- Connected to a real API
- Worked with dates and time
- Processed data with pandas
- Created a visualization
- Handled files and folders
- Saved your results
What’s next?
Now that you’ve built and organized your Python projects, let’s learn how to build interactive web interfaces and chatbots in pure Python using Streamlit!Building UIs with Streamlit
Create interactive web applications and AI dashboards