DEV Community

carrierone
carrierone

Posted on

Federal Contract Award Data (USASpending) via API

Federal Contract Award Data (USASpending) via API

Federal agencies award billions of dollars annually through various contracting mechanisms. As developers, we can access these transactions through the USASpending API to build tools for procurement analytics and business development. To search contracts by agency, vendor, or NAICS code, you'll need a Python script that interacts with this API.

Problem: Searching for Federal Contract Award Data

Let's say you're developing software that needs to filter federal contract awards based on the contracting agency or vendor name. Without an API endpoint to query these data points directly, we'd have to scrape websites manually, which is error-prone and might violate terms of service policies.

Solution: Python Code Example

Here’s a simple example using requests and json libraries in Python to search for federal contracts based on the agency name:


python
import requests

def get_federal_contracts_by_agency(agency_name):
    url = f"https://verilexdata.com/api/search?query=contract_award&agencies={agency_name}"
    headers = {
        "User-Agent": "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2)"
    }

    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        contracts = response.json
Enter fullscreen mode Exit fullscreen mode

Top comments (0)