DEV Community

carrierone
carrierone

Posted on

Federal Contract Award Data (USASpending) via API

Federal Contract Award Data via API

When building tools for federal procurement analytics or government contractor business development, having access to accurate and up-to-date contract award data is crucial. One of the main sources of this information is USASpending.gov, which provides extensive details on contracts awarded by various agencies. To make it more accessible programmatically, the Federal Procurement Data Service offers an API endpoint where you can search for federal contracts using different parameters such as agency, vendor, and NAICS code.

Problem: Searching Contracts Using Different Parameters

Let's say we want to find all government contracts that have been awarded to a specific company or related to a particular industry. We need to perform searches based on the company name or NAICS code (a five-digit number used to classify economic activity). Below is an example of how you can use Python to query this API and filter results based on those parameters.

Solution: Searching Contracts Using USASpending.gov API


python
import requests

def search_contracts(api_key, agency=None, vendor_name=None, naics_code=None):
    base_url = "https://api.asdf.com/usaspending/v1/search"

    params = {}
    if agency:
        params['agency'] = agency
    if vendor_name:
        params['vendorName'] = vendor_name
    if naics_code:
        params['naicsCode']
Enter fullscreen mode Exit fullscreen mode

Top comments (0)