# USAspending Scraper (`real-estate-api/usaspending-scraper`) Actor

USAspending Scraper is a Python tool designed to extract U.S. federal spending data, including contracts, grants, direct payments, and agency budgets, from USAspending.gov. It exports structured datasets into CSV or JSON formats for policy research, financial auditing, and market analysis

- **URL**: https://apify.com/real-estate-api/usaspending-scraper.md
- **Developed by:** [real-estate-api](https://apify.com/real-estate-api) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.99 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## USAspending Scraper: federal contracts, grants, recipients, and agencies

<p align="center">
  <img src="https://i.imgur.com/YRhA0UL.jpg" alt="USA Automotive Leads Hub" width="680" />
</p>

Pull U.S. federal spending straight from the public USAspending Website. Search contract awards, grants, loans, and IDVs, then collect contractor UEIs and agency budget figures into a clean dataset. No API key, no sign-in.

Think of it as a sam.gov alternative when you want government contracts data you can filter and export: by keyword, agency, recipient, NAICS, place of performance, and date. Put it on a schedule and get a fresh awards search every morning.

### Use cases

- **B2G sales leads.** See who wins contracts in your NAICS, who the incumbent is, and which awards are close to their end date.
- **Competitor tracking.** Follow a contractor such as Lockheed across agencies and states.
- **Grant research.** Pull assistance awards for a university or nonprofit keyword.
- **Journalism and policy.** Export award rows with agency, amount, and place of performance.
- **Market sizing.** List toptier agencies with their obligated amounts and budget authority.

### What you get

Award rows carry the award id, generated internal id, amount, outlays, awarding agency, NAICS, PSC, and a link to the award page. Turn on award details when you also need the UEI, county, ZIP, congressional district, business categories, and subaward count.

Recipient rows carry the name, UEI, DUNS (when USAspending still has it), parent or child level, and total amount. Agency rows carry the toptier code, abbreviation, obligated amount, budget authority, mission, and website.

Loan rows use Loan Value as the amount, since that group has no Award Amount field.

### Input

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `mode` | string | `awards` | Search awards, load award details, search recipients, or list agencies. |
| `keywords` | array | `data analytics` | Keywords for award or recipient search. One per line. |
| `awardTypes` | array | `contracts` | contracts, idvs, grants, direct_payments, loans, other. One API call per group. |
| `dateFrom` | string | 1 year ago | Action date start. Earliest searchable date is 2007-10-01. |
| `dateTo` | string | today | Action date end. |
| `awardingAgencies` | array | empty | Exact toptier names, such as Department of Defense. |
| `recipients` | array | empty | Recipient name text, such as Lockheed. |
| `placeOfPerformanceStates` | array | empty | Two-letter state codes, such as TX. |
| `naicsCodes` | array | empty | NAICS codes. `541511` was checked on the live API. |
| `minAmount` | integer | empty | Minimum award amount in USD. |
| `sortBy` | string | Award Amount | Award Amount, Start Date, End Date, or Last Modified Date. Descending. |
| `includeDetails` | boolean | false | Extra request per award for UEI and location. |
| `awardIds` | array | empty | generated_internal_id values for award_details mode. |
| `maxItems` | integer | 200 | Stop after this many rows. Hard cap 10,000. |
| `timeoutSecs` | integer | 300 | Overall run timeout. Max 3600. |
| `requestTimeoutSecs` | integer | 30 | Per-request timeout. |
| `proxyConfiguration` | object | No proxy | Optional. Leave useApifyProxy false unless requests fail. |

#### A simple awards search

```json
{
    "mode": "awards",
    "keywords": ["data analytics"],
    "awardTypes": ["contracts"],
    "dateFrom": "2025-01-01",
    "dateTo": "2025-12-31",
    "maxItems": 50,
    "includeDetails": false,
    "proxyConfiguration": { "useApifyProxy": false }
}
```

#### A tighter govcon lead search

```json
{
    "mode": "awards",
    "awardTypes": ["contracts"],
    "awardingAgencies": ["Department of Defense"],
    "recipients": ["Lockheed"],
    "placeOfPerformanceStates": ["TX"],
    "dateFrom": "2025-01-01",
    "dateTo": "2025-06-30",
    "sortBy": "Award Amount",
    "maxItems": 100
}
```

### Output

Rows land in the dataset. Award text is stored as `awardSummary` and also as `description`, because `description` cannot be used as a dataset schema field name.

```json
{
    "recordKind": "award",
    "awardId": "70CTD022FR0000002",
    "generatedInternalId": "CONT_AWD_70CTD022FR0000002_7012_GS35F386DA_4732",
    "awardTypeGroup": "contracts",
    "awardType": "DELIVERY ORDER",
    "recipientName": "BOOZ ALLEN HAMILTON INC",
    "amount": 76183271.16,
    "totalOutlays": 59221308.22,
    "awardSummary": "EO14042 DHS ICE REQUIRES DESIGN, DEVELOPMENT AND DATA ANALYTICS SUPPORT",
    "description": "EO14042 DHS ICE REQUIRES DESIGN, DEVELOPMENT AND DATA ANALYTICS SUPPORT",
    "startDate": "2021-12-03",
    "endDate": "2027-03-01",
    "awardingAgency": "Department of Homeland Security",
    "awardingSubAgency": "U.S. Immigration and Customs Enforcement",
    "placeOfPerformanceState": "VA",
    "naicsCode": "541511",
    "pscCode": "DD01",
    "url": "https://www.usaspending.gov/award/CONT_AWD_70CTD022FR0000002_7012_GS35F386DA_4732"
}
```

| Field | Type | Description |
|-------|------|-------------|
| `awardId` | string | Award ID from search, or PIID/FAIN from details. |
| `generatedInternalId` | string | Stable id. Duplicate ids are dropped. |
| `amount` | number | Award amount, or Loan Value for loans. Large values stay as numbers. |
| `awardSummary` | string | Award description. The same text is also on `description`. |
| `recipientUei` | string | UEI after award details, or from loan search. |
| `url` | string | Award, recipient, or agency page. |
| `recipientLevel` | string | P, C, or R on recipient rows. Also stored as `level`. |
| `errorDetail` | string | API `detail` text when a call returns 422 or another error. |

The dataset has four table views: Awards, Recipients, Agencies, and Errors.

### Run it on a schedule

Run the actor on a schedule and filter the dataset on `lastModified` or `endDate` for new-award alerts or expiring-contract lists. Apify webhooks can push each run to Google Sheets, Slack, or your own API.

### Limits

Search dates start at 2007-10-01. Older spending needs the bulk download, which this actor does not call. The free cap is 10,000 rows per run, and the API serves at most 100 rows per page. Agencies report on their own cadence, so brand-new awards can lag. The endpoints returned no rate-limit headers when they were checked, so the actor caps page size, detail concurrency, and retries rather than guessing a requests-per-minute number.

### FAQ

**What is the difference between contracts and IDVs?**
Contracts use codes A, B, C, and D. IDVs use IDV_A through IDV_E and cover indefinite delivery vehicles. The actor sends one group per request. Mixing groups in one body is rejected.

**Should I use UEI or DUNS?**
UEI is the current SAM identifier. Award details return `recipient_uei`. Recipient search still returns DUNS when USAspending has the legacy number. Prefer UEI for a contractor list you plan to match against SAM.

**Do I need an API key?**
No. This uses the public USAspending API v2.

**Why did an agency filter return nothing?**
The awarding agency name has to match the toptier name, for example Department of Defense. The actor checks the name with `/autocomplete/awarding_agency/` and writes an error row when nothing matches.

**How many rows can one run return?**
`maxItems` defaults to 200 and cannot go above 10,000. Each page asks for at most 100 awards.

### Trademark notice

USAspending.gov, the U.S. Department of the Treasury, and related names, logos, and trademarks belong to their respective owners. Their use in this documentation only identifies the source of the data and does not imply affiliation, sponsorship, endorsement, or partnership.

### Disclaimer

This actor is an independent tool. It is not affiliated with, endorsed by, sponsored by, or officially associated with USAspending.gov or the U.S. Department of the Treasury.

### Is web scraping legal?

Collecting information that is already public is generally legal. Scraping is not hacking, and no single law bans it. The usual limits apply: do not break into accounts, do not take private or confidential data, and be careful with personal data and copyrighted works. A site's terms can also restrict how you access it. A public name, price, or rating is a fact, which is not the same as republishing someone's article or photo.

This actor reads public pages and official public APIs. It does not log in and it does not bypass access controls.

This is not legal advice. For the longer version, see Apify's article [Is web scraping legal?](https://blog.apify.com/is-web-scraping-legal/).

# Actor input Schema

## `mode` (type: `string`):

awards searches contracts, grants, loans, and IDVs. award_details loads generated_internal_id values. recipients finds contractors. agencies lists toptier budgets.

## `keywords` (type: `array`):

Search text for awards or recipients. One keyword per line. Example: data analytics.

## `awardTypes` (type: `array`):

Award groups to search. Each group is its own request. Contracts are A B C D. Grants are 02 03 04 05. The API rejects a mix of groups in one call.

## `dateFrom` (type: `string`):

Earliest 2007-10-01. Default: 1 year ago. Earlier dates are moved up to 2007-10-01.

## `dateTo` (type: `string`):

End of the action-date window. Default: today.

## `awardingAgencies` (type: `array`):

Exact toptier names, for example Department of Defense. Names are checked with the awarding-agency autocomplete endpoint.

## `recipients` (type: `array`):

Recipient name text sent as recipient_search_text on award search, or as the keyword in recipients mode when Keywords is empty.

## `placeOfPerformanceStates` (type: `array`):

Two-letter USPS codes. Each code is sent as country USA plus that state.

## `naicsCodes` (type: `array`):

NAICS codes sent as naics_codes. Checked live with 541511 on contract search.

## `minAmount` (type: `integer`):

Lower bound in USD, sent as award_amounts.lower_bound. Leave empty to skip the filter. Checked live.

## `sortBy` (type: `string`):

Sort field for award search, descending. Loans use Loan Value and Issued Date because that group has no Award Amount field.

## `includeDetails` (type: `boolean`):

1 extra request per award. Adds UEI, place of performance, business categories, and subaward count. Up to 3 detail calls at a time.

## `awardIds` (type: `array`):

USAspending generated_internal_id values for award_details mode. Example: CONT_AWD_70CTD022FR0000002_7012_GS35F386DA_4732.

## `maxItems` (type: `integer`):

Free version cap: 10,000 per run. Stops paging once this many awards, recipients, or agencies are kept. Duplicates do not count twice.

## `timeoutSecs` (type: `integer`):

Stop the run after this many seconds and keep rows already collected. Default 300. Maximum 3600.

## `requestTimeoutSecs` (type: `integer`):

Per-request HTTP timeout. Default 30. 429, 5xx, and timeouts retry with backoff capped at 60 seconds.

## `proxyConfiguration` (type: `object`):

Optional proxy for USAspending requests. Default is no proxy. Turn on Apify Proxy only if requests start failing.

## Actor input object example

```json
{
  "mode": "awards",
  "keywords": [
    "data analytics"
  ],
  "awardTypes": [
    "contracts"
  ],
  "dateFrom": "2025-01-01",
  "dateTo": "2025-12-31",
  "awardingAgencies": [
    "Department of Defense"
  ],
  "recipients": [
    "Lockheed"
  ],
  "placeOfPerformanceStates": [
    "TX"
  ],
  "naicsCodes": [
    "541511"
  ],
  "minAmount": 1000000,
  "sortBy": "Award Amount",
  "includeDetails": false,
  "awardIds": [
    "CONT_AWD_70CTD022FR0000002_7012_GS35F386DA_4732"
  ],
  "maxItems": 200,
  "timeoutSecs": 300,
  "requestTimeoutSecs": 30,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

## `awards` (type: `string`):

Recipient, amount, awarding agency, description, start date, and award URL.

## `recipients` (type: `string`):

Contractor name, UEI, DUNS, parent or child level, and total amount.

## `agencies` (type: `string`):

Toptier agency, abbreviation, code, obligated amount, and website.

## `errors` (type: `string`):

Calls that failed, with HTTP status and the API detail message.

## `dataset` (type: `string`):

Every row from the run, without a table view applied.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "keywords": [
        "data analytics"
    ],
    "proxyConfiguration": {
        "useApifyProxy": false
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("real-estate-api/usaspending-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "keywords": ["data analytics"],
    "proxyConfiguration": { "useApifyProxy": False },
}

# Run the Actor and wait for it to finish
run = client.actor("real-estate-api/usaspending-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "keywords": [
    "data analytics"
  ],
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}' |
apify call real-estate-api/usaspending-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,real-estate-api/usaspending-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/m1eZWn2KIJnhM68S9/builds/uoMy6ALzXn9zoxu8j/openapi.json
