Skip to content

Migrate bill discovery + text fetch from Congress.gov API to govinfo bulk data #10

Closed
7 of 7 issues completed
Closed

Description

@willhea

Summary

Replace the Congress.gov API (fetch_bills.py) with GPO govinfo bulk data for both bill discovery and text retrieval. This removes the API-key/rate-limit dependency, recovers bill titles the committee API drops, and lets discovery generalize beyond appropriations (search by number or title), which matches how users actually find bills and supports diffing any bill.

Validated with a local prototype (parity test against existing fixtures + a discovery demo). Key results are inlined below; the prototype branch can be pushed for reproduction on request.

Why

  • Byte-identical text. govinfo BILLS XML is byte-for-byte identical to the congress.gov "Formatted XML" we download today — verified on all 12 existing test fixtures (12/12 exact match). Same legacy bill.dtd format, so bill_tree.py needs no parser changes (it is NOT USLM; the default /bulkdata/BILLS/ path is legacy DTD).
  • No API key, no rate limit. Covers 113th Congress forward.
  • Titles + discovery for free. BILLSTATUS bulk carries title, subjects, and committee/subcommittee codes — the title is exactly what the committee API omits today.
  • The "firehose" was a paging artifact. 450k bills / 250-per-page is only a problem via the API. As bulk ZIPs, a whole chamber-congress is ~14 MB and a trivial local index (measured: 5,649 Senate bills in the 118th).

Target architecture

Concern Source
Search by number direct URL construction (no index, any bill)
Search by title local index built from BILLSTATUS per-type ZIP
Full text for diff BILLS bulk XML (byte-identical to today)

Appropriations becomes a label/facet, not a discovery gate.

URL shapes:

  • text: bulkdata/BILLS/{congress}/{session}/{type}/BILLS-{congress}{type}{number}{ver}.xml
  • status: bulkdata/BILLSTATUS/{congress}/{type}/BILLSTATUS-{congress}{type}{number}.xml
  • per-type ZIP: bulkdata/BILLSTATUS/{congress}/{type}/BILLSTATUS-{congress}-{type}.zip

Implementation notes / gotchas (found during prototyping)

  1. Resolve version codes from the BILLS directory listing (prefix-match BILLS-118s4690*), not by mapping human-readable version labels — BILLSTATUS says "Reported to Senate" while the API/our fixtures say "reported-in-senate". The vocabularies differ.
  2. Do not filter by text-version count. All appropriations test bills have exactly 1 published version (Senate bills are reported as original bills); a >=2-version filter drops every one. Diffs are against external baselines (budget request / prior year / companion), not intra-bill versions.
  3. Appropriations facet: committee referral (ssap00/hsap00, 45 bills in 118th S) is more precise than the "Appropriations" subject term (50); they diverge slightly. Pick committee for precision or union for recall.
  4. Session in path: govinfo splits BILLS by session (1/2). Resolve session from the directory listing rather than probing both.

Out of scope / unaffected

  • Pre-introduction draft PDFs still have no XML upstream anywhere; this change does not address them.
  • The law API is explicitly rejected as an alternative: it only covers enacted bills, losing all in-progress versions (the bulk of diff value).

Acceptance

  • govinfo-backed fetch produces byte-identical XML to current pipeline on existing fixtures (regression guard)
  • Discovery by bill number works for any bill type/congress
  • Title search works over a BILLSTATUS-built index, with appropriations as a facet
  • No Congress.gov API key required to run the fetch pipeline
  • Version codes resolved from directory listing (not label mapping)

Migrated from willhea/civic_tech_appropriations_bills#61 (original author @willhea).

Sub-issues

Sub-issues

7 of 7 Issues completed
Loading 7 sub-issues

