Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 1.68 KB

File metadata and controls

61 lines (45 loc) · 1.68 KB

Python examples — USASpending.gov Scraper

Call the hosted Actor with the official apify-client for Python. This calls logiover/usaspending-gov-scraper — no Actor source code is involved.

Install

pip install apify-client

Run and read results

from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")

run = client.actor("logiover/usaspending-gov-scraper").call(run_input={
    "awardTypes": ["contracts", "grants"],
    "startDate": "2026-01-01",
    "endDate": "2026-12-31",
    "keyword": "cybersecurity",
    "maxAwards": 2000,
})

for award in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(award["recipientName"], f"${award.get('awardAmount'):,}" if award.get("awardAmount") else "-",
          award.get("awardingAgency"), award.get("placeOfPerformanceState"))

Rank top recipients with pandas

import pandas as pd

run = client.actor("logiover/usaspending-gov-scraper").call(run_input={
    "awardTypes": ["contracts"],
    "keyword": "cloud",
    "maxAwards": 0,
})

df = pd.DataFrame(list(client.dataset(run["defaultDatasetId"]).iterate_items()))
top = df.groupby("recipientName")["awardAmount"].sum().sort_values(ascending=False).head(10)
print(top)

Export federal grants for a state to CSV

run = client.actor("logiover/usaspending-gov-scraper").call(run_input={
    "awardTypes": ["grants"],
    "state": "CA",
    "maxAwards": 2000,
})

df = pd.DataFrame(list(client.dataset(run["defaultDatasetId"]).iterate_items()))
df.to_csv("federal-awards.csv", index=False)
print(f"Saved {len(df)} awards")

Docs: https://docs.apify.com/api/client/python/