As a data engineer, one of your most essential skills is knowing how to interact with APIs. APIs are crucial for ingesting data from countless sources, building robust data pipelines, and integrating different systems. They are the digital conduits that allow you to fetch the raw materials for your work.
This tutorial will give you firsthand experience by walking you through a real-world example using a fun, free dataset.
An API, or Application Programming Interface, is a set of rules and protocols that allows different software applications to communicate with each other. It defines the methods and data formats that applications can use to request and exchange information.
Think of it like this: you are at the Jolly Roger and want to know what's on tap. Instead of going behind the bar yourself, you ask the bartender (the API) for the beer list. The bartender then gives you a structured menu (the data) that you can read. In our case, our program will ask the Open Brewery DB's API for data, and the server will return it in a clean, predictable format.
To celebrate the craft of brewing, we'll be using the Open Brewery DB, a community-driven API that provides public information on breweries, cideries, and brewpubs. It's the perfect dataset for learning how to request, retrieve, and process data from an external source - a core task for any data engineer. So, let's get started!
Let's start by getting a list of breweries. We'll use Python and the popular requests library - All code can be found on Google Colab
The base URL for the Open Brewery DB API is https://api.openbrewerydb.org/v1/breweries. We can send a GET request to this URL to retrieve a list of breweries.
This code will print the names of the first five breweries returned by the API.
The response from the API is in JSON (JavaScript Object Notation) format, which is easy to work with in Python. The response.json() method automatically converts the JSON response into a Python list of dictionaries, where each dictionary is a brewery.
Each brewery dictionary has a wealth of information, including:
Let's say we want to find all the microbreweries in a specific city, like "San Diego." We can do this by adding parameters to our API request.
This will give you a list of up to five microbreweries in San Diego. You can easily change the params dictionary to filter by state, name, or other fields.
The Open Brewery DB API also has a powerful search endpoint that lets you find breweries by a search term. This is useful when you don't know the exact name of a brewery but have a keyword in mind.
Let's search for breweries with "Agars" in their name, just to see if a South African favourite has made the list.
This will return a list of breweries that match the search term "agars", and we can see that South Africa has not yet made the cut.
And there you have it! You've learned how to consume and process data from the Open Brewery DB API. This is just the beginning, of course. You can use this data to:
The possibilities are as endless as the variety of craft beers out there. So, this International Brewing Day, raise a glass to the power of data and the joy of a good brew.
Cheers!
Need more?
Do you have an idea buzzing in your head? A dream that needs a launchpad? Or maybe you're curious about how Calybre can help build your future, your business, or your impact. Whatever your reason, we're excited to hear from you!
Reach out today - let's start a coversation and uncover the possibilities.
Hello. We are Calybre. Here's a summary of how we protect your data and respect your privacy.
We call you
You receive emails from us
You chat with us for requesting a service
You opt-in to blog updates
If you have any concerns about your privacy at Calybre, please email us at info@calybre.global
Can't make BigDataLondon? Here's your chance to listen to Ryan Jamieson as he talks about AI Readiness