{"id":17957904,"url":"https://github.com/mwouts/world_trade_data","last_synced_at":"2025-04-03T17:40:38.499Z","repository":{"id":55527017,"uuid":"223821129","full_name":"mwouts/world_trade_data","owner":"mwouts","description":"World Integrated Trade Solution (WITS) API in Python","archived":false,"fork":false,"pushed_at":"2023-07-19T14:59:15.000Z","size":271,"stargazers_count":33,"open_issues_count":5,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-10T12:16:27.530Z","etag":null,"topics":["data","statistics","trade","worldbank"],"latest_commit_sha":null,"homepage":"https://mwouts.github.io/world_trade_data","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mwouts.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-11-24T22:42:26.000Z","updated_at":"2025-02-19T03:41:01.000Z","dependencies_parsed_at":"2023-01-22T10:15:52.614Z","dependency_job_id":"90a848ab-d94b-4fe0-9ffe-68a184187793","html_url":"https://github.com/mwouts/world_trade_data","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"8bf57d4e2df47add95ee8472ebff70ccef096786"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwouts%2Fworld_trade_data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwouts%2Fworld_trade_data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwouts%2Fworld_trade_data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwouts%2Fworld_trade_data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mwouts","download_url":"https://codeload.github.com/mwouts/world_trade_data/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247051582,"owners_count":20875675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","statistics","trade","worldbank"],"created_at":"2024-10-29T10:57:47.143Z","updated_at":"2025-04-03T17:40:38.456Z","avatar_url":"https://github.com/mwouts.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# World Trade Statistics (WITS) API in Python\n\n[![Build Status](https://travis-ci.com/mwouts/world_trade_data.svg?branch=master)](https://travis-ci.com/mwouts/world_trade_data)\n[![codecov.io](https://codecov.io/github/mwouts/world_trade_data/coverage.svg?branch=master)](https://codecov.io/github/mwouts/world_trade_data?branch=master)\n[![Language grade: Python](https://img.shields.io/badge/lgtm-A+-brightgreen.svg)](https://lgtm.com/projects/g/mwouts/world_trade_data/context:python)\n[![Pypi](https://img.shields.io/pypi/v/world_trade_data.svg)](https://pypi.python.org/pypi/world_trade_data)\n[![pyversions](https://img.shields.io/pypi/pyversions/world_trade_data.svg)](https://pypi.python.org/pypi/world_trade_data)\n[![Jupyter Notebook](https://img.shields.io/badge/Binder-Notebook-blue.svg)](\n    https://mybinder.org/v2/gh/mwouts/world_trade_data/master?filepath=README.md)\n[![GitHub.io](https://img.shields.io/badge/GitHub-HTML-blue.svg)](https://mwouts.github.io/world_trade_data)\n\u003ca class=\"github-button\" href=\"https://github.com/mwouts/world_trade_data\" data-icon=\"octicon-star\" data-show-count=\"true\" aria-label=\"Star mwouts/world_trade_data on GitHub\"\u003eStar\u003c/a\u003e\n\nThis package is an implementation of the [World Integrated Trade Solution API](https://wits.worldbank.org/witsapiintro.aspx).\nUse this package to explore the [Trade and Tariff Data](https://wits.worldbank.org/) published by the [World Bank](https://www.worldbank.org/).\n\nThis python package itself is licenced under the MIT License. Different Terms and Conditions apply to the WITS data itself, please read the [Frequently Asked Questions](https://wits.worldbank.org/faqs.html) on the WITS website.\n\n# Quick tutorial\n\n## Installation\n\nInstall or update the _World Trade Data_ python package with\n\n```\npip install world_trade_data --upgrade\n```\n\n## Get the list of countries, products, indicators\n\nSee the outputs of the commands below on [GitHub](https://mwouts.github.io/world_trade_data/). Or even, open this `README.md` as a notebook and run it interactively on [Binder](https://mybinder.org/v2/gh/mwouts/world_trade_data/master?filepath=README.md)!\n\n```python\nimport pandas as pd\nimport world_trade_data as wits\npd.set_option('display.max_rows', 6)\n```\n\n```python\nwits.get_countries()\n```\n\n```python\nwits.get_products()\n```\n\n```python\nwits.get_indicators()\n```\n\nAll these methods accept a `datasource` argument, which can be any of\n```python\nwits.DATASOURCES\n```\n\nThe nomenclature, and data availability, are accessible with `get_nomenclatures()` and `get_dataavailability()`.\n\n## Get the Trade or Tariff data\n\nIndicators are available with `get_indicator`. Tariff rates can be loaded with `get_tariff_reported` and `get_tariff_estimated`.\n\n## Working with codes rather than with category names\n\nThe three functions above accept a `name_or_id` argument that defaults to `'name'`. Use `name_or_id='id'` to \nget codes rather than full description for products and countries:\n\n```python\nwits.get_indicator('MPRT-TRD-VL', reporter='usa', year='2017', name_or_id='id')\n```\n\n## Sample use case\n\nIn the below we show how to collect and plot the Import and Export data for the USA in 2017.\n\n![](https://raw.githubusercontent.com/mwouts/world_trade_data/master/examples/usa_2017.png)\n\nTo begin with, we request the values for the corresponding import and exports. Here, we use the default value for `partner='wld'`, and the default value for `product='all'`.\n\n```python\nusa_imports_2017 = wits.get_indicator('MPRT-TRD-VL', reporter='usa', year='2017')\nusa_exports_2017 = wits.get_indicator('XPRT-TRD-VL', reporter='usa', year='2017')\n```\n\n```python\nusa_imports_2017\n```\n\nNow we remove the first levels of the index\n\n```python\nusa_imports_2017 = usa_imports_2017.loc['Annual'].loc['United States'].loc['World']\nusa_exports_2017 = usa_exports_2017.loc['Annual'].loc['United States'].loc['World']\n```\n\nNote that one line in the table gives the value for imports on all products:\n\n```python\nusa_imports_2017.loc['All Products']\n```\n\nIn order to avoid double counting, we only look at sectors:\n\n```python\nproducts = wits.get_products()\nsectors = products.loc[(products.grouptype=='Sector') \u0026 (products.index!='Total')].productdescription.values\nsectors\n```\n\nand make sure that we reproduce well the total:\n\n```python\nassert pd.np.isclose(usa_imports_2017.loc[sectors].Value.sum(), usa_imports_2017.loc['All Products'].Value)\n```\n\nFinally we represent the data using e.g. [Plotly's Pie Charts](https://plot.ly/python/pie-charts/)\n\n```python\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\n\nimports_musd = usa_imports_2017.loc[sectors].Value / 1e3\nexports_musd = usa_exports_2017.loc[sectors].Value / 1e3\n\nfig = make_subplots(rows=1, cols=2, specs=[[{'type':'domain'}, {'type':'domain'}]])\nfig.add_trace(go.Pie(labels=sectors, values=imports_musd, name=\"Imports\"), 1, 1)\nfig.add_trace(go.Pie(labels=sectors, values=exports_musd, name=\"Exports\"), 1, 2)\n\nfig.update_traces(hole=.4, \n                  scalegroup='usa',\n                  textinfo='label',\n                  hovertemplate = \"%{label}\u003cbr\u003e%{value:,.0f}M$\u003cbr\u003e%{percent}\")\n\nfig.update_layout(\n    title_text=\"Trade Statistics, USA, 2017\",\n    annotations=[dict(text='Imports\u003cbr\u003e{:.3f}T$'.format(imports_musd.sum()/1e6),\n                      x=0.17, y=0.5, font_size=16, showarrow=False),\n                 dict(text='Exports\u003cbr\u003e{:.3f}T$'.format(exports_musd.sum()/1e6),\n                      x=0.83, y=0.5, font_size=16, showarrow=False)])\nfig.show(renderer='notebook_connected')\n```\n\n# References \u0026 Alternatives\n\n- The official [WITS portal](https://wits.worldbank.org/) let you visualize and download trade and tariff data. And the API implemented in this package is documented [here](https://wits.worldbank.org/witsapiintro.aspx).\n- The WITS data can be accessed in R with the [tradestatistics](https://tradestatistics.io/) library.\n- An alternative way to access the WITS data is to use [pandasdmx](https://pandasdmx.readthedocs.io/).\n\n\u003cscript async defer src=\"https://buttons.github.io/buttons.js\"\u003e\u003c/script\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwouts%2Fworld_trade_data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmwouts%2Fworld_trade_data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwouts%2Fworld_trade_data/lists"}