Two JSON datasets from the Commerce Ministry's TRADESTAT, all 98 HS chapters for FY2018-19 to FY2025-26 plus 4-digit gold, silver, copper and other metal imports by partner country, ready to query with plain Python.
Open-Source Tools · How-To · Policy analysis
How to use india-commodity-trade-deficit: eight years of HS-chapter trade data and bare-metal imports
Revised
· v1.0.0 · what changed
Code: github.com/herrrickshaw/india-commodity-trade-deficit
Watch the walkthrough
Watch on YouTube: youtu.be/MVZiBaQ_nFo
Why it is useful
- Economists, journalists and students who need the commodity leg of India's trade gap get 8 years of chapter-level exports and imports in two small JSON files, with no portal scraping.
- It replaces manual TRADESTAT downloads. The 4-digit file splits bullion out of chapter 71, which the 2-digit data cannot do (gold 7108 and silver 7106 separately).
- Evidence from the run: the totals reproduce the README headline (deficit widening from -$184.0 bn to -$334.3 bn), and a one-screen script ranks chapters by deficit: mineral fuels, then precious stones and metals, then electrical machinery.
- A useful catch: silver imports rose from $4.8 bn to $12.1 bn (+150%) in one year, while platinum-group imports fell 92%, which looks like trade moving between customs lines, not demand disappearing.
What it is for
The repo isolates the commodity part of India's merchandise trade deficit using DGCI&S TRADESTAT figures (US$ million). data/ holds the chapter-level export/import file and the 4-digit bare-metal file with country breakdowns, plus a validation file on listed metal recyclers. blog/ holds a finished HTML post on the recycling counter-force.
This post uses only the two TRADESTAT files, read with the Python standard library.
Who it is for
- Trade and macro analysts
- Journalists writing on gold, silver and copper imports
- Students looking for a clean, citable trade dataset
- Researchers testing the recycling-substitution argument
- Trading or investment decisions: this is not investment advice
- Real-time monitoring: the data is annual and FY2025-26 is provisional
- Product-level (HS8) analysis: the files stop at chapter and selected 4-digit codes
What you need
| Requirement | Why | How to get it |
|---|---|---|
| Python 3 (standard library) | The JSON files load with the json module | python3 --version |
| git | To clone | Pre-installed on most systems |
Get the code and an AI assistant
You do not have to be a programmer. Get the repository, give it to an AI assistant, and ask in plain language. Any of these routes works:
| Tool | What you need | Best for |
|---|---|---|
| GitHub | Free account to fork or star; git to clone, or the green Code button, then Download ZIP, or open in Codespaces | Getting the code and keeping up with updates |
| Claude Code | Claude subscription or API key; run claude inside the cloned folder | Letting the AI read and run the whole repo |
| Gemini CLI | Google account; run gemini inside the cloned folder | The same hands-on workflow with Gemini |
| Claude.ai, Gemini or ChatGPT in the browser | A chat account; upload README.md and the files you care about (or paste the output of git ls-files) | Understanding the project and asking questions without installing anything |
| Other tools (Copilot Chat, Cursor, Codex CLI) | Open the cloned folder in the tool and point it at README.md first | Editing and extending the code |
git clone https://github.com/herrrickshaw/india-commodity-trade-deficit.git
cd india-commodity-trade-deficit
claude # or: gemini
Install
- Clone the repository
git clone https://github.com/herrrickshaw/india-commodity-trade-deficit.git cd india-commodity-trade-deficit
Quick start: commands and what you should see
Print the trade balance by fiscal year
python3 - <<'E'
import json
d=json.load(open('data/tradestat_hsn_export_import_2018-19_to_2025-26.json'))
t=d['totals']
for y in t['import']:
print(y, round(t['import'][y]/1e3,1), round(t['export'][y]/1e3,1), round((t['export'][y]-t['import'][y])/1e3,1))
E
Eight rows of year, imports, exports and balance in US$ billion.
Rank chapters by FY2025-26 trade balance
python3 - <<'E'
import json
d=json.load(open('data/tradestat_hsn_export_import_2018-19_to_2025-26.json'))
i,e=d['by_chapter']['import'],d['by_chapter']['export']
y='2025 - 2026'
r=sorted((e.get(c,{}).get(y,0)-v[y],c,v['name'][:40]) for c,v in i.items())
for b,c,n in r[:8]: print(c,n,round(b/1e3,1))
E
The eight chapters with the largest deficits; see sample outputs.
Sample outputs
Real output from a run on the date shown in the sources line; trimmed to fit.
Trade balance by fiscal year (US$ billion)
FY imports exports balance
2018-19 514.1 330.1 -184.0
2019-20 474.7 313.4 -161.3
2020-21 394.4 291.8 -102.6
2021-22 613.1 422.0 -191.0
2022-23 716.0 451.1 -264.9
2023-24 678.2 437.1 -241.1
2024-25 721.2 437.7 -283.5
2025-26 776.0 441.7 -334.3 (provisional)
Computed from the 'totals' block of the chapter file.
Chapter deficit table, FY2025-26 (US$ billion)
ch name imports exports balance
27 Mineral fuels, mineral oils 203.4 55.9 -147.5
71 Pearls, precious/semi-precious stones+metals 109.4 28.3 -81.1
85 Electrical machinery and equipment 104.9 54.0 -50.9
84 Nuclear reactors, boilers, machinery 74.0 36.6 -37.4
15 Animal or vegetable fats and oils 19.8 2.2 -17.5
39 Plastic and articles thereof 22.2 7.6 -14.6
31 Fertilisers 14.6 0.2 -14.4
88 Aircraft, spacecraft and parts 13.8 1.7 -12.1
Chapter 27 plus 71 are 40.3% of FY2025-26 imports in my calculation; chapter 71 alone supplied $20.5 bn of the $54.8 bn rise in total imports (37%).
4-digit bare-metal imports (US$ billion)
hs item FY25 FY26 change share of imports FY26
7108 Gold, unwrought/semi-mfd 58.01 71.98 +24% 9.28%
7106 Silver 4.83 12.05 +150% 1.55%
7110 Platinum group metals 5.42 0.42 -92% 0.05%
2603 Copper ores+concentrates 3.85 5.94 +54% 0.77%
7404 Copper waste and scrap 2.38 3.43 +44% 0.44%
7602 Aluminium waste and scrap 3.93 4.55 +16% 0.59%
From data/metals_hsn4_import_2024-25_to_2025-26.json (14 codes in total; trimmed here).
Ways to use it
| Method | How it works |
|---|---|
| Plain Python or pandas | Load the JSON and reshape by_chapter into a DataFrame for charts. |
| Country drill-down | The 4-digit file has a by_country block per code, for example gold by Switzerland, UAE, Peru and Ghana. |
| Read the finished essay | blog/blog_metal_recycling_import_bill.html is a self-contained post you can open in a browser. |
| Through an AI assistant | Open the clone in Claude Code or Gemini CLI, or upload the JSON files to a chat assistant and ask for tables or charts. |
Sample prompts for your AI assistant
Copy, paste and edit the parts in [brackets].
- Load data/tradestat_hsn_export_import_2018-19_to_2025-26.json and chart the trade balance by year, with chapters 27 and 71 shown separately.
- Which chapters contributed most to the rise in imports between FY2024-25 and FY2025-26? Show a table and explain the top three.
- From the 4-digit metals file, show gold imports by partner country for both years and flag the biggest changes.
- Compare silver (7106) and platinum group metals (7110) import values across the two years and suggest, with caveats, why they moved in opposite directions.
- Read the README and tell me which numbers in the headline table I can reproduce from the JSON files and which I cannot.
Limits and honest caveats
- Not investment advice. Annual trade statistics only.
- FY2025-26 is provisional (source last updated 19 May 2026 per the file); the data was retrieved 18 July 2026 and 3 August 2026, so later revisions are not included.
- Commodity share depends on the definition. The README's 48% is oil plus chapter 71 plus metal chapters; my simpler chapter 27 plus 71 figure is 40.3%, so state your definition.
- The metals file covers 14 selected 4-digit codes, not all of HS; 'diamonds' (7102) sits there only for chapter-71 context.
- Partner-country values are as served by TRADESTAT; re-exports and misclassification can shift flows between codes, which is what the platinum-to-gold shift may reflect.
- I did not run or validate the metal-recycler business-model file; it contains company financial claims that need their own check.
Sources: the india-commodity-trade-deficit README and data/ JSON files (TRADESTAT / DGCI&S via the Commerce Ministry); queries run with Python 3 standard library on 19 October 2026 on the committed files.
- v1.0.0 — 19 October 2026 — first published.
About this article: Researched, written and edited by Umashankar Triplicane Dwarakanathan, with AI research assistance; every figure is meant to trace to the primary source cited. See the Editorial Policy for how sourcing, AI use and corrections work.