

#Us debt clock how to
While this tutorial is not focused on teaching you how to use Tableau, it describes the steps to build the visualization shown below.
#Us debt clock free
I chose to use the free Tableau Public data visualization desktop application and website to visualize US total debt since January 1, 2002.
#Us debt clock full

#Us debt clock code
The Python get_us_debt.py code module to call the c_us_debt class. The next section presents pseudocode that describes how the code works. It creates an instance of c_us_debt and calls it with file name, start date, and end date parameters. The module get_us_debt.py is the program’s entry point. To call the Debt Information API, I wrote a Python class called c_us_debt in module c_us_debt_api.py. Feel free to use those tools on Windows, or a recent version of Python and your preferred IDE or code editor on your platform of choice. I used Python 3.10 and the Microsoft Visual Studio Community 2022 integrated development environment (IDE), on Windows 10, to write and run the Python program described and shown below. Python Program to Retrieve Total Debt Data and Write it to a File You can also run this API call in a web browser, but the JSON-formatted data won’t be readable. The Python program in the following section expects a JSON output, so we will add the “format” parameter to the URL to return the data in the JSON format. But for programmatic purposes, it can also return data in the j son, jsonp, and xhtml (XML) formats. By default, the API returns data in this tabular format. It should return records like those shown in the screenshot below. To run this query, paste the full URL into the address bar of a web browser. Note these startdate and enddate parameters, that follow “:”Ī question mark (?) precedes the first parameter, while an ampersand (&) precedes subsequent parameters. It uses what the API documentation calls the “Debt Search Endpoint.” Following is the format of the Debt Information API for that date range.

In this tutorial, we will search, retrieve, and view more than twenty years of daily debt records, from January 1, 2002, through April 21, 2022. The API can be called with a web browser or from any number of programming languages, including Python. ” You can add parameters to the base URL to retrieve specific data.

Summary of Debt Information API and DataĬalling the Debt Information API is simple. It will then demonstrate how to create an area chart in Tableau Public to visualize the data. This article will show you how to write a Python program to retrieve debt data. You can programmatically retrieve US government debt level data, to the penny, with the US TreasuryDirect Debt Information API managed by the US Department of the Treasury. That is more than thirty trillion dollars. Photo by Dan Dennis on Unsplash.Īccording to the US National Debt Clock, the United States federal government has amassed a total debt of $30,403,148,491,160 as I write this article.
