Skip to main content

A package that facilitates API calls to UN Comtrade and the International Monetary Fund to gather macroeconomic export data

Project description

export_ease

Built 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 a research project led 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 Program

Comtrade

  • This part of the program utilizes the comtradeapicall Python package to implement additional functionality.
  • To query export 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 reporters
  • When you run these functions, you'll need to enter the parameters for your query in the console. The program will ask you for the input that the query requires. Once the program's finished running, it'll output the names of the files that were just created.

IMF

  • The code to get IMF data is almost identical in structure to Comtrade's. The only difference is the input required to make the query, but there's no need to worry about accidentally typing the wrong input, as the program will both prompt you for the type of input and ensure the input is valid before making the API call.
    • If you input an incorrect country name for get_reporter_exports, you can check country_codes.csv to see valid country names (this file is written by the program when you run get_reporter_exports).
  • Functions with which to query data:
    • get_reporter_exports: writes csv file containing value exports from reporter provided in console input to all its partners
    • get_total_exports: same as Comtrade's get_total_exports method

Other Notes

  • This 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 titled data (i.e., both your source code's and data'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 find data.
  • Data is expressed in USD (Comtrade in ones, IMF in millions) and is available in both monthly and annual quantities.
  • All methods defined in this package don't require any arguments, but they will prompt you for input through the console/terminal.
  • 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.
  • The get_reporter_exports function 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 Script

from export_ease.comtrade import Comtrade     # importing the Comtrade class
from export_ease.imf import IMF     # importing the IMF class

comtrade_obj = Comtrade()     # creating a Comtrade object so that we can use the methods of the class we imported
imf_obj = IMF()     # creating an IMF object so that we can use the methods of the class we imported

# see above documentation
comtrade_obj.get_all_exports()
comtrade_obj.get_total_exports()

imf_obj.get_reporter_exports()
imf_obj.get_total_exports()

The above code can also be found in the test folder in the GitHub repository for this package.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

export_ease-0.0.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

export_ease-0.0.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file export_ease-0.0.1.tar.gz.

File metadata

  • Download URL: export_ease-0.0.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for export_ease-0.0.1.tar.gz
Algorithm Hash digest
SHA256 347838e7378cc2776b03fe05c43bcfb2b9053fb83c965609461d88af54d6269b
MD5 d1cac8df4f47940471707560647ff43e
BLAKE2b-256 1ac6f743a530213d6ab1ad84bfe4eb62fd6bb14756dec9e03ffd33450efd3d80

See more details on using hashes here.

File details

Details for the file export_ease-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: export_ease-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for export_ease-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 59794d6492de952d6d15cc13012c26d4d776deb024b06bf2851232cec9c45d47
MD5 06e64761a7b79705e092afcf2c82aaf5
BLAKE2b-256 0051518a756c49e618bff914bcaa3e84ef37bb12ee218228924fcb26153f10f1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page