A script and result file that sort India's chemical, fertiliser and plastics imports into import-substitution signals at 8-digit HS level, using public TRADESTAT value and quantity data.
Open-Source Tools · How-To · Policy analysis
How to use chemical_import_substitution: HS-8 import-substitution signals for India's chemical chapters
Revised
· v1.0.0 · what changed
Code: github.com/herrrickshaw/chemical_import_substitution
Watch the walkthrough
Watch on YouTube: youtu.be/8c9sOTgIJRE
Why it is useful
- Industrial-policy analysts and investors scanning for import-substitution gaps get a pre-sorted list of 827 chemical HS-8 lines instead of eight raw TRADESTAT chapter downloads.
- It replaces a manual rule of thumb with explicit signals: A scissors (value and volume falling, price rising), B inelastic target, D deepening, E no clear signal.
- Evidence from the run: the committed results show plastics (ch. 39), organic chemicals (ch. 29), fertilisers (ch. 31) and inorganic chemicals (ch. 28) carry $59.3 bn of the $67.9 bn deficit, and 59.6% of codes have no clear one-year signal, a useful reminder of how little one year of data can say.
- The top lines are fertilisers and precious-metal compounds, which the repo's own rationale tags call structurally import-dependent rather than substitutable.
What it is for
The repo has one analysis script (scripts/hsn8_signal_analysis.py) and its output (data/chem_hsn8_signals.json, plus an HTML registry of codes). For each HS-8 code in chapters 28, 29, 31, 32, 33, 34, 38 and 39 with an FY2025-26 import-minus-export gap of at least $0.5 million, it computes value, volume and unit-price growth and assigns a signal and a keyword-based rationale tag.
The script needs the raw TRADESTAT Excel downloads, which are not in the repo, so this post reads the committed result file.
Who it is for
- Industrial-policy and PLI analysts
- Chemical-sector researchers and equity analysts looking for gaps
- Students of import substitution
- Developers wanting a worked HS-8 classification example
- Investment advice: this is not investment advice
- Judging true substitutability: the rationale text is keyword rules, not engineering assessment (conceptual, not engineering design)
- Multi-year trend claims: the signals use a single fiscal-year change
What you need
| Requirement | Why | How to get it |
|---|---|---|
| Python 3 | To read the JSON result file (standard library is enough) | python3 --version |
| openpyxl (only to re-run the script) | The script reads TRADESTAT .xlsx exports | pip install openpyxl |
| TRADESTAT HS-8 import/export value and import quantity files (only to re-run) | Raw inputs are not committed | Download from tradestat.commerce.gov.in; see the script docstring for the expected files |
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/chemical_import_substitution.git
cd chemical_import_substitution
claude # or: gemini
Install
- Clone the repository
git clone https://github.com/herrrickshaw/chemical_import_substitution.git cd chemical_import_substitution - Optional, for re-running the script
python3 -m venv .venv && source .venv/bin/activate pip install openpyxl
Quick start: commands and what you should see
Summarise the committed results by chapter and signal
python3 - <<'E'
import json
from collections import Counter
d=json.load(open('data/chem_hsn8_signals.json'))
for ch,v in sorted(d['by_chapter'].items()):
print(ch, d['ch_names'][ch], len(v), round(sum(r['deficit_fy26'] for r in v)/1e3,1), dict(Counter(r['is_signal'][0] for r in v)))
E
One line per chapter: code count, deficit in US$ billion and a count of signal letters.
List the active-substitution (scissors) codes
python3 - <<'E'
import json
d=json.load(open('data/chem_hsn8_signals.json'))
r=[x for v in d['by_chapter'].values() for x in v if x['is_signal']=='A_SCISSORS']
for x in sorted(r,key=lambda x:-x['deficit_fy26'])[:5]: print(x['hs'],x['name'][:40],x['imp_fy25'],x['imp_fy26'],x['qty_growth_pct'],x['price_growth_pct'])
E
Five HS-8 codes with falling value and volume and rising price.
Sample outputs
Real output from a run on the date shown in the sources line; trimmed to fit.
HS-chapter substitution table (FY2025-26, US$ billion)
ch name codes imports exports deficit signals (A/B/C/D/E)
28 Inorganic Chemicals & Fert. Intermed. 113 12.75 0.72 12.03 5/7/0/36/65
29 Organic Chemicals 305 19.73 4.07 15.66 11/16/16/66/196
31 Fertilisers 20 14.58 0.15 14.43 0/3/0/9/8
32 Dyes, Pigments, Tanning & Colouring 59 2.32 0.42 1.90 1/3/0/16/39
33 Essential Oils, Cosmetics, Perfumery 28 0.89 0.40 0.49 2/2/0/11/13
34 Soaps, Waxes, Polishes, Surfactants 24 1.13 0.27 0.86 3/3/0/4/14
38 Miscellaneous Chemical Products 77 7.25 1.93 5.32 5/11/9/15/37
39 Plastics & Articles Thereof 201 20.90 3.69 17.21 7/21/0/52/121
Totals over the 827 qualifying codes (FY2025-26 import minus export of at least $0.5 million). Signal letters: A scissors, B inelastic target, C insufficient data, D deepening, E no clear signal.
Largest deficits by HS-8 code (US$ million)
31053000 Diammonium hydrogen orthophosphate (DAP) imports 4871.6 deficit 4867.4 D_DEEPENING
28433000 Gold compounds imports 4012.3 deficit 4012.2 B_INELASTIC_TARGET
31021010 Fertiliser grade, HS 3102 10 10 imports 3868.9 deficit 3868.8 D_DEEPENING
28092010 Phosphoric acid imports 2674.2 deficit 2666.0 E_NO_CLEAR_SIGNAL
39041020 Suspension-grade PVC resin imports 1632.6 deficit 1632.1 E_NO_CLEAR_SIGNAL
Names are cleaned up slightly from TRADESTAT's own spellings, which contain typos such as 'DIAMONM'.
Scissors signal examples
38231900 industrial monocarboxylic fatty acids imports 659.9 -> 548.9 qty -24% price +9.5%
34011920 soap flakes, chips and powder imports 141.3 -> 44.8 qty -71% price +8.5%
28258000 antimony oxides imports 76.4 -> 68.1 qty -60% price +122.9%
A falling quantity with a rising price is the script's marker of substitution; it can equally reflect supply shocks or a price spike.
Ways to use it
| Method | How it works |
|---|---|
| Query the committed JSON | Load data/chem_hsn8_signals.json and filter by chapter, signal or deficit size. |
| Re-run with fresh TRADESTAT files | Edit the file paths in hsn8_signal_analysis.py to point at new downloads (not run in this post). |
| Open the HTML registry | data/chem_hsn8_full_hsn_registry.html is a styled browsable table of the HS-8 lines. |
| Through an AI assistant | Upload chem_hsn8_signals.json to Claude, Gemini or ChatGPT, or open the clone in Claude Code or Gemini CLI. |
Sample prompts for your AI assistant
Copy, paste and edit the parts in [brackets].
- Load data/chem_hsn8_signals.json and list the top 15 B_INELASTIC_TARGET codes by FY2025-26 deficit, with the rationale text for each.
- Explain the signal definitions in scripts/hsn8_signal_analysis.py and what each one can and cannot tell a policy analyst.
- Group the D_DEEPENING codes by chapter and show the five largest per chapter. Which look like feedstock dependence?
- Which scissors (A) codes might be false positives caused by price spikes? Suggest a check using a second fiscal year.
- Draft a methodology note for a report using this file, listing the limits stated in the script docstring.
Limits and honest caveats
- Not investment advice, and conceptual only: the rationale text comes from keyword rules on product names, not plant or engineering analysis.
- Single-year window (FY2024-25 to FY2025-26) only. The docstring itself says it lacks the 3-5 year trend, an Import Penetration Ratio, component-shift detection, country-of-origin checks and a tariff/PLI cross-reference.
- I did not run the script: its raw TRADESTAT Excel inputs are not in the repo. Everything shown is read from the committed results file (last commit 3 October 2026).
- Unit prices are stored rounded to one decimal, so many per-kg prices show as 0.0 in the file; use price_growth_pct instead.
- Product names are as served by TRADESTAT, typos included; for example one 'urea' line is labelled 'Fertilizer grade, conforming to Standard' and I paraphrased it in the table.
- There is no README in the repo, so the usage notes here come from the script docstring.
Sources: the chemical_import_substitution scripts/hsn8_signal_analysis.py docstring and data/chem_hsn8_signals.json (DGCI&S TRADESTAT FY2024-25 and FY2025-26); Python 3 standard-library queries run on 19 October 2026 on the committed files. The script itself was not run.
- 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.