Skip to main content

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 using uv and organize our files.

1. Initialize the Project

Create a new directory for your project and initialize it with uv:

2. Project Structure

A clean project structure helps keep your code, data, and output organized. Organize your folder structure like this:
Create the folders and move the default script using your terminal:

3. Install Dependencies

Install the required packages for API requests, data analysis, and plotting using uv add:
This will automatically create a virtual environment (.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:
Output:

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
This is exactly how data analysis works in the real world!
Try modifying the code to get weather for your city. Find your coordinates at latlong.net.

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