BrazilDataAPI: Access Brazilian Data via APIs and Curated Datasets"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(BrazilDataAPI)
library(ggplot2)
library(dplyr)

Introduction

The BrazilDataAPI package provides a unified interface to access open data from the BrasilAPI, REST Countries API, Nager.Date API, and World Bank API, with a focus on Brazil. It allows users to easily retrieve up-to-date information on postal codes, banks, economic indicators, holidays, company registrations, international country-level data, public holidays information, and economic development data relevant to Brazil.

In addition to API-access functions, the package includes a collection of curated datasets related to Brazil, covering diverse domains such as demographics (male and female population by state and year), river levels in Manaus, environmental emission factors in São Paulo, Brazilian film festivals, and historical yellow fever outbreaks.

BrazilDataAPI is designed to support research, teaching, and data analysis focused on Brazil by integrating public RESTful APIs with high-quality, domain-specific datasets from multiple domains into a single, easy-to-use R package.

Functions for BrazilDataAPI

The BrazilDataAPI package provides several core functions to access real-time and structured information about Brazil from public APIs such as BrasilAPI, REST Countries, Nager.Date API, and World Bank API. Below is a list of the main functions included in the package:

These functions allow users to access high-quality and structured information on Brazil, which can be combined with tools like dplyr, tidyr, and ggplot2 to support a wide range of data analysis and visualization tasks. In the following sections, you’ll find examples on how to work with BrazilDataAPI in practical scenarios.

List official interest rates and indexes from the BrasilAPI

# Retrieves official interest rates and indexes from the BrazilAPI

brazil_rates_001 <- get_brazil_rates()

print(brazil_rates_001)

Get Vehicle Brands from BrasilAPI (FIPE Data)

# A string indicating the type of vehicle. Must be one of "carros", "motos", or "caminhoes".

brazil_vehicles <- get_brazil_vehicle_brands("motos")

print(brazil_vehicles)

Get Municipalities of a Brazilian State

# A two-letter string representing the Brazilian state abbreviation (e.g., "SP", "RJ", "BA").

brazil_Municipalities <- get_brazil_municipalities("SP")

print(brazil_Municipalities)

Brazil's GDP (Current US$) from World Bank 2022 - 2017

brazil_gdp <- head(get_brazil_gdp())

print(brazil_gdp)

Brazil's Life Expectancy at Birth from World Bank 2022 - 2017

brazil_life_expectancy <- head(get_brazil_life_expectancy())

print(brazil_life_expectancy)

Female Deaths by Age Group in Brazil

# Summarize total deaths by age and year
df_plot <- Brasil_females_df %>%
  group_by(year1, age) %>%
  summarise(total_deaths = sum(deaths, na.rm = TRUE), .groups = "drop")

# Plot: Deaths by age group over time
ggplot(df_plot, aes(x = age, y = total_deaths, color = as.factor(year1))) +
  geom_line(size = 1) +
  labs(
    title = "Female Deaths by Age Group in Brazil",
    subtitle = "Aggregated by year (year1)",
    x = "Age",
    y = "Number of Deaths",
    color = "Year"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(face = "bold", size = 14),
    legend.position = "bottom"
  )

Dataset Suffixes

Each dataset in BrazilDataAPI is labeled with a suffix to indicate its structure and type:

Datasets Included in BrazilDataAPI

In addition to API access functions, BrazilDataAPI provides several preloaded datasets offering insights into Brazil's demographic structure, environmental conditions, cultural events, and public health records. Here are some featured examples:

Conclusion

The BrazilDataAPI package provides a robust set of tools to access open data about Brazil through RESTful APIs and curated datasets. It includes functions to retrieve information about postal codes, banks, economic rates, company registrations, and holidays via the BrasilAPI, international country indicators through the REST Countries API, public holidays information through the Nager.Date API, and economic development data through the World Bank API. Additionally, it offers preloaded datasets on Brazil's male and female population by state and year, film festivals, São Paulo's emission factors, river data from Manaus, and records of yellow fever outbreaks.



Try the BrazilDataAPI package in your browser

Any scripts or data that you put into this service are public.

BrazilDataAPI documentation built on Sept. 15, 2025, 9:09 a.m.