ustrade 0.4.0__py3-none-any.whl

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.
ustrade/errors.py ADDED
@@ -0,0 +1,47 @@
1
+
2
+
3
+
4
+ class USTradeError(Exception):
5
+ """
6
+ Base error for the library
7
+ """
8
+
9
+ class APITimeOutError(USTradeError):
10
+ pass
11
+
12
+
13
+ ##### Data search error ##################################################
14
+
15
+ class EmptyResult(USTradeError):
16
+ """
17
+ Could not find any data for the specified query
18
+ """
19
+ pass
20
+
21
+
22
+
23
+
24
+
25
+ ####### countries error ##################################################
26
+
27
+ class InvalidCountryError(USTradeError):
28
+ """
29
+ Country is not referenced
30
+ """
31
+ pass
32
+
33
+ ####### codes error ##################################################
34
+
35
+ class InvalidCodeError(USTradeError):
36
+ """
37
+ Argument of function is not of a valid type
38
+ """
39
+ pass
40
+
41
+ class CodeNotFoundError(USTradeError):
42
+ """
43
+ Could not find the reference to this code in the base
44
+ """
45
+ pass
46
+
47
+
@@ -0,0 +1,189 @@
1
+ Metadata-Version: 2.4
2
+ Name: ustrade
3
+ Version: 0.4.0
4
+ Summary: Python client for the U.S. Census Bureau International Trade API
5
+ Author: Fantin Sibony
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/fantinsib/ustrade
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE.txt
11
+ Requires-Dist: requests
12
+ Requires-Dist: pandas
13
+ Dynamic: license-file
14
+
15
+ # ustrade
16
+
17
+ > A lightweight and intuitive Python client for the **U.S. Census Bureau International Trade API**.
18
+ > Allows to fetch imports and exports between the US and commercial partners - based on Harmonized System codes (HS)
19
+
20
+ <p align="left">
21
+ <img src="https://img.shields.io/badge/python-3.10%2B-blue" />
22
+ <img src="https://img.shields.io/badge/status-active-success" />
23
+ <img src="https://img.shields.io/badge/license-MIT-green" />
24
+ </p>
25
+
26
+ ---
27
+
28
+ ## Features
29
+
30
+ - **Simple API**: `ust.get_imports()`, `ust.get_exports()`
31
+ - Automatic normalization of country inputs:
32
+ - `"France"`
33
+ - `"FR"` (ISO2)
34
+ - `"4279"` (Census code)
35
+ - HS codes lookup + product descriptions
36
+ - Standardized DataFrame output with clean column names
37
+ - Uses a cached internal client for efficiency
38
+ - Zero configuration required
39
+
40
+ ---
41
+
42
+ ## Installation
43
+
44
+ ### PyPI Install
45
+
46
+ Install with pip :
47
+
48
+ ```bash
49
+ pip install ustrade
50
+ ```
51
+
52
+ ### Github
53
+ Clone this repository and install via pip in editable mode:
54
+
55
+ ```bash
56
+ git clone https://github.com/fantinsib/ustrade.git
57
+ cd ustrade
58
+ pip install -e .
59
+ ```
60
+ ## Quick Example
61
+
62
+ ```python
63
+
64
+ import ustrade as ust
65
+
66
+ # Example: Mexican imports of fruits and nuts between January 2010 and January 2025
67
+ df = ust.get_imports_on_period("Mexico", "08", "2010-01", "2025-01")
68
+ print(df)
69
+ ```
70
+
71
+ ## Full API Reference
72
+
73
+ ## *Fetching Data*
74
+
75
+ ### • `get_imports(country, product, date)`
76
+ Fetch monthly import data for a given country and HS code.
77
+
78
+ **Parameters:**
79
+ - `country` — country name (`France`), ISO2 (`FR`), Census code (`4279`) or `Country` instance, or a list of the previous
80
+ - `product` — HS code as string (e.g. `2701`) or list of string
81
+ - `date` — `YYYY-MM` format (e.g. `2020-01`)
82
+
83
+ **Example:**
84
+ ```python
85
+ ust.get_imports("FR", "10", "2025-01")
86
+ ust.get_imports(["France", "GB"], ["12", "13"], "2018-03")
87
+ ```
88
+
89
+ ---
90
+
91
+ ### • `get_exports(country, product, date)`
92
+ Fetch monthly export data for a given country and HS code.
93
+
94
+ **Example:**
95
+ ```python
96
+ ust.get_exports("GB", "73", "2019-01")
97
+ ust.get_exports(["France", "GB"], ["08", "09"], "2018-03")
98
+ ```
99
+
100
+ ---
101
+
102
+ ### • `get_imports_on_period(country, product, start, end)`
103
+ Fetch a DataFrame containing monthly imports for a given country and HS code
104
+
105
+ **Parameters:**
106
+ - `country` — country name (`France`), ISO2 (`FR`), Census code (`4279`) or `Country` instance, or list of the previous
107
+ - `product` — HS code as string (e.g. `2701`) or list of string
108
+ - `start` and `end` — `YYYY-MM` format (e.g. `2020-01`)
109
+
110
+ **Example:**
111
+ ```python
112
+ ust.get_imports_on_period("Mexico", "27", "2010-01", "2025-01")
113
+ ust.get_imports_on_period(["France", "DE", "GB"], ["09", "08", "07"], "2016-01", "2018-01")
114
+ ```
115
+
116
+ ---
117
+
118
+ ### • `get_exports_on_period(country, product, start, end)`
119
+ Fetch a DataFrame containing monthly exports for a given country and HS code
120
+
121
+ **Example:**
122
+ ```python
123
+ ust.get_exports_on_period("France", "10", "2020-01", "2023-01")
124
+ ```
125
+
126
+ ---
127
+
128
+ ## *Exploring Codes*
129
+
130
+ HS Codes follow a tree hierarchy.
131
+
132
+ ### • `get_desc_from_code(hs)`
133
+ Return the description associated with an HS code.
134
+
135
+ **Example:**
136
+ ```python
137
+ ust.get_desc_from_code("2701")
138
+ ```
139
+
140
+ ### • `get_children_codes(code, return_names)`
141
+ Return a dictionnary of the codes and descriptions attached to the parent code if return_names is True, and a list of the code if return_names if False.
142
+
143
+ **Example:**
144
+ ```python
145
+ ust.get_children_codes("10")
146
+ ```
147
+
148
+
149
+ ### • `get_product(hs)`
150
+ Return the HSCode instance associated with the hs code specified.
151
+
152
+ **Example:**
153
+ ```python
154
+ ust.get_product("10")
155
+ ```
156
+
157
+ ## *Exploring countries*
158
+
159
+ ### • `get_country_by_name(name)`
160
+ Look up a country by its full name (case-insensitive).
161
+
162
+ **Example:**
163
+ ```python
164
+ ust.get_country_by_name("France")
165
+ ```
166
+
167
+ ### • `get_country_by_code(code)`
168
+ Look up a country using its U.S. Census numeric code.
169
+
170
+ **Example:**
171
+ ```python
172
+ ust.get_country_by_code("4279")
173
+ ```
174
+
175
+ ### • `get_country_by_iso2(iso)`
176
+ Look up a country by ISO2 code.
177
+
178
+ **Example:**
179
+ ```python
180
+ ust.get_country_by_iso2("FR")
181
+ ```
182
+
183
+ ---
184
+
185
+ ## 🧩 Notes
186
+
187
+ - All data retrieval functions return a **pandas DataFrame** unless otherwise noted.
188
+ - Column names are automatically standardized (see schema section).
189
+ - This library is still in <1.0.0 version and can change. Contributions are always welcome !
@@ -0,0 +1,12 @@
1
+ ustrade/__init__.py,sha256=uOIWAm1QLJKPm0ajouB4t_NNh822k3g3xc8M6AITma0,5968
2
+ ustrade/client.py,sha256=txGvXKFSC88T74HmBd5Q9b9L-7Bvh_eu1sEX3SWB16k,16611
3
+ ustrade/codes.py,sha256=-4f54TUF9Dq93PYuzJli6d5HyGlWWmYlHqngb1GJe40,1900
4
+ ustrade/countries.py,sha256=8CagTTccgs_Obr3dSpTffPKcikVe7eUdObcer-azIbU,783
5
+ ustrade/errors.py,sha256=AIKPwwb1fUmtvZkwqNpVAXevwD5jSz2NN8_iYzpM1Dk,802
6
+ ustrade/data/country_codes.csv,sha256=xwpr9MmBsIB78lIiKGDCaWDbGaO1kyDz0Vxwcxu1TTU,5794
7
+ ustrade/data/harmonized-system.csv,sha256=537p4c_RWkLR-t6ywGGNEPa57ZrsDl1mgm3H750xJqU,850576
8
+ ustrade-0.4.0.dist-info/licenses/LICENSE.txt,sha256=dwk5PMNyALOsBcKsVyrMjtoD0LvXr-Lu61cMjFJJn7I,1066
9
+ ustrade-0.4.0.dist-info/METADATA,sha256=IhiWRMtf6vFlsmD88cITFl1F0f5HE_OmlZ4vGalWbsA,4602
10
+ ustrade-0.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ ustrade-0.4.0.dist-info/top_level.txt,sha256=sGFKm5WBJQE8rpKswtEFbRvBNzrON1Dr5UCdQptW2GE,8
12
+ ustrade-0.4.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 fantinsib
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 @@
1
+ ustrade