Skip to content

feat(sam): reproducible ingestion from the SAM public monthly extract - #146

Open
ekim1394 wants to merge 1 commit into
mainfrom
feat/sam-extract-ingest
Open

feat(sam): reproducible ingestion from the SAM public monthly extract#146
ekim1394 wants to merge 1 commit into
mainfrom
feat/sam-extract-ingest

Conversation

@ekim1394

Copy link
Copy Markdown
Collaborator

Full sam_entities coverage from SAM's public monthly entity extract, sidestepping the API's daily quota (~1K req/day) and ~5K pagination cap that capped the live reader at a small sample.

Already applied: the 2026-07 extract is parsed and published to R2 — sam_entities went 4,685 → 885,266 entities, and the UEI join to usaspending_recipients jumped 5 → 60,558 overlapping UEIs (the org-resolution join is now real).

This PR makes it reproducible: scripts/ingest_sam_extract.py parses the 142-field pipe-delimited flat file → the 18-col sam_entities schema, with the confirmed field-position map and code→description mappings documented in the module. Run monthly:

uv run python -m spicy_regs.scripts.ingest_sam_extract SAM_PUBLIC_MONTHLY_V2_YYYYMMDD.dat --upload

Get the file from SAM.gov → Data Services → Entity Registration → Public.

Known extract limits (documented): entity_type_desc, profit_structure_desc, exclusion_status_flag aren't cleanly in the extract → published NULL; entity_structure_desc carries the raw structure code. Hermetic test covers the parse/mapping. ruff + ty + test green.

The SAM Entity API is daily-quota-gated (~1K req/day) and pagination-capped
at ~5K, so the live reader can only sample the ~885K entities. This adds
spicy_regs/ingest_sam_extract.py to parse the public monthly extract flat
file (142 pipe-delimited fields) into the full sam_entities table — one file
= full coverage. Confirmed field map + code->desc mappings documented; the 3
fields the extract doesn't expose (entity_type_desc, profit_structure_desc,
exclusion_status_flag) are published NULL. Hermetic test with a 142-field
fixture. (The 2026-07 extract, 885,266 entities, is already published to R2
via this parser.)
@ekim1394
ekim1394 force-pushed the feat/sam-extract-ingest branch from 87a3cdd to 36b8b68 Compare July 18, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant