Skip to content

Instantly share code, notes, and snippets.

@jsvine
Created November 18, 2015 12:30
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jsvine/9cb3300588ed402160fe to your computer and use it in GitHub Desktop.
Save jsvine/9cb3300588ed402160fe to your computer and use it in GitHub Desktop.
How to download SIPRI arms transfer data as a CSV file instead of a rich-text file.

The Stockholm International Peace Research Institute's Arms Transfers Database provides a tool to download the data. By default, that output is an .rtf rich-text file — not so easy to analyze with your favorite spreadsheet or statistics software. Luckily, getting a CSV of the data isn't very difficult. Here's how.

To get all transfers for 2014, by seller, run this command in your terminal:

curl http://armstrade.sipri.org/armstrade/html/export_trade_register.php --compressed \
    --data 'low_year=2014' \
    --data 'high_year=2014' \
    --data 'seller_country_code=' \
    --data 'buyer_country_code=' \
    --data 'armament_category_id=any' \
    --data 'buyers_or_sellers=sellers' \
    --data 'filetype=csv' \
    --data 'include_open_deals=on' \
    --data 'sum_deliveries=on' \
    --data 'Submit4=Download' \
> sipri-arms-by-seller-2014.csv
  • To adjust the timespan, change the low_year and/or high_year variables. E.g., 'low_year=2010'.
  • To get data only for specific countries, add their three-letter codes to the seller_country_code and/or buyer_country_code variables, with each country code separated by a space. E.g., focus on U.S. and Canadian sales, use 'seller_country_code=USA CAN'.
@pierwill
Copy link

Thanks! Any way to include the "comments" field?

@nichnaib
Copy link

Hi, I am going to make an University project with this dataset but the site seems to be down for everyone, is there a way to re-upload the file? Maybe from someone who had download it? Thanks

@nichnaib
Copy link

Nevermind, the site came back up!

@BichTran91
Copy link

Hi Jeremy! I'm so glad to see your post. Could you please explain more about what tool you use to download the data as csv file? Thanks!

@jsvine
Copy link
Author

jsvine commented Sep 24, 2020

Hi @BichTran91, the tool used in the gist above is curl, a command-line utility for fetching HTTP(S) resources: https://en.wikipedia.org/wiki/CURL

Any HTTP library or tool should be able to do the same.

@BichTran91
Copy link

Hi @jsvine, thanks for your reply. I realized that your code runs on Linux (I'm using Windows). I figured out how to do the same using Request in Python. However, the columns I got were 'tidn', 'buyercod', 'sellercod', 'odat', 'odai', 'onum', 'onai', 'ldat', 'term', 'desig2', 'wcat', 'desc', 'coprod', 'nrdel', 'nrdelai', 'delyears', 'buyer', 'seller', 'status', 'tivunit', 'tivorder', 'tivdel'.
Did you encounter this problem? How to get the columns' full names and units?

@jsvine
Copy link
Author

jsvine commented Sep 28, 2020

Hi @BichTran91, unfortunately it has been a long time since I've examined the data or tried to download it. I would recommend examining the SIPRI website (or contacting SIPRI if the website doesn't provide enough information) to get official answers to these questions.

@BichTran91
Copy link

If there is a coding solution for that, I would like to know. Otherwise I agree with you suggestion. Thanks again, @jsvine!

@acoabo
Copy link

acoabo commented Oct 6, 2020

Hi just FYI I just used the code works perfectly! (using mac os 10.14)

thanks a ton, saved a lot of time, greetings from italy (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment