Excel remains the standard tool for real estate financial models. This tutorial uses Python and openpyxl to build a populated investment workbook from API data automatically.
Requirements
pip install requests openpyxl
Fetching Data and Building Workbook
import requests, openpyxl
from openpyxl.styles import Font, PatternFill, Alignment
from openpyxl.utils import get_column_letter
KEY = "your_key"
ZIPS = ["78701", "30301", "85001", "37201"]
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "Investment Analysis"
# Header row
headers = ["ZIP Code","Median Price","2BR Rent","Gross Yield","DOM","YoY Change","Temp"]
for c, h in enumerate(headers, 1):
cell = ws.cell(row=1, column=c, value=h)
cell.font = Font(bold=True)
cell.fill = PatternFill("solid", fgColor="111009")
cell.font = Font(bold=True, color="FFFFFF")
# Data rows
for row, z in enumerate(ZIPS, 2):
ms = requests.get("https://zipmarketdata.com/market-stats",
params={"zip_code": z},
headers={"x-rapidapi-proxy-secret": KEY}).json()
ry = requests.get("https://zipmarketdata.com/rental-yield",
params={"zip_code": z, "bedrooms": 2},
headers={"x-rapidapi-proxy-secret": KEY}).json()
ws.cell(row, 1, z)
ws.cell(row, 2, ms.get("median_sale_price"))
ws.cell(row, 3, ry.get("fair_market_rent"))
ws.cell(row, 4, ry.get("gross_yield_pct"))
ws.cell(row, 5, ms.get("median_days_on_market"))
ws.cell(row, 6, ms.get("yoy_price_change"))
ws.cell(row, 7, ms.get("market_temperature"))
wb.save("investment_analysis.xlsx")
print("Saved investment_analysis.xlsx")