Package: export-ease
export_easeBuilt upon Python modules that call JSON RESTful API to gather macroeconomic data, this package offers a streamlined interface through which you can request and subsequently analyze vast amounts of macroeconomic data from sources including UN Comtrade and the International Monetary Fund (IMF). Below is a step-by-step guide detailing effective use of this program. (This package was built to supplement aresearch projectled by Morad Bali at Duke University's Nicholas School of the Environment. The link provided offers further resources to tidy the data that this package writes.)Running the ProgramComtradeThis part of the program utilizes the comtradeapicall Python package to implement additional functionality.
To query export and import data from Comtrade, you can use the following methods:get_all_exports: writes csv file containing export data for all available country pairs (i.e., exports from each reportner to all its partners)get_total_exports: writes csv file containing total-export (exports to world) data for all available reportersget_all_imports: writes csv file containing import data for all available country pairs (i.e., imports to each reporter from all its partners)get_total_imports: writes csv file containing total-import (imports from world) data for all available reportersget_cmd_exports: writes csv file containing import data for a commodity for a specific reporter-partner pair. If you want the total amount of a commodity imported by a reporter, make the partner0(the world). If you want the amount of a commodity imported by a reporter from each of its individual partners, make the partner argumentNULL(all possible partners).get_cmd_imports: does same thing asget_cmd_exportsbut for importsWhen you run these functions, you'll need to enter the criteria for your query. All of these functions require at least two arguments, the first being the frequency ("A" for annual, "M" for monthly, or "B" for both) and the second being the year for which to gather data (e.g., 2021). Once the program's finished running, it'll output the names of the files that were just created.get_cmd_exportsandget_cmd_importsalso require reporter, partner, and cmd_code arguments. You can find Comtrade's country codes indataunder the file name "comtrade_countries.pdf"  and HS-classified commodity codeshere.IMFFunctions with which to query data:get_reporter_exports: writes csv file containing value exports from reporter provided in console input to all its partnersget_total_exports: same as Comtrade's get_total_exports methodThe code to get IMF data is almost identical in structure to Comtrade's. The only difference is the arguments for get_reporter_exports (get_total_exports is the same across Comtrade and IMF): the first argument is the name of the reporting country for which you'd like to gather (e.g., "France"), followed by the frequency and year (in the same format as Comtrade's).If you input an incorrect country name forget_reporter_exports, you can check country_codes.csv to see valid country names (this file is written by the program when you runget_reporter_exports).Other NotesThis program assumes that the source code is contained in a subdirectory within the project (e.g.,src) and that the files generated will be written to another subdirectory titleddata(i.e., both your source code's anddata's parent directory must be the root directory for your project). Be sure that your project adheres to this structure, as this package will throw errors if it can't finddata.Data is expressed in USD (Comtrade in ones, IMF in millions) and is available in both monthly and annual quantities. In addition, no data from either source are seasonally or inflation adjusted.Comtrade functions will retrieve data for the given year only, while IMF functions will retrieve data starting at the given year and ending with the most recently published data.Theget_reporter_exportsfunction for IMF has a quirk that occurs when the user requests a query for annual data starting at a year within 3 years of the current year. In this case, the function will "override" the user's indicated year and instead make the starting year 3 years less than the current year--I had to add this padding in order to work around the varying structures of the JSON file returned by the IMF API. This has no serious implications, as it still gets all the data you requested (and then some).Example Python Scriptfrom export_ease.comtrade import Comtrade     # importing the Comtrade class
from export_ease.imf import IMF     # importing the IMF class

# see above documentation
Comtrade.get_all_exports("B", 2021)
Comtrade.get_total_exports("B", 2021)

Comtrade.get_all_imports("B", 2021)
Comtrade.get_total_imports("B", 2021)

IMF.get_reporter_exports("France", "B", 2021)
IMF.get_total_exports("B", 2021)The above code can also be found in thetestfolder in theGitHub repositoryfor this package.