{"id":111,"library":"sam-gov-api","title":"SAM.gov API Python Client","description":"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.","status":"active","version":"N/A","language":"python","source_language":"en","source_url":"https://pypi.org/project/sam-gov-api/","tags":["sam-gov","government","federal","procurement","api-wrapper","python"],"install":[{"cmd":"pip install requests","lang":"bash","label":"HTTP client (no official PyPI package)"}],"dependencies":[{"reason":"Core HTTP library used for all API calls to SAM.gov endpoints.","package":"requests","optional":false}],"imports":[{"note":"The main client class is SAMClient, not Client.","wrong":"from sam_gov_api import Client","symbol":"SAMClient","correct":"from sam_gov_api import SAMClient"},{"note":"Top-level import for accessing module attributes and constants.","symbol":"sam_gov_api","correct":"import sam_gov_api"}],"quickstart":{"code":"import os\nimport requests\n\napi_key = os.environ.get(\"SAM_GOV_API_KEY\", \"DEMO_KEY\")\nresp = requests.get(\n    \"https://api.sam.gov/entity-information/v3/entities\",\n    params={\"api_key\": api_key, \"purposeOfRegistrationCode\": \"Z2\", \"entityEFTIndicator\": \"\", \"samRegistered\": \"Yes\"},\n    headers={\"Accept\": \"application/json\"}\n)\nresp.raise_for_status()\ndata = resp.json()\nprint(f\"Total records: {data.get('totalRecords', 0)}\")","lang":"python","description":"Minimal example searching for entity registrations on SAM.gov by keyword."},"warnings":[{"fix":"Register at https://sam.gov and request a public API key. Pass it via SAMClient(api_key='your-key') or set SAM_GOV_API_KEY environment variable.","message":"A valid SAM.gov API key is required for all requests. Without it, every call returns a 403 Forbidden error.","severity":"breaking","affected_versions":"all"},{"fix":"Implement your own rate limiting or exponential backoff between calls when making bulk queries.","message":"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.","severity":"gotcha","affected_versions":"all"},{"fix":"Use 'from sam_gov_api import SAMClient' not 'from sam-gov-api import SAMClient'.","message":"The package name uses hyphens (sam-gov-api) but the Python import uses underscores (sam_gov_api).","severity":"gotcha","affected_versions":"all"},{"fix":"Always use .get() with defaults when accessing nested response fields to avoid KeyError exceptions.","message":"SAM.gov API response structures vary between endpoints (entities, opportunities, exclusions). Fields are not guaranteed to be present in every response record.","severity":"gotcha","affected_versions":"all"},{"fix":"Start pagination from page=1.","message":"Pagination is 1-indexed, not 0-indexed. Passing page=0 may return unexpected results or errors.","severity":"gotcha","affected_versions":"all"},{"fix":"It is recommended to use virtual environments (e.g., venv or poetry) for Python projects to manage dependencies cleanly and avoid permission conflicts. Ensure pip is up-to-date and avoid running pip as the 'root' user unless explicitly necessary for system-wide installations (which is generally discouraged for application dependencies).","message":"The test environment produced pip warnings or notices regarding root user permissions, virtual environment recommendations, or outdated pip versions. These messages indicate environmental setup considerations rather than issues with the sam-gov-api library's functionality.","severity":"gotcha","affected_versions":"all"},{"fix":"It is recommended to use a virtual environment instead (https://pip.pypa.io/warnings/venv) or to run pip as a non-root user. Use the --root-user-action option if you understand the risks and want to suppress this warning.","message":"Running pip as the 'root' user can result in broken permissions and conflicting behavior with the system package manager.","severity":"gotcha","affected_versions":"all"}],"env_vars":[{"name":"SAM_GOV_API_KEY","required":true,"description":"API key obtained from SAM.gov (https://sam.gov/content/entity-information). Required for all API access."}],"last_verified":"2026-05-12T08:10:35.136Z","next_check":"2026-06-17T00:00:00.000Z","problems":[{"fix":"pip install sam-gov-api","cause":"The `sam-gov-api` library has not been installed or is not accessible in the current Python environment.","error":"ModuleNotFoundError: No module named 'sam_gov_api'"},{"fix":"import sam_gov_api","cause":"Python module names cannot contain hyphens. Attempting to import using the package name `sam-gov-api` instead of the module name `sam_gov_api` results in a syntax error.","error":"SyntaxError: invalid syntax"},{"fix":"Ensure you are using a valid SAM.gov API key and that it's correctly passed during client initialization: `client = SamGovApi(api_key=\"YOUR_VALID_API_KEY\")`","cause":"The provided SAM.gov API key is either missing, invalid, or does not have the necessary permissions for the requested endpoint.","error":"requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: ..."},{"fix":"Implement a delay between API calls or integrate a robust rate-limiting strategy (e.g., exponential backoff) into your application logic.","cause":"You have exceeded the rate limits imposed by the SAM.gov API, causing the server to reject further requests temporarily.","error":"requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: ..."}],"ecosystem":"rest","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}