Article type: How-to guide (one task: list the open federal grants from chosen agencies that a 501(c)(3) nonprofit can apply for, with award amounts and deadlines, in a CSV)
Prerequisites: Python 3 with
requests(pip install requests). No API key or account: the Grants.gov API is public. An Apify account only if you use the hosted version at the end.Tested on: 15 November 2026, against the live Grants.gov API.
You work for a nonprofit, or help one, and want a shortlist of federal grants that are open now: who's funding, when it closes, how big the awards are, and whether your kind of organization can apply. Grants.gov lists every federal grant opportunity, and its API gives you all of that with no key. This guide pulls the open grants from two departments, the Department of Agriculture (USDA) and the Department of the Interior, and writes them to a CSV sorted by deadline.
All the data in this post comes from two Grants.gov API calls:
| Call | What it gives you |
|---|---|
search2 |
Matching opportunities: number, title, agency, open and close dates. Filters for status, agency, applicant type and funding category. |
fetchOpportunity |
One opportunity's details: award floor and ceiling, total funding, expected number of awards, cost sharing, eligible applicant types and the eligibility text. |
Both are POST requests to https://api.grants.gov/v1/api/... with a JSON body, and Grants.gov's docs say neither needs authentication.
How do I list the open grants my organization can apply for?
The script searches for posted opportunities from USDA and Interior agencies whose eligible applicants include 501(c)(3) nonprofits (code 12), "Others" (25) or anyone (99). It drops any whose close date has passed, fetches the details for the rest, and writes one row per grant. Save it as grants_open.py:
import csv
import html
import re
import time
from datetime import date, datetime
import requests
API = "https://api.grants.gov/v1/api"
AGENCIES = "USDA|USDA-*|DOI|DOI-*" # top-level code AND its sub-agencies (see gotcha 1)
ELIGIBLE = "12|25|99" # 12 = 501(c)(3) nonprofits, 25 = "Others", 99 = Unrestricted
TODAY = date.today()
def post(endpoint, body):
r = requests.post(f"{API}/{endpoint}", json=body, timeout=60)
r.raise_for_status()
data = r.json()
if data.get("errorcode") != 0: # the body has its own status: check it
raise RuntimeError(data.get("msg"))
time.sleep(0.3)
return data["data"]
def mdy(s):
"""Search dates are MM/DD/YYYY strings: parse them before you sort or compare."""
return datetime.strptime(s, "%m/%d/%Y").date() if s else None
def money(v):
"""Award fields are strings; 'none' or '' means not stated."""
try:
n = float(str(v).replace(",", ""))
return int(n) if n > 0 else ""
except (TypeError, ValueError):
return ""
def short(text, n=300):
"""Plain text, no email addresses, cut to n characters."""
t = re.sub(r"<[^>]+>", " ", html.unescape(text or ""))
t = re.sub(r"\S+@\S+", "", t)
return re.sub(r"\s+", " ", t).strip()[:n]
# 1. Search: every posted opportunity from these agencies open to these applicant types.
hits, start = [], 0
while True:
page = post("search2", {"oppStatuses": "posted", "agencies": AGENCIES, "eligibilities": ELIGIBLE,
"rows": 100, "startRecordNum": start})
hits += page["oppHits"]
start += len(page["oppHits"])
if not page["oppHits"] or start >= page["hitCount"]:
break
open_hits = [h for h in hits if not h["closeDate"] or mdy(h["closeDate"]) >= TODAY]
print(f"search2: {len(hits)} posted, {len(hits) - len(open_hits)} already past their close date, {len(open_hits)} kept")
# 2. Details: amounts and eligibility are only in fetchOpportunity. No contact fields are read.
rows = []
for h in open_hits:
d = post("fetchOpportunity", {"opportunityId": int(h["id"])})
s = d.get("synopsis") or {}
types = {t["id"] for t in s.get("applicantTypes") or []}
close = mdy(h["closeDate"])
rows.append({
"number": h["number"],
"title": html.unescape(h["title"]),
"agency": h["agency"],
"agency_code": h["agencyCode"],
"close_date": close.isoformat() if close else "",
"days_left": (close - TODAY).days if close else "",
"nonprofit_501c3": "listed" if "12" in types else ("unrestricted" if "99" in types else "check text"),
"eligibility_text": short(s.get("applicantEligibilityDesc")),
"award_floor": money(s.get("awardFloor")),
"award_ceiling": money(s.get("awardCeiling")),
"total_funding": money(s.get("estimatedFunding")),
"expected_awards": money(s.get("numberOfAwards")),
"cost_sharing": "yes" if s.get("costSharing") else "no",
"aln": " ".join(c["cfdaNumber"] for c in d.get("cfdas") or [] if c.get("cfdaNumber")),
"url": f"https://www.grants.gov/search-results-detail/{h['id']}",
})
# 3. Soonest deadline first; no close date last.
rows.sort(key=lambda r: (r["close_date"] == "", r["close_date"]))
with open("federal_grants.csv", "w", newline="") as f:
w = csv.DictWriter(f, fieldnames=list(rows[0]))
w.writeheader()
w.writerows(rows)
print(f"wrote {len(rows)} rows to federal_grants.csv")
for flag in ("listed", "unrestricted", "check text"):
print(f" 501(c)(3) {flag:<13}{sum(r['nonprofit_501c3'] == flag for r in rows):>3}")
print(f"\n{'close':<11}{'days':>5} {'501(c)(3)':<13}{'ceiling':>12} title")
for r in [r for r in rows if r["nonprofit_501c3"] != "check text"][:8]:
ceiling = f"${r['award_ceiling']:,}" if r["award_ceiling"] else "-"
print(f"{r['close_date'] or '-':<11}{r['days_left']:>5} {r['nonprofit_501c3']:<13}{ceiling:>12} {r['title'][:52]}")
Output on 15 November 2026:
search2: 77 posted, 12 already past their close date, 65 kept
wrote 65 rows to federal_grants.csv
501(c)(3) listed 9
501(c)(3) unrestricted 4
501(c)(3) check text 52
close days 501(c)(3) ceiling title
2026-11-19 4 listed $5,000,000 Easement Restoration and Stewardship
2026-11-30 15 listed $150,000 F26AS00023 FY2026 Prescott Marine Mammal Rescue and
2026-12-04 19 listed $1,000,000 Specialty Crop Multi-State Grant Program 2026
2026-12-07 22 listed $2,000,000 MPPEP Phase 3 Invasive Wild-Caught Catfish
2026-12-08 23 listed $1,000,000 Great Lakes Restoration Initiative: Community Forest
2026-12-31 46 unrestricted $100,000 F26AS00084 Aquatic Invasive Species Grants to Great
2026-12-31 46 unrestricted $600,000 F26AS00083 Aquatic Invasive Species Grants to Great
2026-12-31 46 unrestricted $923,809 F26AS00085 Aquatic Invasive Species Interjurisdictio
"listed" means 501(c)(3) nonprofits are one of the applicant types; "unrestricted" means any type of entity; "check text" means the grant was matched through "Others", so you have to read its eligibility text. Some columns from federal_grants.csv:
number,agency_code,close_date,nonprofit_501c3,award_floor,award_ceiling,total_funding,expected_awards,cost_sharing
USDA-NHQ-ACEP-26-NOFO0001456,USDA-NRCS,2026-11-19,listed,250000,5000000,,4,no
F26AS00023,DOI-FWS,2026-11-30,listed,,150000,2350000,21,yes
G27AS00084,DOI-USGS1,2026-11-30,check text,1,360000,360000,1,no
USDA-AMS-TM-SCMP-G-26-0020,USDA-AMS,2026-12-04,listed,250000,1000000,14300000,20,yes
Why it's built this way:
-
Filter by applicant type in the search.
eligibilitiesis a server-side filter, so you fetch details only for grants that could fit. -
Details only for what's left. Award amounts and eligibility aren't in the search results, so the script makes one
fetchOpportunitycall per kept grant (65 here), with a short pause between calls. -
Check
errorcode, not just the HTTP status. The response body carries its own status;0means success. -
No contact fields.
fetchOpportunityalso returns the agency contact's name, email and phone. The script never reads them, and strips email addresses from the eligibility text, so the CSV holds grant data only.
What should I check before I trust the list?
-
A top-level agency code can return nothing.
agencies: "USDA"returned 0 posted grants and"DOI"returned 0, even though the search's own agency counts showed USDA 20 and DOI 62. The grants sit under sub-agency codes such asUSDA-NRCSandDOI-FWS, whichUSDA-*matches. It isn't always that way round:DOCreturned 8,DOC-*17, and you needDOC|DOC-*to get all 25. Send both forms, as the script does. -
"501(c)(3) nonprofits" alone misses most of the list. With these two departments, eligibility code
12returned 9 grants,12|99returned 14, and12|25|99returned 77. Many agencies tick "Others" (25) and put the real rule in the eligibility text. - Then read the eligibility text. 30 of the 65 open rows were cooperative agreements for partners of a Cooperative Ecosystem Studies Unit, and the text says only participating partners of that unit can apply. A "listed" row can be narrow too: the marine mammal rescue grant above is for "eligible marine mammal stranding participants" and "stranding network collaborators". Treat the code as a first filter, not the answer.
- "Posted" doesn't mean "still open". 12 of the 77 had a close date of 14 November. The script treated them as past because we ran it just after midnight GMT on 15 November, which was still the evening of 14 November on the US East Coast. The search's close date has no time or time zone, so check the deadline in the notice itself before you rule one in or out.
-
Dates are
MM/DD/YYYYstrings. Sorted as text, the earliest close date in the raw results came out as01/04/2027; parsed as dates, it was11/14/2026. Parse before you sort or compare. -
Award amounts need a second look. 31 rows had an award floor of $1, which looks like a placeholder, and 34 had a ceiling equal to the total funding, so one award could take the whole amount. The fields are strings and can be
none. Two rows had no ceiling and 6 had no floor. - The close date isn't always the next deadline. One grant had no close date at all, and four closed more than a year out (up to November 2030), including two recurring five-year notices and a master cooperative agreement. Read the notice for the actual application windows.
-
The live field names differ from the docs' sample. The
fetchOpportunitysample showsalnswithalnNumber; the live response hadcfdaswithcfdaNumber, and one entry with no number. Read fields with.get().
To change the search, edit AGENCIES and ELIGIBLE (the search response's eligibilities list gives every code and its label), or add "fundingCategories" to the search body.
The hosted version (Disclosure: we built this)
We built an Apify Actor, SAM.gov Scraper: Government Contracts, Bids & Federal Grants, that reads the same search2 and fetchOpportunity calls live on every run. Set opportunityType to grants and it returns one row per grant with the award ceiling and floor, estimated total funding, expected number of awards, assistance listings, funding categories, eligible applicant types and attachments. Point-of-contact fields are off by default. Its agency filter matches text in the agency name or agency code, so USDA also catches USDA-NRCS, and dueAfter keeps only grants that close on or after a date (grants with no close date are left out when you set it). It doesn't filter by applicant type or read the eligibility text, so check those columns and the notice yourself. Monitor mode returns only grants it hasn't returned before, and it can add SAM.gov contract opportunities in the same layout. It's pay per event, charged per opportunity row returned; the prices are on the Actor's Pricing tab. For example (not run for this post):
{
"opportunityType": "grants",
"agencies": ["USDA", "DOI"],
"grantStatuses": ["posted"],
"postedSince": "2018-01-01",
"dueAfter": "2026-11-15",
"maxResults": 0
}
SAM.gov & Grants.gov Scraper on Apify
Data: Grants.gov API (search2 and fetchOpportunity), read 15 November 2026. Opportunity details are as posted by the agencies. This post and the Actor are not affiliated with or endorsed by Grants.gov, the U.S. Department of Health and Human Services or any agency named.
Your Evenings
Top comments (0)