hs-code-tariff 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hs_code_tariff-0.1.0/LICENSE +21 -0
- hs_code_tariff-0.1.0/PKG-INFO +67 -0
- hs_code_tariff-0.1.0/README.md +49 -0
- hs_code_tariff-0.1.0/pyproject.toml +30 -0
- hs_code_tariff-0.1.0/setup.cfg +4 -0
- hs_code_tariff-0.1.0/src/hs_code_tariff/__init__.py +207 -0
- hs_code_tariff-0.1.0/src/hs_code_tariff/__main__.py +43 -0
- hs_code_tariff-0.1.0/src/hs_code_tariff.egg-info/PKG-INFO +67 -0
- hs_code_tariff-0.1.0/src/hs_code_tariff.egg-info/SOURCES.txt +10 -0
- hs_code_tariff-0.1.0/src/hs_code_tariff.egg-info/dependency_links.txt +1 -0
- hs_code_tariff-0.1.0/src/hs_code_tariff.egg-info/entry_points.txt +2 -0
- hs_code_tariff-0.1.0/src/hs_code_tariff.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RadarBG (https://radarbg.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hs-code-tariff
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Zero-dependency offline Harmonized System (HS 2022) 97-chapter & 21-section classifier, HS/CN/HTS code validator, normalizer, and keyword search CLI.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://radarbg.com/tools/hs-code-lookup?ref=pypi-hscode
|
|
7
|
+
Project-URL: Free Online HS Code Lookup, https://radarbg.com/tools/hs-code-lookup?ref=pypi-hscode
|
|
8
|
+
Project-URL: HS Code Tariff REST API, https://radarbg.com/apis/hs-code-tariff-lookup?ref=pypi-hscode
|
|
9
|
+
Keywords: hs-code,tariff,customs,harmonized-system,hts,cn-code,ecommerce,trade,logistics,cli
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Office/Business
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# hs-code-tariff
|
|
20
|
+
|
|
21
|
+
Zero-dependency offline **Harmonized System (HS 2022)** code validator, normalizer, 97-chapter & 21-section classifier, and keyword search utility for Python.
|
|
22
|
+
|
|
23
|
+
Need **full 6/8/10-digit commodity descriptions, EU TARIC / US HTS duty rates, or natural-language product classification**?
|
|
24
|
+
- Free browser lookup (no sign-up): [radarbg.com/tools/hs-code-lookup](https://radarbg.com/tools/hs-code-lookup?ref=pypi-hscode)
|
|
25
|
+
- REST API (JSON, full HS/HTS/tariff search): [radarbg.com/apis/hs-code-tariff-lookup](https://radarbg.com/apis/hs-code-tariff-lookup?ref=pypi-hscode)
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install hs-code-tariff
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from hs_code_tariff import parse_hs_code, search_chapters
|
|
37
|
+
|
|
38
|
+
info = parse_hs_code("2204.21.00")
|
|
39
|
+
print(info)
|
|
40
|
+
# {
|
|
41
|
+
# 'raw': '2204.21.00',
|
|
42
|
+
# 'digits': '22042100',
|
|
43
|
+
# 'formatted': '2204.21.00',
|
|
44
|
+
# 'valid': True,
|
|
45
|
+
# 'level': 'CN-8 (EU Combined Nomenclature)',
|
|
46
|
+
# 'chapter': '22',
|
|
47
|
+
# 'chapter_title': 'Beverages, spirits and vinegar',
|
|
48
|
+
# 'section': 'IV',
|
|
49
|
+
# 'section_title': 'Prepared Foodstuffs; Beverages, Spirits and Vinegar; Tobacco',
|
|
50
|
+
# 'heading': '2204',
|
|
51
|
+
# 'subheading': '220421'
|
|
52
|
+
# }
|
|
53
|
+
|
|
54
|
+
hits = search_chapters("coffee")
|
|
55
|
+
# [{'chapter': '09', 'title': 'Coffee, tea, maté and spices', 'section': 'II', ...}]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## CLI
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
hs-code-tariff 8517.13
|
|
62
|
+
hs-code-tariff --search "lithium battery"
|
|
63
|
+
hs-code-tariff --json 2204.21 6109.10
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
MIT
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# hs-code-tariff
|
|
2
|
+
|
|
3
|
+
Zero-dependency offline **Harmonized System (HS 2022)** code validator, normalizer, 97-chapter & 21-section classifier, and keyword search utility for Python.
|
|
4
|
+
|
|
5
|
+
Need **full 6/8/10-digit commodity descriptions, EU TARIC / US HTS duty rates, or natural-language product classification**?
|
|
6
|
+
- Free browser lookup (no sign-up): [radarbg.com/tools/hs-code-lookup](https://radarbg.com/tools/hs-code-lookup?ref=pypi-hscode)
|
|
7
|
+
- REST API (JSON, full HS/HTS/tariff search): [radarbg.com/apis/hs-code-tariff-lookup](https://radarbg.com/apis/hs-code-tariff-lookup?ref=pypi-hscode)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install hs-code-tariff
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from hs_code_tariff import parse_hs_code, search_chapters
|
|
19
|
+
|
|
20
|
+
info = parse_hs_code("2204.21.00")
|
|
21
|
+
print(info)
|
|
22
|
+
# {
|
|
23
|
+
# 'raw': '2204.21.00',
|
|
24
|
+
# 'digits': '22042100',
|
|
25
|
+
# 'formatted': '2204.21.00',
|
|
26
|
+
# 'valid': True,
|
|
27
|
+
# 'level': 'CN-8 (EU Combined Nomenclature)',
|
|
28
|
+
# 'chapter': '22',
|
|
29
|
+
# 'chapter_title': 'Beverages, spirits and vinegar',
|
|
30
|
+
# 'section': 'IV',
|
|
31
|
+
# 'section_title': 'Prepared Foodstuffs; Beverages, Spirits and Vinegar; Tobacco',
|
|
32
|
+
# 'heading': '2204',
|
|
33
|
+
# 'subheading': '220421'
|
|
34
|
+
# }
|
|
35
|
+
|
|
36
|
+
hits = search_chapters("coffee")
|
|
37
|
+
# [{'chapter': '09', 'title': 'Coffee, tea, maté and spices', 'section': 'II', ...}]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## CLI
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
hs-code-tariff 8517.13
|
|
44
|
+
hs-code-tariff --search "lithium battery"
|
|
45
|
+
hs-code-tariff --json 2204.21 6109.10
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hs-code-tariff"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Zero-dependency offline Harmonized System (HS 2022) 97-chapter & 21-section classifier, HS/CN/HTS code validator, normalizer, and keyword search CLI."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = []
|
|
13
|
+
keywords = ["hs-code", "tariff", "customs", "harmonized-system", "hts", "cn-code", "ecommerce", "trade", "logistics", "cli"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Topic :: Office/Business",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
hs-code-tariff = "hs_code_tariff.__main__:main"
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://radarbg.com/tools/hs-code-lookup?ref=pypi-hscode"
|
|
26
|
+
"Free Online HS Code Lookup" = "https://radarbg.com/tools/hs-code-lookup?ref=pypi-hscode"
|
|
27
|
+
"HS Code Tariff REST API" = "https://radarbg.com/apis/hs-code-tariff-lookup?ref=pypi-hscode"
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
where = ["src"]
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"""Zero-dependency offline Harmonized System (HS 2022) validator, classifier & search."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any, Dict, List
|
|
7
|
+
|
|
8
|
+
SECTIONS: Dict[str, str] = {
|
|
9
|
+
"I": "Live Animals; Animal Products",
|
|
10
|
+
"II": "Vegetable Products",
|
|
11
|
+
"III": "Animal, Vegetable or Microbial Fats and Oils",
|
|
12
|
+
"IV": "Prepared Foodstuffs; Beverages, Spirits and Vinegar; Tobacco",
|
|
13
|
+
"V": "Mineral Products",
|
|
14
|
+
"VI": "Products of the Chemical or Allied Industries",
|
|
15
|
+
"VII": "Plastics and Articles Thereof; Rubber and Articles Thereof",
|
|
16
|
+
"VIII": "Raw Hides and Skins, Leather, Furskins and Articles Thereof",
|
|
17
|
+
"IX": "Wood and Articles of Wood; Cork; Basketware",
|
|
18
|
+
"X": "Pulp of Wood; Paper and Paperboard and Articles Thereof",
|
|
19
|
+
"XI": "Textiles and Textile Articles",
|
|
20
|
+
"XII": "Footwear, Headgear, Umbrellas, Prepared Feathers",
|
|
21
|
+
"XIII": "Articles of Stone, Plaster, Cement, Asbestos, Mica; Ceramic; Glass",
|
|
22
|
+
"XIV": "Natural or Cultured Pearls, Precious Stones, Precious Metals, Jewelry",
|
|
23
|
+
"XV": "Base Metals and Articles of Base Metal",
|
|
24
|
+
"XVI": "Machinery and Mechanical Appliances; Electrical Equipment; Electronics",
|
|
25
|
+
"XVII": "Vehicles, Aircraft, Vessels and Associated Transport Equipment",
|
|
26
|
+
"XVIII": "Optical, Photographic, Cinematographic, Measuring, Medical Instruments; Clocks; Musical",
|
|
27
|
+
"XIX": "Arms and Ammunition; Parts and Accessories Thereof",
|
|
28
|
+
"XX": "Miscellaneous Manufactured Articles (Furniture, Toys, Sports)",
|
|
29
|
+
"XXI": "Works of Art, Collectors' Pieces and Antiques",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Official WCO HS 2022 Chapters (01-97; Chapter 77 is reserved for future use)
|
|
33
|
+
CHAPTERS: Dict[str, tuple[str, str]] = {
|
|
34
|
+
"01": ("I", "Live animals"),
|
|
35
|
+
"02": ("I", "Meat and edible meat offal"),
|
|
36
|
+
"03": ("I", "Fish and crustaceans, molluscs and other aquatic invertebrates"),
|
|
37
|
+
"04": ("I", "Dairy produce; birds' eggs; natural honey; edible products of animal origin"),
|
|
38
|
+
"05": ("I", "Products of animal origin, not elsewhere specified or included"),
|
|
39
|
+
"06": ("II", "Live trees and other plants; bulbs, roots; cut flowers and ornamental foliage"),
|
|
40
|
+
"07": ("II", "Edible vegetables and certain roots and tubers"),
|
|
41
|
+
"08": ("II", "Edible fruit and nuts; peel of citrus fruit or melons"),
|
|
42
|
+
"09": ("II", "Coffee, tea, mate and spices"),
|
|
43
|
+
"10": ("II", "Cereals"),
|
|
44
|
+
"11": ("II", "Products of the milling industry; malt; starches; inulin; wheat gluten"),
|
|
45
|
+
"12": ("II", "Oil seeds and oleaginous fruits; miscellaneous grains, seeds and fruit; medicinal plants"),
|
|
46
|
+
"13": ("II", "Lac; gums, resins and other vegetable saps and extracts"),
|
|
47
|
+
"14": ("II", "Vegetable plaiting materials; vegetable products not elsewhere specified"),
|
|
48
|
+
"15": ("III", "Animal, vegetable or microbial fats and oils and their cleavage products; edible fats"),
|
|
49
|
+
"16": ("IV", "Preparations of meat, of fish, of crustaceans, molluscs or of insects"),
|
|
50
|
+
"17": ("IV", "Sugars and sugar confectionery"),
|
|
51
|
+
"18": ("IV", "Cocoa and cocoa preparations"),
|
|
52
|
+
"19": ("IV", "Preparations of cereals, flour, starch or milk; pastrycooks' products"),
|
|
53
|
+
"20": ("IV", "Preparations of vegetables, fruit, nuts or other parts of plants"),
|
|
54
|
+
"21": ("IV", "Miscellaneous edible preparations"),
|
|
55
|
+
"22": ("IV", "Beverages, spirits and vinegar"),
|
|
56
|
+
"23": ("IV", "Residues and waste from the food industries; prepared animal fodder"),
|
|
57
|
+
"24": ("IV", "Tobacco and manufactured tobacco substitutes; nicotine products"),
|
|
58
|
+
"25": ("V", "Salt; sulphur; earths and stone; plastering materials, lime and cement"),
|
|
59
|
+
"26": ("V", "Ores, slag and ash"),
|
|
60
|
+
"27": ("V", "Mineral fuels, mineral oils and products of their distillation; bituminous substances"),
|
|
61
|
+
"28": ("VI", "Inorganic chemicals; organic or inorganic compounds of precious metals"),
|
|
62
|
+
"29": ("VI", "Organic chemicals"),
|
|
63
|
+
"30": ("VI", "Pharmaceutical products"),
|
|
64
|
+
"31": ("VI", "Fertilisers"),
|
|
65
|
+
"32": ("VI", "Tanning or dyeing extracts; dyes, pigments; paints and varnishes; inks"),
|
|
66
|
+
"33": ("VI", "Essential oils and resinoids; perfumery, cosmetic or toilet preparations"),
|
|
67
|
+
"34": ("VI", "Soap, organic surface-active agents, washing preparations, lubricating preparations, waxes"),
|
|
68
|
+
"35": ("VI", "Albuminoidal substances; modified starches; glues; enzymes"),
|
|
69
|
+
"36": ("VI", "Explosives; pyrotechnic products; matches; pyrophoric alloys"),
|
|
70
|
+
"37": ("VI", "Photographic or cinematographic goods"),
|
|
71
|
+
"38": ("VI", "Miscellaneous chemical products"),
|
|
72
|
+
"39": ("VII", "Plastics and articles thereof"),
|
|
73
|
+
"40": ("VII", "Rubber and articles thereof"),
|
|
74
|
+
"41": ("VIII", "Raw hides and skins (other than furskins) and leather"),
|
|
75
|
+
"42": ("VIII", "Articles of leather; saddlery and harness; travel goods, handbags"),
|
|
76
|
+
"43": ("VIII", "Furskins and artificial fur; manufactures thereof"),
|
|
77
|
+
"44": ("IX", "Wood and articles of wood; wood charcoal"),
|
|
78
|
+
"45": ("IX", "Cork and articles of cork"),
|
|
79
|
+
"46": ("IX", "Manufactures of straw, of esparto or of other plaiting materials; basketware"),
|
|
80
|
+
"47": ("X", "Pulp of wood or of other fibrous cellulosic material; recovered paper or paperboard"),
|
|
81
|
+
"48": ("X", "Paper and paperboard; articles of paper pulp, of paper or of paperboard"),
|
|
82
|
+
"49": ("X", "Printed books, newspapers, pictures and other products of the printing industry"),
|
|
83
|
+
"50": ("XI", "Silk"),
|
|
84
|
+
"51": ("XI", "Wool, fine or coarse animal hair; horsehair yarn and woven fabric"),
|
|
85
|
+
"52": ("XI", "Cotton"),
|
|
86
|
+
"53": ("XI", "Other vegetable textile fibres; paper yarn and woven fabrics"),
|
|
87
|
+
"54": ("XI", "Man-made filaments; strip and the like of man-made textile materials"),
|
|
88
|
+
"55": ("XI", "Man-made staple fibres"),
|
|
89
|
+
"56": ("XI", "Wadding, felt and nonwovens; special yarns; twine, cordage, ropes and cables"),
|
|
90
|
+
"57": ("XI", "Carpets and other textile floor coverings"),
|
|
91
|
+
"58": ("XI", "Special woven fabrics; tufted textile fabrics; lace; tapestries; embroidery"),
|
|
92
|
+
"59": ("XI", "Impregnated, coated, covered or laminated textile fabrics"),
|
|
93
|
+
"60": ("XI", "Knitted or crocheted fabrics"),
|
|
94
|
+
"61": ("XI", "Articles of apparel and clothing accessories, knitted or crocheted"),
|
|
95
|
+
"62": ("XI", "Articles of apparel and clothing accessories, not knitted or crocheted"),
|
|
96
|
+
"63": ("XI", "Other made-up textile articles; sets; worn clothing and rags"),
|
|
97
|
+
"64": ("XII", "Footwear, gaiters and the like; parts of such articles"),
|
|
98
|
+
"65": ("XII", "Headgear and parts thereof"),
|
|
99
|
+
"66": ("XII", "Umbrellas, sun umbrellas, walking-sticks, whips, riding-crops"),
|
|
100
|
+
"67": ("XII", "Prepared feathers and down; artificial flowers; articles of human hair"),
|
|
101
|
+
"68": ("XIII", "Articles of stone, plaster, cement, asbestos, mica or similar materials"),
|
|
102
|
+
"69": ("XIII", "Ceramic products"),
|
|
103
|
+
"70": ("XIII", "Glass and glassware"),
|
|
104
|
+
"71": ("XIV", "Natural or cultured pearls, precious or semi-precious stones, precious metals, jewellery"),
|
|
105
|
+
"72": ("XV", "Iron and steel"),
|
|
106
|
+
"73": ("XV", "Articles of iron or steel"),
|
|
107
|
+
"74": ("XV", "Copper and articles thereof"),
|
|
108
|
+
"75": ("XV", "Nickel and articles thereof"),
|
|
109
|
+
"76": ("XV", "Aluminium and articles thereof"),
|
|
110
|
+
"78": ("XV", "Lead and articles thereof"),
|
|
111
|
+
"79": ("XV", "Zinc and articles thereof"),
|
|
112
|
+
"80": ("XV", "Tin and articles thereof"),
|
|
113
|
+
"81": ("XV", "Other base metals; cermets; articles thereof"),
|
|
114
|
+
"82": ("XV", "Tools, implements, cutlery, spoons and forks, of base metal"),
|
|
115
|
+
"83": ("XV", "Miscellaneous articles of base metal"),
|
|
116
|
+
"84": ("XVI", "Nuclear reactors, boilers, machinery and mechanical appliances; computers; parts"),
|
|
117
|
+
"85": ("XVI", "Electrical machinery and equipment; sound recorders; TV; smartphones; batteries"),
|
|
118
|
+
"86": ("XVII", "Railway or tramway locomotives, rolling-stock and parts thereof"),
|
|
119
|
+
"87": ("XVII", "Vehicles other than railway or tramway rolling-stock, and parts and accessories"),
|
|
120
|
+
"88": ("XVII", "Aircraft, spacecraft, and parts thereof"),
|
|
121
|
+
"89": ("XVII", "Ships, boats and floating structures"),
|
|
122
|
+
"90": ("XVIII", "Optical, photographic, cinematographic, measuring, checking, precision, medical instruments"),
|
|
123
|
+
"91": ("XVIII", "Clocks and watches and parts thereof"),
|
|
124
|
+
"92": ("XVIII", "Musical instruments; parts and accessories of such articles"),
|
|
125
|
+
"93": ("XIX", "Arms and ammunition; parts and accessories thereof"),
|
|
126
|
+
"94": ("XX", "Furniture; bedding, mattresses, cushions; luminaires and lighting fittings; prefab buildings"),
|
|
127
|
+
"95": ("XX", "Toys, games and sports requisites; parts and accessories thereof"),
|
|
128
|
+
"96": ("XX", "Miscellaneous manufactured articles"),
|
|
129
|
+
"97": ("XXI", "Works of art, collectors' pieces and antiques"),
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
_LEVEL_MAP = {
|
|
133
|
+
2: "HS-2 (Chapter)",
|
|
134
|
+
4: "HS-4 (Heading)",
|
|
135
|
+
6: "HS-6 (International Harmonized System Subheading)",
|
|
136
|
+
8: "CN-8 (EU Combined Nomenclature / National Tariff)",
|
|
137
|
+
10: "HTS-10 / TARIC-10 (National Statistical / Duty Code)",
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def format_hs_code(code: str) -> str:
|
|
142
|
+
d = re.sub(r"\D+", "", str(code or ""))
|
|
143
|
+
if len(d) <= 4:
|
|
144
|
+
return d
|
|
145
|
+
if len(d) <= 6:
|
|
146
|
+
return f"{d[:4]}.{d[4:]}"
|
|
147
|
+
if len(d) <= 8:
|
|
148
|
+
return f"{d[:4]}.{d[4:6]}.{d[6:]}"
|
|
149
|
+
return f"{d[:4]}.{d[4:6]}.{d[6:8]}.{d[8:]}"
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def parse_hs_code(code: str) -> Dict[str, Any]:
|
|
153
|
+
raw = str(code or "").strip()
|
|
154
|
+
digits = re.sub(r"[\s.\-]+", "", raw)
|
|
155
|
+
if not digits.isdigit() or len(digits) not in (2, 4, 6, 8, 10):
|
|
156
|
+
return {
|
|
157
|
+
"raw": raw,
|
|
158
|
+
"digits": digits,
|
|
159
|
+
"valid": False,
|
|
160
|
+
"error": "HS/CN/HTS code must contain 2, 4, 6, 8, or 10 digits.",
|
|
161
|
+
}
|
|
162
|
+
ch = digits[:2]
|
|
163
|
+
if ch not in CHAPTERS:
|
|
164
|
+
return {
|
|
165
|
+
"raw": raw,
|
|
166
|
+
"digits": digits,
|
|
167
|
+
"valid": False,
|
|
168
|
+
"error": f"Unknown HS chapter '{ch}' (valid: 01-97, excluding reserved 77).",
|
|
169
|
+
}
|
|
170
|
+
sec, ch_title = CHAPTERS[ch]
|
|
171
|
+
return {
|
|
172
|
+
"raw": raw,
|
|
173
|
+
"digits": digits,
|
|
174
|
+
"formatted": format_hs_code(digits),
|
|
175
|
+
"valid": True,
|
|
176
|
+
"level": _LEVEL_MAP[len(digits)],
|
|
177
|
+
"chapter": ch,
|
|
178
|
+
"chapter_title": ch_title,
|
|
179
|
+
"section": sec,
|
|
180
|
+
"section_title": SECTIONS[sec],
|
|
181
|
+
"heading": digits[:4] if len(digits) >= 4 else None,
|
|
182
|
+
"subheading": digits[:6] if len(digits) >= 6 else None,
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def is_valid_hs_code(code: str) -> bool:
|
|
187
|
+
return bool(parse_hs_code(code).get("valid"))
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def search_chapters(query: str, limit: int = 10) -> List[Dict[str, str]]:
|
|
191
|
+
tokens = [t for t in re.findall(r"[a-z0-9]+", (query or "").lower()) if len(t) >= 2]
|
|
192
|
+
if not tokens:
|
|
193
|
+
return []
|
|
194
|
+
scored = []
|
|
195
|
+
for ch, (sec, title) in CHAPTERS.items():
|
|
196
|
+
hay = f"{title} {SECTIONS[sec]}".lower()
|
|
197
|
+
hits = sum(1 for t in tokens if t in hay)
|
|
198
|
+
if hits:
|
|
199
|
+
scored.append((hits, ch, sec, title))
|
|
200
|
+
scored.sort(key=lambda x: (-x[0], x[1]))
|
|
201
|
+
return [
|
|
202
|
+
{"chapter": ch, "title": title, "section": sec, "section_title": SECTIONS[sec]}
|
|
203
|
+
for _, ch, sec, title in scored[:limit]
|
|
204
|
+
]
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
__all__ = ["parse_hs_code", "is_valid_hs_code", "format_hs_code", "search_chapters", "CHAPTERS", "SECTIONS"]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""CLI entry point for hs-code-tariff."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
from . import parse_hs_code, search_chapters
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main(argv=None) -> int:
|
|
11
|
+
ap = argparse.ArgumentParser(description="Offline HS 2022 code validator, classifier & chapter search.")
|
|
12
|
+
ap.add_argument("codes", nargs="*", help="One or more HS/CN/HTS codes (e.g. 2204.21 8517.13.00)")
|
|
13
|
+
ap.add_argument("--search", "-s", help="Search HS 2022 chapters by product keyword")
|
|
14
|
+
ap.add_argument("--json", action="store_true", help="Output JSON")
|
|
15
|
+
args = ap.parse_args(argv)
|
|
16
|
+
|
|
17
|
+
if args.search:
|
|
18
|
+
res = search_chapters(args.search)
|
|
19
|
+
if args.json:
|
|
20
|
+
print(json.dumps(res, indent=2))
|
|
21
|
+
else:
|
|
22
|
+
for r in res:
|
|
23
|
+
print(f"Ch {r['chapter']} (Sec {r['section']}): {r['title']}")
|
|
24
|
+
return 0 if res else 1
|
|
25
|
+
|
|
26
|
+
if not args.codes:
|
|
27
|
+
ap.print_help()
|
|
28
|
+
return 2
|
|
29
|
+
|
|
30
|
+
results = [parse_hs_code(c) for c in args.codes]
|
|
31
|
+
if args.json:
|
|
32
|
+
print(json.dumps(results if len(results) > 1 else results[0], indent=2))
|
|
33
|
+
else:
|
|
34
|
+
for r in results:
|
|
35
|
+
if not r.get("valid"):
|
|
36
|
+
print(f"{r['raw']}: INVALID ({r.get('error')})")
|
|
37
|
+
else:
|
|
38
|
+
print(f"{r['formatted']} | {r['level']} | Ch {r['chapter']}: {r['chapter_title']} (Sec {r['section']})")
|
|
39
|
+
return 0 if all(r.get("valid") for r in results) else 1
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
sys.exit(main())
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hs-code-tariff
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Zero-dependency offline Harmonized System (HS 2022) 97-chapter & 21-section classifier, HS/CN/HTS code validator, normalizer, and keyword search CLI.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://radarbg.com/tools/hs-code-lookup?ref=pypi-hscode
|
|
7
|
+
Project-URL: Free Online HS Code Lookup, https://radarbg.com/tools/hs-code-lookup?ref=pypi-hscode
|
|
8
|
+
Project-URL: HS Code Tariff REST API, https://radarbg.com/apis/hs-code-tariff-lookup?ref=pypi-hscode
|
|
9
|
+
Keywords: hs-code,tariff,customs,harmonized-system,hts,cn-code,ecommerce,trade,logistics,cli
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Office/Business
|
|
14
|
+
Requires-Python: >=3.8
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# hs-code-tariff
|
|
20
|
+
|
|
21
|
+
Zero-dependency offline **Harmonized System (HS 2022)** code validator, normalizer, 97-chapter & 21-section classifier, and keyword search utility for Python.
|
|
22
|
+
|
|
23
|
+
Need **full 6/8/10-digit commodity descriptions, EU TARIC / US HTS duty rates, or natural-language product classification**?
|
|
24
|
+
- Free browser lookup (no sign-up): [radarbg.com/tools/hs-code-lookup](https://radarbg.com/tools/hs-code-lookup?ref=pypi-hscode)
|
|
25
|
+
- REST API (JSON, full HS/HTS/tariff search): [radarbg.com/apis/hs-code-tariff-lookup](https://radarbg.com/apis/hs-code-tariff-lookup?ref=pypi-hscode)
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install hs-code-tariff
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from hs_code_tariff import parse_hs_code, search_chapters
|
|
37
|
+
|
|
38
|
+
info = parse_hs_code("2204.21.00")
|
|
39
|
+
print(info)
|
|
40
|
+
# {
|
|
41
|
+
# 'raw': '2204.21.00',
|
|
42
|
+
# 'digits': '22042100',
|
|
43
|
+
# 'formatted': '2204.21.00',
|
|
44
|
+
# 'valid': True,
|
|
45
|
+
# 'level': 'CN-8 (EU Combined Nomenclature)',
|
|
46
|
+
# 'chapter': '22',
|
|
47
|
+
# 'chapter_title': 'Beverages, spirits and vinegar',
|
|
48
|
+
# 'section': 'IV',
|
|
49
|
+
# 'section_title': 'Prepared Foodstuffs; Beverages, Spirits and Vinegar; Tobacco',
|
|
50
|
+
# 'heading': '2204',
|
|
51
|
+
# 'subheading': '220421'
|
|
52
|
+
# }
|
|
53
|
+
|
|
54
|
+
hits = search_chapters("coffee")
|
|
55
|
+
# [{'chapter': '09', 'title': 'Coffee, tea, maté and spices', 'section': 'II', ...}]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## CLI
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
hs-code-tariff 8517.13
|
|
62
|
+
hs-code-tariff --search "lithium battery"
|
|
63
|
+
hs-code-tariff --json 2204.21 6109.10
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/hs_code_tariff/__init__.py
|
|
5
|
+
src/hs_code_tariff/__main__.py
|
|
6
|
+
src/hs_code_tariff.egg-info/PKG-INFO
|
|
7
|
+
src/hs_code_tariff.egg-info/SOURCES.txt
|
|
8
|
+
src/hs_code_tariff.egg-info/dependency_links.txt
|
|
9
|
+
src/hs_code_tariff.egg-info/entry_points.txt
|
|
10
|
+
src/hs_code_tariff.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hs_code_tariff
|