Activity

  1. willhea commented on Jun 24, 2026

    @willhea
    CollaboratorAuthor

    Status update. Moving off In review → Backlog; flagging for discussion before we commit.

    This isn't actually in review — there's no open PR. The current state is: prototyped and validated (byte-identical govinfo BILLS XML on all 12 fixtures, discovery demo), but no implementation merged. fetch_bills.py on develop still uses the Congress.gov API v3 as its only source — no govinfo bulkdata client, no key-less fallback.

    Want to revisit this together before scheduling the work — open questions to settle:

    • Whether to do it now vs. after the delivery-channel decision (it doesn't unblock anything user-facing).
    • Appropriations as committee-referral facet vs. subject-term union (precision vs. recall) for discovery.
    • Scope: full discovery+title-index migration, or just the key-less text-fetch path first.

    Leaving open in Backlog pending that discussion.

  2. willhea commented on Jun 24, 2026

    @willhea
    CollaboratorAuthor

    Partial coverage from PR #24 (bill-index). Reviewed against this issue — it addresses the discovery/metadata half, not the text-fetch half.

    What PR #24 addresses

    Delivers discovery + a metadata index via govinfo bulk data:

    • fetch_bill_archives.py downloads govinfo BILLSTATUS bulk ZIPs (bulkdata/BILLSTATUS/{congress}/{type}/BILLSTATUS-{congress}-{type}.zip) and extracts per-bill metadata, including the title the committee API drops. No key, no rate limit on this path.
    • bill_index/bill_index.py — CSV-backed metadata manager keyed by the congress-type-number[:version] slug convention; generalizes discovery beyond appropriations (the 100K+ bill large_bills.csv index proves it).
    • download-all --file <csv> drives bulk text download off any slug list, so appropriations is no longer a discovery gate.

    Maps to the issue's "title search / discovery / appropriations-as-facet" acceptance items.

    Where Congress.gov API-key reliance still lives (NOT migrated)

    The full-text fetch — the core diff input — still goes through the keyed Congress.gov API:

    1. Version discovery still hits the API. fetch_text_versions() calls /bill/{congress}/{type}/{number}/text via api_get(...), which requires api_key. There is zero bulkdata/BILLS/ (text) usage anywhere on the branch — only BILLSTATUS (metadata). The headline win (byte-identical BILLS XML from govinfo, no parser change) is not implemented.
    2. Text file URLs are still congress.gov. get_xml_url/get_pdf_url read Formatted XML/PDF URLs out of the API's textVersions response, so you must call the keyed API first to enumerate versions.
    3. The key is still mandatory. main() calls get_api_key() unconditionally; even download-all --file flows through fetch_text_versions → api_get. With no key it falls back to DEMO_KEY (30 req/hr) rather than running key-free. So the acceptance item "No Congress.gov API key required to run the fetch pipeline" is not met.
    4. The committee API call (fetch_all_committee_bills) remains for the year-range download-all path — also keyed.

    Remaining work to close this issue

    • Resolve version codes from the govinfo BILLS/{congress}/{session}/{type}/ directory listing (prefix-match) and download BILLS-...xml directly, instead of via the API textVersions URLs.
    • Make get_api_key() optional so the pipeline runs key-free.

    Net: PR #24 covers the metadata/discovery half; the text-retrieval half (the part that actually removes the key/rate-limit dependency) is still open. Keeping this in Backlog for the revisit discussion.

  3. willhea commented on Jun 28, 2026

    @willhea
    CollaboratorAuthor

    Crediting prior groundwork: @RolfHendriks's PR #24 ("Bill index") already landed foundational pieces for this migration — bill_index for accumulating bill metadata, bulk-data bill fetching via the shared API, and CSV-backed batch download (fetch_bills, default format both). That work is a substantial head start on the govinfo bulk-data switch tracked here. Not assigning, since the full migration is still open and unclaimed — flagging the lineage so the contribution is visible and reusable.

  4. added a commit that references this issue on Jul 18, 2026
  5. self-assigned this
    on Jul 18, 2026
  6. added a commit that references this issue on Jul 18, 2026
  7. willhea commented on Jul 18, 2026

    @willhea
    CollaboratorAuthor

    Reopening: closed as COMPLETED on 2026-07-18 appears premature. The migration is still in progress — steps 5–11 of the approved plan remain, PR #225 (step 4, enumeration) is an open draft, and verification this session surfaced a completeness gap now tracked in #226 (govinfo doesn't mirror Congress.gov 1:1; ~0.1% of versions need an automatic API fallback, blocking the --source wiring). #10 stays the umbrella epic until that work lands.

  8. 23 remaining items

  9. willhea commented on Jul 19, 2026

    @willhea
    CollaboratorAuthor

    Closing — migration complete

    All 7 sub-issues closed (7/7). --source govinfo is the keyless default for discovery and text fetch, with the Congress.gov API path retained behind --source api.

    What shipped

    #223 rhuc version code with an authoritative label
    #238 complete VERSION_CODES — all 53 authoritative govinfo codes, so no real code falls through to an unreadable raw-code filename
    #231 standing gate: every observed BILLSTATUS <type> spelling resolves to a version code
    #240 title search over a BILLSTATUS-built index, appropriations as a facet
    #242 lightweight per-congress BILLSTATUS fetch (the on-ramp for search)
    #244 typographic punctuation + accent fold so ASCII queries reach typeset titles
    #226 XML-less completeness gap surfaced, not silently dropped

    Boundary decisions worth carrying forward

    Deliberately out of scope, tracked independently and not blocking this epic:

    Releasing to main is a separate decision and is not part of this epic.

  10. added 4 commits that reference this issue on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions