Create a research table in Python
Fetch a small notice set and write selected fields to CSV.
Before you start
You need active GovBiz API access and a key with the search permission. Create your key first.
Use Python 3.12 or later. The example uses the standard library. Save your key in GOVBIZ_API_KEY.
Each request uses your shared workspace allowance. The examples do not send email or update another service.
Run the example
Save the code in query.py. Run it with python3 query.py.
import csv, json, os, urllib.request
url = "https://www.govbiz.ai/api/v2/opportunities/search?naics_code=541512&limit=10"
request = urllib.request.Request(url, headers={
"Authorization": "Bearer " + os.environ["GOVBIZ_API_KEY"]
})
with urllib.request.urlopen(request, timeout=30) as response:
result = json.load(response)
links = {c["id"]: c["url"] for c in result.get("citations", [])}
with open("notices.csv", "w", newline="", encoding="utf-8") as output:
writer = csv.writer(output)
writer.writerow(["notice_id", "title", "posted_date", "source_url"])
for row in result["data"]["results"]:
# Prevent spreadsheet formula execution when importing public text.
title = row.get("title") or ""
if title.lstrip().startswith(("=", "+", "-", "@")):
title = "'" + title
writer.writerow([row["notice_id"], title,
row.get("posted_date"), links.get(row["notice_id"], "")])
print("Saved notices.csv")Check the result
Open notices.csv. It contains notice identifiers, titles, posted dates, and source links.
Live results change. Compare the response shape with our captured sample and check the original notices.
Limits and care
Keep credentials out of shared code, browser bundles, and workbooks you distribute. Excel parameters may be visible to people who can open the workbook.
Check HTTP errors before using results. Retry temporary errors with a delay. Avoid repeated retries for authentication failures.
These examples use explicit filters. They do not make bid decisions or produce proposals.