DEV Community

Your Evenings Data
Your Evenings Data

Posted on

Find open SAM.gov small-business set-aside bids, sorted by response deadline, in a CSV (Python, no API key)

Article type: How-to guide (one task: list the open SAM.gov bids set aside for small businesses, sorted by response deadline, in a CSV)

Prerequisites: Python 3.9 or later with requests (pip install requests), and about 250 MB of free disk space. No SAM.gov API key or account: the file is public. An Apify account only if you use the hosted version at the end.

Tested on: 17 November 2026, against SAM.gov's public Contract Opportunities extract dated 17 November 2026.

Your business qualifies for a small-business set-aside, maybe 8(a), HUBZone, service-disabled veteran-owned (SDVOSB) or women-owned (WOSB), and you want one list of every open federal bid reserved for businesses like yours, soonest deadline first. SAM.gov publishes every active contract notice in one public CSV file that it regenerates once a day, and you don't need an API key to download it. This guide reads that file and writes the open set-aside solicitations due in the next 30 days to a CSV.

The notice counts and examples in this post come from one file:

https://sam.gov/api/prod/fileextractservices/v1/api/download/Contract%20Opportunities/datagov/ContractOpportunitiesFullCSV.csv?privacy=Public

It was 219 MB with 72,286 notices when we ran this. It's encoded as Windows-1252 (cp1252), not UTF-8, and each row carries the notice type, the set-aside code and label, the response deadline, NAICS and product/service codes, the place of performance and a link to the notice.

How do I list the open set-aside bids I can respond to?

The script downloads the file, keeps solicitations and combined synopsis/solicitations whose set-aside code is one of seven small-business codes, keeps the newest notice for each solicitation number, and writes those due in the next 30 days to set_aside_bids.csv. Save it as set_aside_bids.py:

import csv
import json
from collections import Counter
from datetime import datetime, timedelta, timezone
from zoneinfo import ZoneInfo

import requests

EXTRACT = ("https://sam.gov/api/prod/fileextractservices/v1/api/download/Contract%20Opportunities/"
           "datagov/ContractOpportunitiesFullCSV.csv?privacy=Public")
SET_ASIDES = {                      # competitive small-business set-asides (sole-source codes left out, see gotcha 3)
    "SBA": "Small business", "SBP": "SB partial", "8A": "8(a)",
    "HZC": "HUBZone", "SDVOSBC": "SDVOSB", "WOSB": "WOSB", "EDWOSB": "EDWOSB",
}
BID_TYPES = {"Solicitation", "Combined Synopsis/Solicitation"}
DAYS_AHEAD = 30
EASTERN = ZoneInfo("America/New_York")
NOW = datetime.now(timezone.utc)

# 1. Download the whole extract to disk. Open notices can be years old, so you can't stop early.
with requests.get(EXTRACT, stream=True, timeout=600) as r:
    r.raise_for_status()
    extract_date = r.headers.get("Last-Modified")
    with open("opportunities.csv", "wb") as f:
        for chunk in r.iter_content(1 << 20):
            f.write(chunk)
print(f"extract Last-Modified: {extract_date}")


def set_aside_code(raw):
    """Most rows hold a plain code ('SBA'); some hold a JSON list ('["SBA"]')."""
    raw = (raw or "").strip()
    if raw.startswith("["):
        codes = [c for c in json.loads(raw) if c]
        return codes[0] if codes else ""
    return raw


def deadline(raw):
    """Return (UTC datetime, how the time zone was known). Date-only and no-offset values are read as US Eastern."""
    raw = (raw or "").strip()
    if not raw:
        return None, "none"
    if len(raw) == 10:                                  # '2026-11-27': no time at all
        d = datetime.fromisoformat(raw).replace(hour=23, minute=59, tzinfo=EASTERN)
        return d.astimezone(timezone.utc), "date only"
    d = datetime.fromisoformat(raw)
    if d.tzinfo is None:                                # '2026-12-04T17:00:00': no offset
        return d.replace(tzinfo=EASTERN).astimezone(timezone.utc), "no offset"
    return d.astimezone(timezone.utc), "offset given"


# 2. Keep bid notices with these set-asides; one per solicitation number (the newest notice wins,
#    because an amendment is posted as a new notice under the same number).
seen = Counter()
latest = {}
with open("opportunities.csv", encoding="cp1252", newline="") as f:
    for row in csv.DictReader(f):
        seen["rows"] += 1
        code = set_aside_code(row["SetASideCode"])
        if row["Type"] not in BID_TYPES or code not in SET_ASIDES:
            continue
        seen["notices"] += 1
        key = row["Sol#"].strip() or row["NoticeId"]
        if key not in latest or row["PostedDate"] > latest[key][0]["PostedDate"]:
            latest[key] = (row, code)

