Python API Automation: Extract Data with API's in Python (Step-by-step)
Learn how to automate daily weather and news reports with Python APIs. Fetch data, format results, and send automatic email updates with this step-by-step guide.
Automation really feels more useful once your code talks to the outside world. Up to this point in this automation in Python series, you have been automating things that stay on your own computer.
Over the next few minutes, I want to spend time breaking down API’s. What they are, how we most commonly use them and give you guys some great starting API’s that I’ve used in multiple projects to help further your understanding.
I will link the projects that use these API’s in more detail at the bottom for you.
Long story short, API is short for Application Programming Interface. It’s just a structured way for one system to talk to another.
Every week you’ll be introduced to a new topic in Python, think of this as a mini starter course to get you going and allow you to have a structured roadmap that actually builds to create you a solid foundation in Python. Join us today!
Think about this, at a restaurant you do not walk into the kitchen and cook your own meal. You sit at a table, tell the server what you want, and the server carries your order to the kitchen. The kitchen prepares the food and sends it back out to you.
With APIs, Python is the customer placing the order. Your code sends a request, the API acts like the server, and it comes back with the exact data you asked for.
Once you see how this works, a lot of everyday tasks become almost effortless. The best part is that once your script has that data, it can send it to you automatically by email, Slack, text message, or whatever tool you like using.
In this article, I’ll show case how an API works and give you some code you can test out on your own. You’ll see how they work, how to call them from Python, how to work with the data they send back, and how to turn that result into a daily email that arrives on its own.
By the time you reach the end, you will have a simple automation pipeline in place. Your script will grab the daily weather, collect a few top news headlines, format everything into a clean summary, and send it straight to your inbox.
That is what it looks like when you start automating with APIs.
Thank you guys for allowing me to do work that I find meaningful. This is my full-time job so I hope you will support my work by joining as a premium reader today.
If you’re already a premium reader, thank you from the bottom of my heart! You can leave feedback and recommend topics and projects at the bottom of all my articles.
You can get started with Python today with the goal to land a job in the next few months - Join the Masterclass Here.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
Understanding the Role of APIs in Automation
Understanding how APIs fit into automation makes everything that comes later much easier. Before you even start coding, it is worth taking a moment to see why they matter.
Most of the information you use every day does not sit on your laptop. It lives on servers run by weather agencies, news companies, government organizations, financial exchanges, and countless other sources.
If you want your Python scripts to pull data from any of these places, you need a way to reach them. That is the role APIs play.
Calling these APIs is far easier than most people expect. Your code sends a request over the internet and the service sends back structured data, usually in JSON.
Once you automate these calls, you no longer need to check websites or apps on your own. Python becomes the tool that gathers the information for you and presents it in whatever format you choose.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
How APIs Work Behind the Scenes
When you make an API request, all you are really doing is having your code visit a specific URL. That URL points to the exact type of information you want and includes any details the service needs, these could be things like city, date, or temp units. A typical request might look like this:
https://api.openweathermap.org/data/2.5/weather?q=London&appid=YOUR_KEYWhen Python sends a request to that address, the server replies with structured data. That data comes back as plain, organized text that Python can read.
Most APIs return data in JSON format so many other languages can work with the return data. JSON is so similar to a Python dictionary, this makes it easy to work with.
Once you know how to pull out the pieces that matter, you can use them any way you want. You can drop them into an email, save them to a CSV file, store them in a database, or display them on a dashboard. You have full control over how the data is used.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
Learn Python. Build Projects. Get Confident!
Most people get stuck before they even start… But that doesn’t have to be you!
The Python Masterclass is designed to take you from “I don’t know where to start” to “I can build real-world Python projects” — in less than 90 days.
👉 I’m giving you my exact system that’s been proven and tested by over 1,500 students over the last 4+ years!
My masterclass is designed so you see your first win in less than 7 days — The sooner you start, the sooner you’ll have projects you can actually show to employers or clients.
Imagine where you’ll be 90 days from now if you start today.
👉 Ready to get started?
P.S. — Get 20% off your First Month with the code: save20now. Use it at checkout!
Calling the OpenWeather API with Python
To get started, you will pull the current weather for your city. You will need a free API key from OpenWeather, which you can create on their site.
I strongly recommend this API as it’s free and a great easier way to learn how to start interacting with API’s. Once you have it, you can make a Python function like this:
This function handles one job. It builds the request URL, sends the request, and then returns the temperature, the humidity, and a short description of the weather. This step is important because it turns the raw data from the API into something you can actually use.
We get what is known as a “response” from the API, we then take this response and convert it into JSON with the .json() method. Now you can treat this like a dictionary.
You may notice that the function returns only the key pieces of information rather than the whole JSON response. That is on purpose as I am only selecting what I actually want from the API since it returns a boatload of data.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
Fetching Daily News Headlines
The next API I recommend you experiment with is the NewsAPI. Again this is free but the data comes out slightly differently and is a great way to try to work it into your projects.
Pulling news from an API works the same way as pulling weather data. You send a request asking for the latest articles, and the server sends back a structured list that includes headlines, publishers, authors, and links.
This function pulls the top five headlines. If you want, you can also include things like the publisher, a brief summary, or the full link to each article. The whole idea is that your script is putting together a simple morning update for you, which is kinda cool.
Combining API Responses into One
Once you have separate functions that pull the weather and the news, the next step could be to bring everything together. This is when a project stops feeling like a set of small scripts and starts acting like an organized system.
This creates a readable summary that feels similar to a short morning newsletter. You can email it to yourself, write it to a file, or simply print it out.
The important thing is that all the information you gathered is now organized in one place, ready for you to use however you like.
👉 I genuinely hope you get value from these articles, if you do, please help me out, leave it a ❤️, and share it with others who would enjoy this. Thank you so much!
Scheduling the Script to Run Every Morning
Once your script is ready, the last step is setting it up to run on its own each morning. You can do this with Windows Task Scheduler or cron on a Mac/Linux system.
Scheduling is what completes the whole process. You write the script once, and from that point on, it handles everything without you having to remember to run it.
I wrote a whole guide on how you can start scheduling your Python Scripts so I won’t go into it all here. If you want to learn how to schedule your scripts to run automatically you can read that here.
Why APIs are Key for Automation
APIs play a central role in automation because they are the most reliable way for your code to pull in clean, structured data from outside your computer.
You can scrape websites when no API is available, but scraping comes with problems. Sites change often, the HTML can be messy, and small changes can break your script. APIs avoid all of that. They are designed for programs to use, so the data is steady and predictable.
Once you have this foundation in place, you can build far more advanced automation. You can match weather forecasts with appointments on your calendar and send yourself reminders. You can watch exchange rates and get notified when they hit a certain point. You can track your favorite stocks and receive alerts when they move.
This is the point where automation starts to open up in all directions, and you can build whatever you need.
👉 My Python Learning Resources
Here are the best resources I have to offer to get you started with Python no matter your background! Check these out as they’re bound to maximize your growth in the field.
Zero to Knowing: Over 1,500+ students have already used this exact system to learn faster, stay motivated, and actually finish what they start.
P.S - Save 20% off your first month. Use code: save20now at checkout!
Code with Josh: This is my YouTube channel where I post videos every week designed to help break things down and help you grow.
My Books: Maybe you’re looking to get a bit more advanced in Python. I’ve written 3 books to help with that, from Data Analytics, to SQL all the way to Machine Learning.
My Favorite Books on Amazon:
Python Crash Course - Here
Automate the Boring Stuff - Here
Data Structures and Algorithms in Python - Here
Python Pocket Reference - Here
Wrapping it up
Learning to automate with APIs really changes how you think about programming. Instead of seeing your scripts as tools that only work on your own computer, you start to see them as connected systems that can pull in information from anywhere.
With this approach, you can streamline your routine, build your own simple dashboards, and set up tools that actually support your day-to-day life.
You now have a script that gathers the weather, checks the news, and sends everything straight to your inbox before you even start your day. That alone saves
Understanding how to talk to APIs gives you access to countless data sources and a huge range of possibilities.
I hope you guys learned a little something new here and how we can use this to help automate our lives a bit more with Python.
Hope you all have an amazing week nerds ~ Josh (Chief Nerd Officer 🤓)
Projects that use these API’s
👉 If you’ve been enjoying these lessons, consider subscribing to the premium version. You’ll get full access to all my past and future articles, all the code examples, extra Python projects, and more.








