OpenBrewerydb API

Chase Johnson

4/13/2023

Introduction

Open Brewery DB is a free and open-source database of breweries and beers from around the world, that requires no API key. It was created to be a comprehensive source of information for anyone interested in craft beer, including beer enthusiasts, brewers, and businesses in the beer industry. The database includes information such as brewery and beer names, locations, styles, and even labels. Open Brewery DB is maintained by a community of contributors who add, update, and verify the data, making it a reliable source of information. The data is available to access and download for free through the Open Brewery DB API, making it a valuable resource for developers who want to build beer-related applications or websites. Whether you’re a beer lover or a developer, Open Brewery DB is a fantastic resource for exploring the world of craft beer.

Type Description
Microbreweries Most craft breweries. For example, Samuel Adams is still considered a micro brewery. Breweries that produce less than | 15,000 barrels of beer per year and sell 75% or more of their beer off-site.
Brewpubs A beer-focused restaurant or restaurant/bar with a brewery on-premise that sells 25% or more of their beer on-site and operates significant food services.
Taproom Breweries Breweries that produce less than 15,000 barrels of beer per year and sell 75% or more of their beer on-site. These breweries often have taprooms where customers can sample and purchase their beer on-premise.
Regional breweries A regional location of an expanded brewery. For example, Sierra Nevada’s Asheville, NC location. Breweries with an | annual beer production of between 15,000 and 6,000,000 barrels.
Contract brewing A brewery that uses another brewery’s equipment to produce their beer. Contract breweries typically have an annual | beer production of between 15,000 and 6,000,000 barrels.
Nano breweries An extremely small brewery which typically only distributes locally. These breweries may have limited production | capacity and may only be able to serve their beer on-premise or at a small number of local bars and restaurants.
Proprietor Similar to contract brewing but refers more to a brewery incubator. A proprietor brewery is a small-scale operation | that helps other breweries get started by providing access to brewing equipment and facilities. |
Planning A brewery in planning or not yet opened to the public. These breweries may be in the process of securing funding, | equipment, or a physical location, and may not yet have any beer available for sale.
Closed A location which has been closed.

OpenBrewerydb Website

Top 10 States with the highest number of Breweries

state numbers_of_breweries
California 884
Washington 471
Colorado 428
New York 414
Michigan 368
Texas 350
Pennsylvania 337
Florida 308
North Carolina 303
Ohio 297

This table displays the top 10 states in the United States with the highest number of breweries. With 884 breweries, California holds the top spot by a significant margin, followed by Washington with 471 breweries and Colorado with 428 breweries. The table also shows the number of breweries in each state, with New York, Michigan, Texas, Pennsylvania, Florida, North Carolina, and Ohio rounding out the top 10. This information can be useful for anyone interested in the craft beer industry, whether you’re a beer enthusiast looking to explore new breweries or a business owner looking to invest in the industry.

How Openbrewerydb works

This code is used to navigate the Openbrewerydb API and extract data about breweries. The API is divided into pages, with each page consisting of 200 breweries. The metadata reveals that there are 8195 breweries in total, which means we will need to loop through nearly 20 pages to obtain all of the data.

The code begins by calculating the number of pages we need to loop through:

brewery_count <- 8195/200

Next, we set the number of pages we need to loop through to 20:

brewery_pages <- 20

The base_url variable is then set to the URL of the API endpoint we will be accessing:

base_url <- "https://api.openbrewerydb.org/v1/breweries?per_page=200&page="

In the loop, we start with an empty data frame:

brewery_list <- data.frame()

Then, we use a for loop to loop through the pages of the API endpoint, using bind_rows() to add the data from each page to the brewery_list data frame:

for(i in 1:brewery_pages){
  brewery_list <- 
    fromJSON(paste(base_url,i,sep = "")) %>% 
    bind_rows(brewery_list, .)
  Sys.sleep(runif(1,5,15))
  print(paste("Page",i,"collected of",brewery_pages))
}

The fromJSON() function is used to extract the data from each page of the API, and bind_rows() is used to add it to brewery_list. Sys.sleep() is included to add a random delay between each page request, to avoid overwhelming the API. The loop also prints out which page is being collected out of the total number of pages, to give the user an idea of the progress.

APi Call outs

These are different call-outs or parameters that can be used in the API to filter or sort the results of the brewery search based on specific criteria:

“by_city” - this call-out filters the breweries by the city they are located in. You can use underscores or URL encoding for spaces in the city name.

Example: “https://api.openbrewerydb.org/v1/breweries?by_city=san_diego

“by_dist” - this call-out sorts the results by the distance of the breweries from a specific latitude and longitude point.

Example: “https://api.openbrewerydb.org/v1/breweries?by_dist=38.8977,77.0365

“by_name” - this call-out filters the breweries by their name. You can use underscores or URL encoding for spaces in the brewery name.

Example: “https://api.openbrewerydb.org/v1/breweries?by_name=cooper

“by_state” - this call-out filters the breweries by the state they are located in. The full state name is required, and abbreviations cannot be used. You can use underscores or URL encoding for spaces in the state name.

Example: “https://api.openbrewerydb.org/v1/breweries?by_state=new_york

“by_postal” - this call-out filters the breweries by the postal code. It can be filtered by basic (5 digit) postal code or more precisely filtered by postal+4 (9 digit) code. If filtering by postal+4, the search must include either a hyphen or an underscore.

Example: “https://api.openbrewerydb.org/v1/breweries?by_postal=44107

“by_type” - this call-out filters the breweries by their type. The brewery type must be one of the following: micro, nano, regional, brewpub, large (deprecated), planning, bar (deprecated), contract, proprietor, or closed.

Example: “https://api.openbrewerydb.org/v1/breweries?by_type=micro

Conclusion

In conclusion, Open Brewery DB is a fantastic resource for anyone interested in craft beer, including beer enthusiasts, brewers, and businesses in the beer industry. The database provides comprehensive information on breweries and beers from around the world, including brewery and beer names, locations, styles, and labels. The data is maintained by a community of contributors and is available for free through the Open Brewery DB API, making it a valuable resource for developers looking to build beer-related applications or websites.

Furthermore, the top 10 states in the United States with the highest number of breweries were listed in the document, providing useful information for anyone interested in exploring new breweries or investing in the industry. The code provided in the document can also be used to navigate the Open Brewery DB API and extract data about breweries.

Overall, Open Brewery DB is a reliable source of information for exploring the world of craft beer, and its API and community-driven approach make it a valuable resource for beer enthusiasts and businesses alike.