# 3. Keep solicitations whose (newest) response deadline is between now and DAYS_AHEAD days out.
rows = []
for row, code in latest.values():
    due, tz_basis = deadline(row["ResponseDeadLine"])
    if due is None or not (NOW <= due <= NOW + timedelta(days=DAYS_AHEAD)):
        continue
    rows.append({
        "response_deadline_utc": due.strftime("%Y-%m-%d %H:%M"),
        "days_left": (due - NOW).days,
        "deadline_as_posted": row["ResponseDeadLine"],
        "deadline_tz": tz_basis,
        "set_aside": SET_ASIDES[code],
        "set_aside_code": code,
        "notice_type": row["Type"],
        "title": row["Title"].strip(),
        "agency": row["Department/Ind.Agency"].strip(),
        "sub_tier": row["Sub-Tier"].strip(),
        "naics": row["NaicsCode"].strip(),
        "psc": row["ClassificationCode"].strip(),
        "pop_state": row["PopState"].strip(),
        "solicitation_number": row["Sol#"].strip(),
        "posted": row["PostedDate"],
        "url": f"https://sam.gov/opp/{row['NoticeId']}/view",
    })

rows.sort(key=lambda r: r["response_deadline_utc"])
with open("set_aside_bids.csv", "w", newline="") as f:
    w = csv.DictWriter(f, fieldnames=list(rows[0]))
    w.writeheader()
    w.writerows(rows)

print(f"{seen['rows']:,} rows read; {seen['notices']:,} bid notices with these set-asides; "
      f"{len(latest):,} solicitations; {len(rows):,} due in the next {DAYS_AHEAD} days")
for label, n in Counter(r["set_aside"] for r in rows).most_common():
    print(f"  {label:<16}{n:>5}")
print(f"\n{'due (UTC)':<18}{'set-aside':<16}{'NAICS':<8}title")
for r in rows[:8]:
    print(f"{r['response_deadline_utc']:<18}{r['set_aside']:<16}{r['naics']:<8}{r['title'][:42]}")
Enter fullscreen mode Exit fullscreen mode

Output on 17 November 2026 (about 15:24 GMT):

extract Last-Modified: Tue, 17 Nov 2026 04:30:19 GMT
72,286 rows read; 20,159 bid notices with these set-asides; 11,993 solicitations; 2,657 due in the next 30 days
  Small business   2072
  SDVOSB            304
  HUBZone           173
  WOSB               85
  8(a)               12
  SB partial         11

due (UTC)         set-aside       NAICS   title
2026-11-17 16:00  Small business  811310  Material Handling Equipment (MHE) Repair S
2026-11-17 16:00  Small business  722310  3655 CICO AT Meals 30 Nov - 12 Dec 2026 Ca
2026-11-17 17:00  Small business  336611  TSV4 NARR MESSING AND MODERNIZATION
2026-11-17 17:00  Small business  311999  FY27 FCI Loretto 2nd Qtr Subsistence Dry G
2026-11-17 17:00  Small business  311812  FY27 FCI LORETTO 2nd QTR Bread
2026-11-17 17:00  Small business  424430  FY27 FCI LORETTO 2nd QTR Dairy
2026-11-17 17:00  Small business  311999  FY27 FCI LORETTO 2nd QTR Halal-Kosher
2026-11-17 17:00  Small business  311999  FY27 FCI LORETTO 2nd QTR Meat
Enter fullscreen mode Exit fullscreen mode

Some columns from set_aside_bids.csv:

solicitation_number,set_aside_code,deadline_as_posted,deadline_tz,response_deadline_utc,agency,pop_state
N0018927QL011,SBA,2026-11-17T11:00:00-05:00,offset given,2026-11-17 16:00,DEPT OF DEFENSE,MS
W912LP27Q3001,SBA,2026-11-17T10:00:00-06:00,offset given,2026-11-17 16:00,DEPT OF DEFENSE,IA
N0018927QL008,SBA,2026-11-17T12:00:00-05:00,offset given,2026-11-17 17:00,DEPT OF DEFENSE,VA
15B20827Q00000001,SBA,2026-11-17T12:00:00-05:00,offset given,2026-11-17 17:00,"JUSTICE, DEPARTMENT OF",PA
15B20827Q00000002,SBA,2026-11-17T12:00:00-05:00,offset given,2026-11-17 17:00,"JUSTICE, DEPARTMENT OF",PA
Enter fullscreen mode Exit fullscreen mode

Why it's built this way:

  • Read the whole file. The file is sorted by posted date, newest first, so a "posted today" digest can stop early. A list of everything still open can't: 682 of the 2,657 solicitations were posted more than seven days before the run, and the oldest on 14 November 2025.
  • Keep the newest notice per solicitation number. An amendment is posted as a new notice under the same number. Of 23,383 solicitation numbers on bid notices, 6,066 had more than one notice, 3,775 of those with different deadlines across their notices and 447 with different set-aside codes. Without collapsing them you'd get 3,292 rows instead of 2,657. Collapse first and filter by date second: done the other way round, 11 solicitations stayed on the list with an old notice's deadline, even though their newest notice had moved the deadline past the 30-day window or into the past.
  • Bid notices only. The file also holds 11,540 award notices plus presolicitations, sources sought and special notices. Those can be worth watching, but you can't submit a bid against most of them yet.
  • No contact columns. Each row also has a primary and a secondary point of contact, with name, email and phone. The script doesn't copy them, so the CSV holds notice data only.

