Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 9,015 Bytes
61d29fc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | ---
sidebar_position: 3
---
# Grants.gov API Integration
Track federal grant opportunities and match them to nonprofits in your database.
## Overview
The Grants.gov API provides access to **federal grant opportunities** from all federal agencies. This integration adds a NEW dimension to your data by tracking **available grants** (future opportunities) alongside your existing **IRS Form 990 data** (past awards).
**API Documentation**: https://www.grants.gov/api
## What You Get
### Data NOT in Your Current System
β
**Federal Grant Opportunities**:
- Grant titles, descriptions, and purposes
- Funding amounts and award ceilings
- Eligibility criteria
- Application deadlines
- Opportunity status (forecasted, posted, closed, archived)
- Assistance Listing Numbers (ALN/CFDA)
- Agency contact information
β
**Search Capabilities**:
- Filter by keyword (e.g., "oral health", "dental care")
- Filter by funding category (HL = Health)
- Filter by federal agency (HHS, NIH, CDC)
- Filter by opportunity status
### Authentication
**NO API KEY REQUIRED** for public endpoints (`search2` and `fetchOpportunity`)!
## Use Cases
### 1. Grant Opportunity Alerts
Alert nonprofits in your database about relevant funding opportunities:
```python
from discovery.grants_gov_integration import GrantsGovAPI, GrantMatcher
# Initialize API
api = GrantsGovAPI()
matcher = GrantMatcher(api)
# Find all oral health grants
oral_health_grants = matcher.find_oral_health_grants(
opp_statuses="forecasted|posted"
)
print(f"Found {len(oral_health_grants):,} opportunities")
```
### 2. Match Grants to State Nonprofits
```python
import pandas as pd
# Load MA nonprofits
nonprofits = pd.read_parquet("data/gold/states/MA/nonprofits_organizations.parquet")
# Match grants to MA organizations
matches = matcher.match_grants_to_state(
state_code="MA",
grants_df=oral_health_grants,
nonprofits_df=nonprofits
)
# Save results
matches.to_parquet("data/gold/states/MA/available_grants.parquet")
```
### 3. Track Funding Trends
Compare available opportunities (Grants.gov) with received funding (IRS 990):
```python
# What grants are AVAILABLE?
available = api.search_to_dataframe(
keyword="oral health",
funding_categories="HL",
opp_statuses="posted"
)
# What grants were RECEIVED? (from IRS 990)
received = pd.read_parquet("data/gold/states/MA/grants_revenue_sources.parquet")
# Analysis: Are there gaps?
# - High demand categories with few opportunities?
# - Opportunities that aren't being utilized?
```
## Quick Start
### Search for Oral Health Grants
```bash
python discovery/grants_gov_integration.py \
--oral-health \
--output data/gold/grants
```
### Custom Search
```bash
python discovery/grants_gov_integration.py \
--keyword "fluoridation" \
--funding-category HL \
--agency HHS \
--output data/gold/grants
```
## API Endpoints
### search2
Search for grant opportunities:
```python
api = GrantsGovAPI()
results = api.search_opportunities(
keyword="oral health",
funding_categories="HL", # Health
agencies="HHS", # Health & Human Services
opp_statuses="forecasted|posted",
rows=100
)
```
**Parameters**:
- `keyword`: Search term (e.g., "oral health", "dental")
- `funding_categories`: Category codes (HL=Health, ED=Education, ENV=Environment)
- `agencies`: Agency codes (HHS, HHS-NIH, HHS-CDC, EPA)
- `opp_statuses`: Pipe-separated statuses (forecasted|posted|closed|archived)
- `eligibilities`: Eligibility codes
- `aln`: Assistance Listing Number (formerly CFDA)
- `rows`: Results per page (max 100)
### fetchOpportunity
Get detailed information about a specific grant:
```python
details = api.fetch_opportunity(opportunity_id=289999)
# Access detailed data
synopsis = details['data']['synopsis']
eligibility = details['data']['eligibility']
funding = details['data']['fundingDetails']
```
## Data Schema
### Opportunity Fields
| Field | Description | Example |
|-------|-------------|---------|
| `id` | Opportunity ID | 289999 |
| `opportunityNumber` | Grant number | HHS-2024-ACF-001 |
| `opportunityTitle` | Grant title | Oral Health Community Programs |
| `agencyCode` | Agency code | HHS |
| `agencyName` | Agency name | Health & Human Services |
| `openDate` | Application open date | 2024-10-15 |
| `closeDate` | Application deadline | 2024-12-31 |
| `opportunityStatus` | Status | posted, forecasted, closed |
| `cfdaList` | Assistance Listing Numbers | `[{"cfdaNumber": "93.223"}]` |
| `fundingCategories` | Funding category codes | HL (Health) |
## Integration with Existing Data
### Complete Grant Lifecycle Tracking
```
βββββββββββββββββββββββββββ
β Grants.gov API β β FUTURE: Available opportunities
β (This Integration) β
β β’ Posted grants β
β β’ Eligibility β
β β’ Deadlines β
βββββββββββββ¬ββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββ
β Your Dashboard β β PRESENT: Alert & match
β β’ Match to nonprofits β
β β’ Send alerts β
β β’ Track applications β
βββββββββββββ¬ββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββ
β IRS Form 990 β β PAST: Received funding
β (Existing Data) β
β β’ Government grants β
β β’ Foundation grants β
β β’ Revenue sources β
βββββββββββββββββββββββββββ
```
### Combined Analysis
```python
# Which MA nonprofits received federal health grants last year?
past_grants = pd.read_parquet("data/gold/states/MA/grants_revenue_sources.parquet")
federal_recipients = past_grants[past_grants['government_grants'] > 0]
# What federal health grants are available NOW?
current_opportunities = api.search_to_dataframe(
keyword="health",
funding_categories="HL",
agencies="HHS",
opp_statuses="posted"
)
# Analysis: Success rate, funding gaps, opportunity awareness
```
## Funding Categories
Common funding category codes:
| Code | Category | Examples |
|------|----------|----------|
| `HL` | Health | Oral health, mental health, public health |
| `ED` | Education | School programs, literacy |
| `ENV` | Environment | Clean water, pollution control |
| `FA` | Food & Agriculture | Nutrition, food safety |
| `CD` | Community Development | Housing, economic development |
| `O` | Other | Multi-purpose grants |
## Agency Codes
Major federal agencies:
| Code | Agency | Focus Areas |
|------|--------|-------------|
| `HHS` | Health & Human Services | Health programs |
| `HHS-NIH` | National Institutes of Health | Medical research |
| `HHS-CDC` | Centers for Disease Control | Public health |
| `HHS-HRSA` | Health Resources & Services | Healthcare access |
| `EPA` | Environmental Protection Agency | Environmental health |
| `ED` | Department of Education | School health programs |
## Rate Limiting
The API does not publish official rate limits, but best practices:
- **Recommended**: 1-2 requests per second
- **Polite**: 0.5-1 second delay between requests
- **Batch operations**: Use pagination (`rows=100`) to minimize requests
Our implementation includes automatic rate limiting (500ms delay).
## Error Handling
All API responses include an error code:
```python
response = api.search_opportunities(keyword="health")
if response.get("errorcode") == 0:
# Success
opportunities = response['data']['oppHits']
else:
# Error
print(f"Error: {response.get('msg')}")
```
## Next Steps
1. **Test the integration**:
```bash
python discovery/grants_gov_integration.py --oral-health
```
2. **Schedule regular updates**:
- Daily cron job to fetch new opportunities
- Weekly digest emails to nonprofits
- Dashboard widget showing "Latest Grants"
3. **Enhance matching**:
- Filter by NTEE codes (oral health orgs only)
- Check organization size (capacity to apply)
- Historical success rate analysis
4. **Build alerts system**:
- Email notifications for relevant grants
- SMS alerts for approaching deadlines
- Dashboard notifications for new opportunities
## Additional Resources
- [Grants.gov API Documentation](https://www.grants.gov/api)
- [API Guide](https://www.grants.gov/api/api-guide)
- [Assistance Listings (formerly CFDA)](https://sam.gov/content/assistance-listings)
- [Grants.gov Learning Center](https://www.grants.gov/learning-center)
## Related Data Sources
- **USAspending.gov API**: Actual grant awards and spending data (complements Grants.gov opportunities)
- **SAM.gov**: Entity registration and contract opportunities
- **IRS Form 990** (your existing data): Nonprofit financial reports showing received grants
|