SAM.gov API Python Client
Python wrapper for the SAM.gov (System for Award Management) public API. Provides access to entity registration data, opportunities, exclusions, and other federal procurement data from SAM.gov. Simplifies authentication and pagination when querying the SAM.gov API endpoints.
Warnings
- breaking A valid SAM.gov API key is required for all requests. Without it, every call returns a 403 Forbidden error.
- gotcha SAM.gov API has strict rate limits (typically 10 requests per second for public keys). Exceeding the limit returns HTTP 429 responses with no automatic retry.
- gotcha The package name uses hyphens (sam-gov-api) but the Python import uses underscores (sam_gov_api).
- gotcha SAM.gov API response structures vary between endpoints (entities, opportunities, exclusions). Fields are not guaranteed to be present in every response record.
- gotcha Pagination is 1-indexed, not 0-indexed. Passing page=0 may return unexpected results or errors.
Install
-
pip install requests
Imports
- SAMClient
from sam_gov_api import SAMClient
- sam_gov_api
import sam_gov_api
Quickstart
import os
import requests
api_key = os.environ.get("SAM_GOV_API_KEY", "DEMO_KEY")
resp = requests.get(
"https://api.sam.gov/entity-information/v3/entities",
params={"api_key": api_key, "purposeOfRegistrationCode": "Z2", "entityEFTIndicator": "", "samRegistered": "Yes"},
headers={"Accept": "application/json"}
)
resp.raise_for_status()
data = resp.json()
print(f"Total records: {data.get('totalRecords', 0)}")