What should I check before I trust the list?

  1. Most notices have no set-aside code at all. 41,297 of the 72,286 rows had an empty SetASideCode and 5,864 had NONE. Filter on the codes you want, and don't read an empty code as a set-aside.
  2. Some codes are JSON lists. 201 rows, all from one department, held ["SBA"] (189) or [""] (12) in the code column with an empty label. None of them was due in our 30-day window, but a plain == "SBA" test skips them without telling you. The script unwraps the list.
  3. Sole-source codes aren't open competitions. 8AN, SDVOSBS, HZS and WOSBSS (41, 83, 18 and 19 bid notices here) are the sole-source versions of the 8(a), SDVOSB, HUBZone and WOSB codes. The script leaves them out; add them to SET_ASIDES if you want to see them.
  4. Deadlines come in four shapes. Across the file, 51,272 deadlines had a UTC offset, 11,958 were a date with no time, 702 had a time but no offset and 8,354 were empty. In our 2,657 rows, 1,787 were date only and 8 had a time but no offset. Most date-only deadlines are on combined synopsis/solicitations (11,714 of the 11,958). The script reads a date-only deadline as 23:59 US Eastern on that date and a time with no offset as US Eastern. That's our assumption, not SAM.gov's, and a rough one: only 37,601 of the 51,272 deadlines with an offset (73%) used -05:00 or -04:00, the offsets US Eastern uses. So the CSV keeps the original text in deadline_as_posted and says which case applied in deadline_tz. Check the notice before you plan around a date-only deadline or one with no offset.
  5. Don't sort the deadline text. The offsets ranged from -10:00 to +13:00 (26 different ones), because notices are posted from many time zones, overseas places of performance included. Sorted as text, 2,580 of the 2,657 rows land in a different position from the real order. For example, 2026-11-17T10:00:00-08:00 (18:00 UTC) sorts before 2026-11-17T11:00:00-05:00 (16:00 UTC). Convert to UTC first, as the script does.
  6. Place of performance is often empty. 2,096 of the 2,657 rows had no state. If you filter by state, decide what to do with those rows instead of dropping them silently.
  7. The file is about a day behind. Ours was dated 04:30 GMT on 17 November, so notices posted or amended after that weren't in it. Check Last-Modified and the notice page on SAM.gov before you bid.

To change the list, edit SET_ASIDES, BID_TYPES (add "Sources Sought" for early market research notices) or DAYS_AHEAD, or add a NAICS test on row["NaicsCode"].

The hosted version (Disclosure: we built this)

We built an Apify Actor, SAM.gov Scraper: Government Contracts, Bids & Federal Grants, that reads the same public extract on every run, so it needs no SAM.gov key either. Set opportunityType to contracts and list codes in setAsideTypes. It reads list-style codes such as ["SBA"] (gotcha 2) as the plain code, so they match your filter and come back as SBA; a notice with several codes comes back as, for example, SBA,8A and matches a filter on any of them, and an empty list counts as no code. A date-only deadline comes back as the date itself (for example 2026-11-27) with responseDeadlineHasTime: false, and a deadline with a time comes back with responseDeadlineHasTime: true: as a UTC timestamp when SAM.gov gives an offset or the notice text states the zone, otherwise as the local time SAM.gov gave with no Z, and responseDeadlineTimeZoneBasis says which. All 8 no-offset deadlines in our 2,657 rows would come back as local times, marked unknown. The Actor doesn't sort by deadline, because date-only values and timestamps have to be converted to one form first. dueAfter keeps notices whose deadline falls on or after a date, compared by calendar date, and leaves out notices with no deadline when you set it. Two things it still doesn't do. It returns one row per notice, so amendments under one solicitation number come back as separate rows: keep one row per solicitationNumber, and check the notice pages when two notices share the newest date (1,387 solicitations in the file have two or more notices on the same newest date). The 'Solicitation' filter also returns presolicitations and combined synopsis/solicitations, so drop Presolicitation rows if you only want bids. The default window is notices posted in the last seven days, so set postedSince to reach older open notices. It adds a free warning row when the extract is more than 36 hours old or empty, contact fields are off by default, and monitor mode returns only notices it hasn't returned before. 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": "contracts",
  "setAsideTypes": ["SBA", "SBP", "8A", "HZC", "SDVOSBC", "WOSB", "EDWOSB"],
  "samNoticeTypes": ["Solicitation"],
  "postedSince": "2025-01-01",
  "dueAfter": "2026-11-17",
  "maxResults": 0
}
Enter fullscreen mode Exit fullscreen mode

SAM.gov Scraper on Apify

Data: SAM.gov Contract Opportunities public extract (Data Services), file dated 17 November 2026, read 17 November 2026. Notices are as posted by the agencies. This post and the Actor are not affiliated with or endorsed by SAM.gov, the U.S. General Services Administration or any agency named.

Your Evenings

Top comments (0)