just the Federal Treasury API
‹
€ | | €€€€≤±‹€€€€≤±‹
€ .| -- | -+
€ ' | | | €€€€≤±±≤€€€€€€€€€€€€≤±±≤€€€€€≤±
€ `| |
€ |`. | €€€€≤±±≤€€€€€€€€€€€€≤±±≤€€€€€≤±
€ | `.|
€ | |`. €€€€≤±±≤€€€€€€€€€€€€≤±±≤€€€€€≤±
€ + | | '
€ | _ | __ | _' €€€≤±±≤€€€€€€€€€€€€≤±±≤€€€€€≤±
€ | |
€€€€€€€€€€€€€€€€€€€€€€≤±±≤€€€€€€€€€€€€≤±±≤€€€€€≤±
€
€€€€€€€€€€€€€€€€€€€€€€≤±±≤€€€€€€€€€€€€≤±±≤€€€€€≤±
€
€ fl±≤€€€€€€€€€€€€≤±±≤€€€€€≤±
€ fl±≤€€€€€≤±
€
€
About this branch
the just-the-api branch of federal-treasury-api contains just the code needed to download the data locally and host a queryable api. master contains code specific to running on ScraperWiki.
About the API
federal-treasury-api is the first-ever electronically-searchable database of the Federal government's daily cash spending and borrowing. It updates daily and the data can be exported in various formats and loaded into various systems.
About the data
There are eight tables.
- I. Operating Cash Balance (
t1) - II. Deposits and Withdrawals (
t2) - IIIa. Public Debt Transactions (
t3a) - IIIb. Adjustment of Public Dept Transactions to Cash Basis (
t3b) - IIIc. Debt Subject to Limit (
t3c) - IV. Federal Tax Deposits (
t4) - V. Short-term Cash Investments (
t5) - VI. Incom Tax Refunds Issued (
t6)
Check out our comprehensive data dictionary and treasury.io for more information.
Obtaining the data
Dependencies
pip install -r requirements.pip
Download, parse raw data, and build database
POSIX / MAC OSX
This one command downloads the (new) fixies and converts them to an SQLite3 database.
./run.sh
Warning: this will take a while... ~ 15-20 minutes on a 5 mbps connection.
Windows
Run everything
cd parser
python download_and_parse_fms_fixies.py
Starting the API
First run this:
python api.py
Now navigate to http://localhost:5000/
Querying the API
parameters:
q= A url-encoded SQL queryformat=jsonorcsv
example:
http://localhost:5000/?q=SELECT * FROM t2 LIMIT 10
Testing the data
This one command tests whether the data is up-to-date, what values are null, if any, and if there are any new line items in the data that we're not yet aware of.
./test.sh
test.sh is also run with run.sh
Optional emails:
If you'd like these tests to be emailed every day, you can register a free app at http://postmarkapp.com. You'll then want to to configure postmark.yml with your credentials:
from: mypostmarkemail@domain.com
to: mypersonalgmail+federal-treasury-api-tests@gmail.com
api_key: dfasfdsdga-dgasg-gdsag-dgasgd-dgasdg
You'll also need to install the following modules:
pip install pystmark pyyaml
Submitting Errors
If you get an emailed error, it means that we've probably got one too. But if we haven't gotten around to fixing it yet, please submit an issue to the repo.
Cron
Run everything each day around 4:30 - right after the data has been released.
30 16 * * * cd path/to/federal-treasury-api && ./run.sh
Optional: set up logging
30 16 * * * cd path/to/federal-treasury-api && ./run.sh >> run.log 2>> err.log