Government Contracts API
Retrieve federal government contract awards from USAspending.gov mapped to stock tickers. Track contract values, awarding agencies, industry classifications, and contract periods.
Endpoint
Section titled “Endpoint”GET /v2/government-contracts/{symbol}Authentication
Section titled “Authentication”The API supports multiple authentication methods:
| Method | Example |
|---|---|
| Bearer token (recommended) | Authorization: Bearer YOUR_API_KEY |
| X-API-Key header | X-API-Key: YOUR_API_KEY |
| Query parameter | ?apiKey=YOUR_API_KEY |
| Legacy query parameter | ?token=YOUR_API_KEY |
Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
symbol | string | Yes | Stock ticker symbol (e.g., LMT, RTX) |
Query Parameters
Section titled “Query Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
startDate | string | No | Start date (YYYY-MM-DD) |
endDate | string | No | End date (YYYY-MM-DD) |
limit | integer | No | Maximum number of results to return (1-500) |
Request
Section titled “Request”from finbrain import FinBrainClient
fb = FinBrainClient(api_key="YOUR_API_KEY")
df = fb.government_contracts.ticker("LMT", date_from="2025-01-01", date_to="2025-12-31", as_dataframe=True)print(df)curl -H "Authorization: Bearer YOUR_API_KEY" \ "https://api.finbrain.tech/v2/government-contracts/LMT"import requests
headers = {"Authorization": "Bearer YOUR_API_KEY"}
response = requests.get( "https://api.finbrain.tech/v2/government-contracts/LMT", headers=headers, params={"limit": 10})data = response.json()
for c in data["data"]["contracts"]: print(f"{c['startDate']}: ${c['awardAmount']:,.0f} " f"from {c['awardingAgency']} — {c['description']}")#include <iostream>#include <string>#include <curl/curl.h>#include <nlohmann/json.hpp>
using json = nlohmann::json;
size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* userp) { userp->append((char*)contents, size * nmemb); return size * nmemb;}
json get_government_contracts(const std::string& symbol, const std::string& api_key) { CURL* curl = curl_easy_init(); std::string response;
if (curl) { std::string url = "https://api.finbrain.tech/v2/government-contracts/" + symbol;
struct curl_slist* headers = nullptr; std::string auth_header = "Authorization: Bearer " + api_key; headers = curl_slist_append(headers, auth_header.c_str());
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); curl_easy_perform(curl); curl_slist_free_all(headers); curl_easy_cleanup(curl); }
return json::parse(response);}
int main() { auto result = get_government_contracts("LMT", "YOUR_API_KEY");
for (auto& c : result["data"]["contracts"]) { std::cout << c["startDate"].get<std::string>() << ": $" << c["awardAmount"].get<double>() << " from " << c["awardingAgency"].get<std::string>() << " — " << c["description"].get<std::string>() << std::endl; }
return 0;}use reqwest::blocking::Client;use serde::Deserialize;use std::error::Error;
#[derive(Debug, Deserialize)]struct Contract { #[serde(rename = "awardId")] award_id: String, #[serde(rename = "awardAmount")] award_amount: f64, #[serde(rename = "awardType")] award_type: String, #[serde(rename = "awardingAgency")] awarding_agency: String, #[serde(rename = "awardingSubAgency")] awarding_sub_agency: String, #[serde(rename = "recipientName")] recipient_name: String, #[serde(rename = "startDate")] start_date: String, #[serde(rename = "endDate")] end_date: String, description: String, #[serde(rename = "naicsCode")] naics_code: String, #[serde(rename = "naicsDescription")] naics_description: String, #[serde(rename = "contractAwardType")] contract_award_type: String,}
#[derive(Debug, Deserialize)]struct ContractData { symbol: String, name: String, contracts: Vec<Contract>,}
#[derive(Debug, Deserialize)]struct ContractResponse { success: bool, data: ContractData,}
fn get_government_contracts(symbol: &str, api_key: &str) -> Result<ContractResponse, Box<dyn Error>> { let url = format!( "https://api.finbrain.tech/v2/government-contracts/{}", symbol );
let client = Client::new(); let response: ContractResponse = client .get(&url) .bearer_auth(api_key) .send()? .json()?;
Ok(response)}
fn main() -> Result<(), Box<dyn Error>> { let result = get_government_contracts("LMT", "YOUR_API_KEY")?;
for c in &result.data.contracts { println!("{}: ${} from {} — {}", c.start_date, c.award_amount, c.awarding_agency, c.description); }
Ok(())}const response = await fetch( "https://api.finbrain.tech/v2/government-contracts/LMT", { headers: { "Authorization": "Bearer YOUR_API_KEY" } });const result = await response.json();
for (const c of result.data.contracts) { console.log(`${c.startDate}: $${c.awardAmount.toLocaleString()} from ${c.awardingAgency} — ${c.description}`);}Response
Section titled “Response”Success Response (200 OK)
Section titled “Success Response (200 OK)”{ "success": true, "data": { "symbol": "LMT", "name": "Lockheed Martin Corporation", "contracts": [ { "awardId": "CONT_AWD_0001", "awardAmount": 50000000, "awardType": "Contract", "awardingAgency": "Department of Defense", "awardingSubAgency": "Department of the Army", "recipientName": "Lockheed Martin Corporation", "startDate": "2025-06-01", "endDate": "2026-06-01", "description": "Aircraft maintenance services", "naicsCode": "336411", "naicsDescription": "Aircraft Manufacturing", "contractAwardType": "Definitive Contract" } ] }, "meta": { "timestamp": "2026-03-12T12:00:00.000Z" }}Response Fields
Section titled “Response Fields”| Field | Type | Description |
|---|---|---|
success | boolean | Whether the request was successful |
data.symbol | string | Stock ticker symbol |
data.name | string | Company name |
data.contracts | array | Array of contract award objects |
meta.timestamp | string | Response timestamp (ISO 8601) |
Contract Object Fields
Section titled “Contract Object Fields”| Field | Type | Description |
|---|---|---|
awardId | string | Unique contract award identifier |
awardAmount | number | Total award value in USD |
awardType | string | Type of award (e.g., Contract) |
awardingAgency | string | Federal agency issuing the contract |
awardingSubAgency | string | Sub-agency within the awarding agency |
recipientName | string | Company receiving the contract |
startDate | string | Contract start date (YYYY-MM-DD) |
endDate | string | Contract end date (YYYY-MM-DD) |
description | string | Plain-text description of the contract scope |
naicsCode | string | NAICS industry classification code |
naicsDescription | string | Human-readable NAICS description |
contractAwardType | string | Specific contract award mechanism |
Errors
Section titled “Errors”| Code | Error | Description |
|---|---|---|
| 400 | Bad Request | Invalid symbol or parameters |
| 401 | Unauthorized | Invalid or missing API key |
| 403 | Forbidden | Authenticated, but not authorized to access this resource |
| 404 | Not Found | Ticker not found |
| 429 | Too Many Requests | Rate limit exceeded — wait and retry |
| 500 | Internal Server Error | Server-side error |
Related
Section titled “Related”- Government Contracts Dataset - Use cases and analysis examples
- Stock Screener API - Screen government contracts across tickers
- Corporate Lobbying API - Corporate lobbying data
- Insider Transactions API - Insider trading data