Treasury
Query federal debt, operating cash, deposits, withdrawals and public debt transactions, and discover Fiscal Data endpoint fields
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/treasury/index.md to help me query Treasury with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
Track US federal debt over time
Example output · captured
- Connector release
- v0.2.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
SELECT record_date, tot_pub_debt_out_amt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date
| record_date | tot_pub_debt_out_amt |
|---|---|
| 2024-01-02 | 33,990,128,000,000 |
| 2024-01-03 | 33,994,220,000,000 |
Quick start
Choose where to run Treasury, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'treasury' AS treasury (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-treasury-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'treasury' AS treasury (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-treasury:0.2.0'
);
3. Run a query
SELECT record_date, tot_pub_debt_out_amt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'treasury' AS treasury
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SELECT record_date, tot_pub_debt_out_amt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date
Query Farm operates Treasury for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use treasury as the catalog alias for the query below.
4. Run a query
SELECT record_date, tot_pub_debt_out_amt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date
Technical details
- Verified connector release
- v0.2.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'treasury' AS treasury (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-treasury-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'treasury' AS treasury (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-treasury:0.2.0'
);
Overview
US Treasury Fiscal Data as SQL tables, covering federal debt, operating cash, deposits and withdrawals, public debt transactions, monthly statements and average interest rates, with exact decimal amounts. No API key needed.
Query federal debt, operating cash, deposits, withdrawals and public debt transactions, and discover Fiscal Data endpoint fields. Treasury Fiscal Data is public and needs no upstream API key. Dates and currency amounts are typed, including exact decimals. Use date arguments and filters_json to reduce upstream work. page_size controls request size and max_rows=0 retrieves all matches. NULL arguments are rejected. Missing optional response fields return NULL. Upstream errors fail the query; SQL WHERE filters are local.
Queries use bounded HTTP responses and retries. Credentials stay out of continuation state. See README.md for deployment and operational limits.
Sources and references
Catalog
Everything treasury exposes once attached — read straight from the worker's
released build.
main 9 functions
Treasury Fiscal Data endpoints as table functions: debt, cash, transactions, statements and interest rates.
Schema examples (12)
Discover fiscal datasets
SELECT dataset, endpoint, amount_units
FROM treasury.main.datasets()
ORDER BY dataset;
Inspect endpoint fields
SELECT field_name, source_type, source_format
FROM treasury.main.fields('v2/accounting/od/debt_to_penny')
ORDER BY field_name;
Read arbitrary fiscal records
SELECT record_date, record_json
FROM treasury.main.records('v2/accounting/od/debt_to_penny', start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date;
Label every field of one raw record from an uncurated endpoint (the second line of Monthly Treasury Statement Table 9 for January 2024, Individual Income Taxes): fields() supplies each source field's label and type, records() the original JSON value as text
SELECT f.field_name, f.label, f.source_type,
r.record_json ->> f.field_name AS source_value
FROM treasury.main.records('v1/accounting/mts/mts_table_9', start_date := '2024-01-31', end_date := '2024-01-31', page_size := 1, start_page := 2, max_rows := 1) AS r
CROSS JOIN treasury.main.fields('v1/accounting/mts/mts_table_9') AS f
ORDER BY f.field_name;
8 more examples
Federal debt to the penny
SELECT record_date, tot_pub_debt_out_amt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date;
| record_date | tot_pub_debt_out_amt |
|---|---|
| 2024-01-02 | 33,990,128,000,000 |
| 2024-01-03 | 33,994,220,000,000 |
Reconcile each day's change in total public debt (debt_to_penny, exact dollars) with the Daily Treasury Statement's issues minus redemptions (public_debt_transactions, USD millions scaled to dollars); the gap stays within a few million dollars because statement amounts are rounded
WITH debt AS (SELECT record_date, tot_pub_debt_out_amt - lag(tot_pub_debt_out_amt) OVER (ORDER BY record_date) AS debt_change_usd FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-12')), flows AS (SELECT record_date, sum(CASE transaction_type WHEN 'Issues' THEN transaction_today_amt ELSE -transaction_today_amt END) * 1000000 AS net_issuance_usd FROM treasury.main.public_debt_transactions(start_date := '2024-01-03', end_date := '2024-01-12') GROUP BY record_date) SELECT f.record_date, f.net_issuance_usd, d.debt_change_usd, d.debt_change_usd - f.net_issuance_usd AS gap_usd
FROM flows AS f
JOIN debt AS d USING (record_date)
ORDER BY f.record_date;
Operating cash balance
SELECT record_date, account_type, open_today_bal
FROM treasury.main.operating_cash_balance(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY record_date, src_line_nbr;
Compare the Treasury General Account closing cash balance (operating_cash_balance; since April 2022 the closing balance is the open_today_bal of the Closing Balance row, in USD millions) with total public debt outstanding (debt_to_penny) for each business day, as a percentage of debt
WITH tga AS (SELECT record_date, open_today_bal * 1000000 AS tga_close_usd FROM treasury.main.operating_cash_balance(start_date := '2024-01-02', end_date := '2024-01-12') WHERE account_type = 'Treasury General Account (TGA) Closing Balance') SELECT d.record_date, d.tot_pub_debt_out_amt, t.tga_close_usd, round(100 * t.tga_close_usd / d.tot_pub_debt_out_amt, 2) AS tga_pct_of_debt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-12') AS d
JOIN tga AS t USING (record_date)
ORDER BY d.record_date;
Cash deposits and withdrawals
SELECT transaction_type, transaction_catg, transaction_today_amt
FROM treasury.main.deposits_withdrawals(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY src_line_nbr;
Public debt transactions
SELECT transaction_type, security_type, transaction_today_amt
FROM treasury.main.public_debt_transactions(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY src_line_nbr;
Monthly Treasury receipts and outlays
SELECT classification_desc, current_month_gross_rcpt_amt,
current_month_gross_outly_amt
FROM treasury.main.monthly_statement(start_date := '2024-01-31', end_date := '2024-01-31')
WHERE data_type_cd='D'
ORDER BY src_line_nbr;
Average interest rates
SELECT security_desc, avg_interest_rate_amt
FROM treasury.main.average_interest_rates(start_date := '2024-01-31', end_date := '2024-01-31')
ORDER BY security_desc;
average_interest_rates (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT)
Monthly average interest rates on outstanding Treasury securities; values are percentages, not fractions.
Average interest rates
SELECT security_desc, avg_interest_rate_amt
FROM treasury.main.average_interest_rates(start_date := '2024-01-31', end_date := '2024-01-31')
ORDER BY security_desc;
datasets (query := VARCHAR)
Search the worker's curated typed endpoints, amount scales and interpretation notes. This local catalog is not an exhaustive listing of every Treasury API dataset; use records() for other relative Fiscal Data routes.
Discover fiscal datasets
SELECT dataset, endpoint, amount_units
FROM treasury.main.datasets()
ORDER BY dataset;
debt_to_penny (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT)
Daily debt held by the public, intragovernmental holdings and total public debt; exact API amounts.
Federal debt to the penny
SELECT record_date, tot_pub_debt_out_amt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date;
| record_date | tot_pub_debt_out_amt |
|---|---|
| 2024-01-02 | 33,990,128,000,000 |
| 2024-01-03 | 33,994,220,000,000 |
Reconcile each day's change in total public debt (debt_to_penny, exact dollars) with the Daily Treasury Statement's issues minus redemptions (public_debt_transactions, USD millions scaled to dollars); the gap stays within a few million dollars because statement amounts are rounded
WITH debt AS (SELECT record_date, tot_pub_debt_out_amt - lag(tot_pub_debt_out_amt) OVER (ORDER BY record_date) AS debt_change_usd FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-12')), flows AS (SELECT record_date, sum(CASE transaction_type WHEN 'Issues' THEN transaction_today_amt ELSE -transaction_today_amt END) * 1000000 AS net_issuance_usd FROM treasury.main.public_debt_transactions(start_date := '2024-01-03', end_date := '2024-01-12') GROUP BY record_date) SELECT f.record_date, f.net_issuance_usd, d.debt_change_usd, d.debt_change_usd - f.net_issuance_usd AS gap_usd
FROM flows AS f
JOIN debt AS d USING (record_date)
ORDER BY f.record_date;
deposits_withdrawals (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT)
Daily Treasury cash deposits and withdrawals, including month-to-date and fiscal-year-to-date figures. Categories and totals may overlap; filter before aggregation.
Cash deposits and withdrawals
SELECT transaction_type, transaction_catg, transaction_today_amt
FROM treasury.main.deposits_withdrawals(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY src_line_nbr;
fields (endpoint VARCHAR)
Read live field metadata for a relative Fiscal Data endpoint. Fetches a single source row to obtain metadata; it emits only field names, labels, source types and format descriptors.
Inspect endpoint fields
SELECT field_name, source_type, source_format
FROM treasury.main.fields('v2/accounting/od/debt_to_penny')
ORDER BY field_name;
monthly_statement (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT)
Monthly Treasury Statement table 1, including headers and subtotals. record_date identifies the report; classification_desc and record_type_cd identify the represented period. Raw API amounts are not scaled to the website display.
Monthly Treasury receipts and outlays
SELECT classification_desc, current_month_gross_rcpt_amt,
current_month_gross_outly_amt
FROM treasury.main.monthly_statement(start_date := '2024-01-31', end_date := '2024-01-31')
WHERE data_type_cd='D'
ORDER BY src_line_nbr;
operating_cash_balance (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT)
Daily Treasury operating cash balances. Since April 2022 some closing fields are null; account_type distinguishes opening and closing balance rows.
Operating cash balance
SELECT record_date, account_type, open_today_bal
FROM treasury.main.operating_cash_balance(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY record_date, src_line_nbr;
Compare the Treasury General Account closing cash balance (operating_cash_balance; since April 2022 the closing balance is the open_today_bal of the Closing Balance row, in USD millions) with total public debt outstanding (debt_to_penny) for each business day, as a percentage of debt
WITH tga AS (SELECT record_date, open_today_bal * 1000000 AS tga_close_usd FROM treasury.main.operating_cash_balance(start_date := '2024-01-02', end_date := '2024-01-12') WHERE account_type = 'Treasury General Account (TGA) Closing Balance') SELECT d.record_date, d.tot_pub_debt_out_amt, t.tga_close_usd, round(100 * t.tga_close_usd / d.tot_pub_debt_out_amt, 2) AS tga_pct_of_debt
FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-12') AS d
JOIN tga AS t USING (record_date)
ORDER BY d.record_date;
public_debt_transactions (end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT)
Public debt issues and redemptions by security type in USD millions. transaction_type distinguishes Issues and Redemptions; security_market distinguishes Marketable and Nonmarketable. security_type retains source classifications such as Bills, Notes, Bonds and Government Account Series; inspect distinct values in your date window rather than assuming a fixed enumeration. transaction_today_amt is daily, transaction_mtd_amt is month-to-date, and transaction_fytd_amt is fiscal-year-to-date. These are overlapping measures; do not sum them together or sum cumulative values across dates. For operating cash use operating_cash_balance(); for deposits and withdrawals use deposits_withdrawals().
Public debt transactions
SELECT transaction_type, security_type, transaction_today_amt
FROM treasury.main.public_debt_transactions(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY src_line_nbr;
records (endpoint VARCHAR, end_date := VARCHAR, filters_json := VARCHAR, max_rows := BIGINT, page_size := BIGINT, sort_fields := VARCHAR, start_date := VARCHAR, start_page := BIGINT)
Stream exact source records from any relative Fiscal Data v1/v2 route. record_json preserves every field; inspect fields() before extracting values. The default sort assumes record_date and src_line_nbr; choose sort_fields for endpoints with different keys.
Read arbitrary fiscal records
SELECT record_date, record_json
FROM treasury.main.records('v2/accounting/od/debt_to_penny', start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date;
Label every field of one raw record from an uncurated endpoint (the second line of Monthly Treasury Statement Table 9 for January 2024, Individual Income Taxes): fields() supplies each source field's label and type, records() the original JSON value as text
SELECT f.field_name, f.label, f.source_type,
r.record_json ->> f.field_name AS source_value
FROM treasury.main.records('v1/accounting/mts/mts_table_9', start_date := '2024-01-31', end_date := '2024-01-31', page_size := 1, start_page := 2, max_rows := 1) AS r
CROSS JOIN treasury.main.fields('v1/accounting/mts/mts_table_9') AS f
ORDER BY f.field_name;
Try these queries
debt_to_penny_endpoint — Look up the Fiscal Data endpoint behind debt_to_penny in the worker's curated dataset catalog (no network request)
SELECT dataset, endpoint
FROM treasury.main.datasets()
WHERE dataset = 'debt_to_penny';
Uses datasets
Inspect endpoint fields
SELECT field_name, source_type, source_format
FROM treasury.main.fields('v2/accounting/od/debt_to_penny')
ORDER BY field_name
Uses fields
Read arbitrary fiscal records
SELECT record_date, record_json
FROM treasury.main.records('v2/accounting/od/debt_to_penny', start_date := '2024-01-02', end_date := '2024-01-03')
ORDER BY record_date
Uses records
Reconcile each day's change in total public debt (debt_to_penny, exact dollars) with the Daily Treasury Statement's issues minus redemptions (public_debt_transactions, USD millions scaled to dollars); the gap stays within a few million dollars because statement amounts are rounded
WITH debt AS (SELECT record_date, tot_pub_debt_out_amt - lag(tot_pub_debt_out_amt) OVER (ORDER BY record_date) AS debt_change_usd FROM treasury.main.debt_to_penny(start_date := '2024-01-02', end_date := '2024-01-12')), flows AS (SELECT record_date, sum(CASE transaction_type WHEN 'Issues' THEN transaction_today_amt ELSE -transaction_today_amt END) * 1000000 AS net_issuance_usd FROM treasury.main.public_debt_transactions(start_date := '2024-01-03', end_date := '2024-01-12') GROUP BY record_date) SELECT f.record_date, f.net_issuance_usd, d.debt_change_usd, d.debt_change_usd - f.net_issuance_usd AS gap_usd
FROM flows AS f
JOIN debt AS d USING (record_date)
ORDER BY f.record_date
Operating cash balance
SELECT record_date, account_type, open_today_bal
FROM treasury.main.operating_cash_balance(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY record_date, src_line_nbr
Cash deposits and withdrawals
SELECT transaction_type, transaction_catg, transaction_today_amt
FROM treasury.main.deposits_withdrawals(start_date := '2024-01-02', end_date := '2024-01-02')
ORDER BY src_line_nbr
Uses deposits_withdrawals
6 more examples in the Catalog, each listed under the table or function it uses.
Treasury is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
BEA
Economy & labour
Discover BEA datasets, parameters and parameter values, then retrieve national, regional, industry and international economic accounts
BLS
Economy & labour
Retrieve labor, employment, price and productivity series with period codes, footnotes, calculations and survey metadata
Bank of England
Economy & labour
Discover Bank of England statistical series and retrieve observations with original periods, units and source metadata