xippios-usda-esr 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.
- xippios_usda_esr-0.1.0/.gitignore +23 -0
- xippios_usda_esr-0.1.0/CHANGELOG.md +75 -0
- xippios_usda_esr-0.1.0/LICENSE +201 -0
- xippios_usda_esr-0.1.0/PKG-INFO +161 -0
- xippios_usda_esr-0.1.0/README.md +132 -0
- xippios_usda_esr-0.1.0/docs/upstream/FETCHED.md +78 -0
- xippios_usda_esr-0.1.0/docs/upstream/openapi/backend-docs-v1.json +236 -0
- xippios_usda_esr-0.1.0/docs/upstream/openapi/portal-document.json +240 -0
- xippios_usda_esr-0.1.0/pyproject.toml +102 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/__init__.py +32 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/_client.py +244 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/_version.py +10 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/api/ESRData_GetAllCountriesData.py +44 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/api/ESRData_GetCommodities.py +30 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/api/ESRData_GetCountries.py +31 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/api/ESRData_GetCountryData.py +50 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/api/ESRData_GetDataReleaseInfo.py +33 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/api/ESRData_GetRegions.py +31 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/api/ESRData_GetUnitsOfMeasure.py +32 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/api/__init__.py +28 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/enums.py +25 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/errors.py +78 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/http.py +16 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/mcp.py +30 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/models.py +232 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/params.py +259 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/py.typed +0 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/reference/README.md +57 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/reference/commodities.json +227 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/reference/countries.json +1484 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/reference/regions.json +55 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/reference/unitsOfMeasure.json +27 -0
- xippios_usda_esr-0.1.0/src/xippios/usda/esr/tasks.py +602 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# environments and caches
|
|
2
|
+
.venv/
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[cod]
|
|
5
|
+
.mypy_cache/
|
|
6
|
+
.ruff_cache/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
.hypothesis/
|
|
9
|
+
|
|
10
|
+
# build artefacts
|
|
11
|
+
dist/
|
|
12
|
+
build/
|
|
13
|
+
*.egg-info/
|
|
14
|
+
|
|
15
|
+
# local secrets are never files, but belt and braces
|
|
16
|
+
.env
|
|
17
|
+
.env.*
|
|
18
|
+
.envrc
|
|
19
|
+
.envrc.*
|
|
20
|
+
|
|
21
|
+
# editors
|
|
22
|
+
.idea/
|
|
23
|
+
.vscode/
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/) (pre-1.0: breaking changes bump the minor).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-10-26
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Scaffold from [sdk-template](https://github.com/xippios/sdk-template) v0.2.0: configured
|
|
14
|
+
client for USDA FAS Export Sales Reporting, MCP server and FastAPI router wired to the
|
|
15
|
+
task layer, test harness, CI, the nightly live tests and publishing.
|
|
16
|
+
- Upstream documentation snapshot of 2026-10-25 in `docs/upstream/`: the ESR part (seven
|
|
17
|
+
`/api/esr/` operations) of the FAS Open Data Services portal's Swagger 2.0 document and
|
|
18
|
+
of the API's own Swashbuckle document, with `FETCHED.md`; written by
|
|
19
|
+
`scripts/refresh_upstream.py` (standard library only, no key), which also records the
|
|
20
|
+
portal and Swagger UI shells, the ESR program page (403 to headless clients) and the
|
|
21
|
+
ESR query URLs (404) without files.
|
|
22
|
+
- `get_exports(commodity_code, market_year, country_code=None)`, MCP tool
|
|
23
|
+
`usda_esr_get_exports`: US weekly export sales of one commodity in one ESR market year,
|
|
24
|
+
to one destination (`ESRData_GetCountryData`) or to every one (`ESRData_GetAllCountriesData`),
|
|
25
|
+
one `CommodityData` record per destination and week with `Decimal` quantities and
|
|
26
|
+
`week_ending_date` as a date. Codes are integers, checked against the packaged lists
|
|
27
|
+
before any call (`errors.UnknownCode`, naming the closest codes, since ESR answers an
|
|
28
|
+
unknown code with an empty list); market years after the current UTC year plus two are
|
|
29
|
+
refused (ESR answers them with an empty list), and ESR's empty 404 for a market year it
|
|
30
|
+
lacks is `errors.NoDataForYear`, a `NotFoundError`. `meta.vintage` is the latest week
|
|
31
|
+
ending date in the answer; `meta.published_at` stays `None`. Over MCP a cut answer's
|
|
32
|
+
note names `country_code` (`tasks.MCP_CAPS`).
|
|
33
|
+
- `get_latest_week(commodity_code, market_year)`,
|
|
34
|
+
`get_top_destinations(commodity_code, market_year, field, n=10)` and
|
|
35
|
+
`get_weekly_series(commodity_code, country_code, market_year)`, MCP tools
|
|
36
|
+
`usda_esr_get_latest_week`, `usda_esr_get_top_destinations` and
|
|
37
|
+
`usda_esr_get_weekly_series`: the slices, each one upstream request
|
|
38
|
+
(`ESRData_GetAllCountriesData` for the first two, `ESRData_GetCountryData` for the
|
|
39
|
+
series) whose records are only selected and ordered: the newest week's records, one per
|
|
40
|
+
destination; those sorted by one quantity, largest first, ties in upstream order, the
|
|
41
|
+
first `n`; one destination's weeks, oldest first. Nothing is excluded. `meta.vintage` is
|
|
42
|
+
the latest week among the records considered, `meta.published_at` `None`; an empty
|
|
43
|
+
answer is an empty result. `field` is a `models.ExportField`, a `StrEnum` of the
|
|
44
|
+
record's eight quantities by their upstream names, which the MCP and HTTP schemas list.
|
|
45
|
+
- `get_release_dates()`, MCP tool `usda_esr_get_release_dates`: when ESR last released each
|
|
46
|
+
commodity's export data, with its current market year (`ESRData_GetDataReleaseInfo`);
|
|
47
|
+
`meta.vintage` is the latest release time stamp's text (`"2026-10-22T08:30:42.670000"`,
|
|
48
|
+
`isoformat()` of upstream's `2026-10-22T08:30:42.67`), `meta.published_at` `None` since
|
|
49
|
+
the documentation states no time zone for `releaseTimeStamp`.
|
|
50
|
+
- `list_commodities(search=None)`, `list_countries(region_id=None, search=None)`,
|
|
51
|
+
`list_regions()` and `list_units_of_measure()`, MCP tools `usda_esr_list_commodities`,
|
|
52
|
+
`usda_esr_list_countries`, `usda_esr_list_regions` and `usda_esr_list_units_of_measure`:
|
|
53
|
+
ESR's four code lists, answered from the packaged files without an upstream call, in
|
|
54
|
+
upstream order with upstream's names and padding. `meta.endpoint` is the operation the
|
|
55
|
+
list came from, `meta.vintage` the day the package fetched it, `meta.retrieved_at` when
|
|
56
|
+
the task answered; `meta.total` stays `None`. `search` is a case-insensitive substring
|
|
57
|
+
match on the code (as digits) and the name, for countries also the description and the
|
|
58
|
+
GENC code; `region_id` selects the countries of one region exactly. Over MCP
|
|
59
|
+
`usda_esr_list_countries` has a cap of its own, 250 rows, so all 211 countries arrive,
|
|
60
|
+
and its note names `region_id` and `search`; `usda_esr_list_commodities`' note names
|
|
61
|
+
`search` (`tasks.MCP_CAPS`).
|
|
62
|
+
- Endpoint wrappers for the seven ESR operations under `api/`, named after the snapshot's
|
|
63
|
+
operationIds, and their models, built from the recorded answers.
|
|
64
|
+
- The configured client for api.data.gov's gateway: the `X-Api-Key` header from
|
|
65
|
+
`DATA_GOV_API_KEY`, the self-imposed pace of 60 requests per minute, core's
|
|
66
|
+
`QuotaPolicy` on the gateway's hourly quota of 1,000 requests per key shared with
|
|
67
|
+
xippios-usda-psd and xippios-usda-gats, and `classify` for the gateway's `API_KEY_*`,
|
|
68
|
+
`OVER_RATE_LIMIT` and `NOT_FOUND` answers and ESR's own 404 and 400.
|
|
69
|
+
- Packaged reference data in `reference/` (44 commodities, 211 countries, 12 regions, 5
|
|
70
|
+
units, fetched 2026-10-25) written by `scripts/refresh_reference.py`, which also renders
|
|
71
|
+
the `IntEnum` `enums.UnitId`.
|
|
72
|
+
- `scripts/check-siblings.sh` and its workflow `siblings.yml`, a check of its own that the
|
|
73
|
+
org ruleset does not require: this wheel installs with xippios-usda-psd and
|
|
74
|
+
xippios-usda-nass, both from PyPI, as portions of the `xippios.usda` namespace
|
|
75
|
+
(ADR-0006); `PSD_REQUIREMENT` and `NASS_REQUIREMENT` override either.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: xippios-usda-esr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed client, MCP tools and HTTP routes for USDA FAS Export Sales Reporting
|
|
5
|
+
Project-URL: Homepage, https://github.com/xippios/sdk-usda-esr
|
|
6
|
+
Project-URL: Upstream, https://www.fas.usda.gov/programs/export-sales-reporting-program
|
|
7
|
+
Project-URL: Changelog, https://github.com/xippios/sdk-usda-esr/blob/main/CHANGELOG.md
|
|
8
|
+
Project-URL: Issues, https://github.com/xippios/sdk-usda-esr/issues
|
|
9
|
+
Author: XIPPIOS GmbH
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agriculture,httpx,mcp,pydantic,sdk,usda-esr
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.12
|
|
21
|
+
Requires-Dist: xippios-core~=0.2.0
|
|
22
|
+
Provides-Extra: http
|
|
23
|
+
Requires-Dist: xippios-core[http]~=0.2.0; extra == 'http'
|
|
24
|
+
Provides-Extra: mcp
|
|
25
|
+
Requires-Dist: xippios-core[mcp]~=0.2.0; extra == 'mcp'
|
|
26
|
+
Provides-Extra: testing
|
|
27
|
+
Requires-Dist: xippios-core[testing]~=0.2.0; extra == 'testing'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# xippios-usda-esr
|
|
31
|
+
|
|
32
|
+
Typed Python client, MCP server and FastAPI routes for
|
|
33
|
+
[USDA FAS Export Sales Reporting](https://www.fas.usda.gov/programs/export-sales-reporting-program), part of the
|
|
34
|
+
[xippios SDK family](https://github.com/xippios). Names and semantics follow the
|
|
35
|
+
upstream documentation; every response carries release metadata (source, endpoint,
|
|
36
|
+
retrieved_at, published_at, vintage).
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
uv add xippios-usda-esr # client only
|
|
42
|
+
uv add "xippios-usda-esr[mcp]" # + MCP server
|
|
43
|
+
uv add "xippios-usda-esr[http]" # + FastAPI router
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Set `DATA_GOV_API_KEY` in the environment. Nothing is read from files.
|
|
47
|
+
|
|
48
|
+
## 30-second example
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from xippios.usda.esr import get_exports, get_release_dates
|
|
52
|
+
|
|
53
|
+
result = get_exports(104, 2024, 1220) # wheat white, market year 2024, to Canada
|
|
54
|
+
week = result.data[-1]
|
|
55
|
+
week.week_ending_date, week.accumulated_exports, week.unit_id # 2024-06-06, Decimal('16217'), 1
|
|
56
|
+
result.meta.vintage # "2024-06-06": the latest week ending date in the answer
|
|
57
|
+
result.meta.published_at # None: get_release_dates tells when ESR released the data
|
|
58
|
+
result.meta.retrieved_at, result.meta.request
|
|
59
|
+
|
|
60
|
+
releases = get_release_dates() # one record per commodity, no parameters
|
|
61
|
+
wheat = next(r for r in releases.data if r.commodity_code == 104)
|
|
62
|
+
wheat.market_year, wheat.market_year_start, wheat.release_time_stamp # 2027, 2026-06-01, ...
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Codes are ESR's own integers (commodity `104` wheat white, `401` corn, `801` soybeans;
|
|
66
|
+
country `1220` Canada, `2010` Mexico, `5880` Japan), checked against the lists packaged
|
|
67
|
+
in `reference/` before any call: ESR answers an unknown code with an empty list, so the
|
|
68
|
+
package refuses it and names the closest codes. A market year is ESR's, named by the year
|
|
69
|
+
it ends in and different per commodity (wheat 2024 is June 2023 to May 2024; corn and
|
|
70
|
+
soybeans run September to August, cotton August to July). Leave out the country for every
|
|
71
|
+
destination at once, one row per destination and week; the MCP server returns at most
|
|
72
|
+
200 rows per call, so pass a country there. Quantities are `Decimal` in Python and JSON
|
|
73
|
+
numbers over MCP and HTTP, in the unit `unit_id` names (`enums.UnitId`).
|
|
74
|
+
|
|
75
|
+
The slices each make the one request `get_exports` makes and only select and order its
|
|
76
|
+
records; nothing is excluded, so `9990` UNKNOWN ranks like a country when ESR sends it:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from xippios.usda.esr import get_latest_week, get_top_destinations, get_weekly_series
|
|
80
|
+
from xippios.usda.esr.models import ExportField
|
|
81
|
+
|
|
82
|
+
week = get_latest_week(1201, 2024) # cottonseed: the newest week, one row per destination
|
|
83
|
+
len(week.data), week.meta.vintage # 11, "2024-08-01"
|
|
84
|
+
top = get_top_destinations(1201, 2024, ExportField.OUTSTANDING_SALES, n=3)
|
|
85
|
+
[r.country_code for r in top.data] # [5800, 5880, 5230], largest first, ties in upstream order
|
|
86
|
+
series = get_weekly_series(104, 1220, 2024) # wheat white to Canada, oldest week first
|
|
87
|
+
len(series.data), series.meta.vintage # 54, "2024-06-06"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`field` takes upstream's names of the eight quantities (`"outstandingSales"`,
|
|
91
|
+
`"accumulatedExports"`, ...; `models.ExportField`), which the MCP and HTTP schemas list.
|
|
92
|
+
|
|
93
|
+
The `list_*` tasks look codes up in the packaged lists, without a call:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from xippios.usda.esr import list_commodities, list_countries
|
|
97
|
+
|
|
98
|
+
result = list_countries(region_id=11) # ESR's region WESTERN HEMISPHERE (list_regions)
|
|
99
|
+
[c.country_code for c in result.data][:3] # [1010, 1220, 1610], 40 in upstream order
|
|
100
|
+
result.meta.endpoint, result.meta.vintage # "ESRData_GetCountries", "2026-10-25" (fetched)
|
|
101
|
+
list_countries(search="united").data # 4120, 5200, 7830: code, name, description or GENC code
|
|
102
|
+
list_countries(search="deu").data # 4280 GERMANY, by its GENC code "DEU"
|
|
103
|
+
list_commodities(search="wheat").data # 101 to 107 and 201 Wheat Products
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
`meta.vintage` of a list is the day the package fetched it (upstream gives these lists no
|
|
107
|
+
version), `meta.retrieved_at` when the task answered. Names are upstream's, padding
|
|
108
|
+
included: `country_name` is `"CANADA "`. The list tasks spend no request of the
|
|
109
|
+
api.data.gov quota.
|
|
110
|
+
|
|
111
|
+
## MCP
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"mcpServers": {
|
|
116
|
+
"usda-esr": {
|
|
117
|
+
"command": "uvx",
|
|
118
|
+
"args": ["--from", "xippios-usda-esr[mcp]", "xippios-usda-esr-mcp"],
|
|
119
|
+
"env": { "DATA_GOV_API_KEY": "..." }
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Tools are read-only and named `usda_esr_<verb>_<noun>`. Results are capped, at
|
|
126
|
+
200 rows or 64 KB unless a tool has a cap of its own, with a note on how to see the rest;
|
|
127
|
+
`usda_esr_list_countries` has a cap of its own, 250 rows, so all 211 countries arrive.
|
|
128
|
+
`--http` serves streamable HTTP instead of stdio.
|
|
129
|
+
|
|
130
|
+
## Status
|
|
131
|
+
|
|
132
|
+
| Upstream operation | Task function | MCP tool | Status |
|
|
133
|
+
| --- | --- | --- | --- |
|
|
134
|
+
| `ESRData_GetCountryData` (`exports/commodityCode/{commodityCode}/countryCode/{countryCode}/marketYear/{marketYear}`) | `get_exports(commodity_code, market_year, country_code)` | `usda_esr_get_exports` | alpha |
|
|
135
|
+
| `ESRData_GetAllCountriesData` (`exports/commodityCode/{commodityCode}/allCountries/marketYear/{marketYear}`) | `get_exports(commodity_code, market_year)` | `usda_esr_get_exports` | alpha |
|
|
136
|
+
| `ESRData_GetAllCountriesData` | `get_latest_week(commodity_code, market_year)` | `usda_esr_get_latest_week` | alpha; slice |
|
|
137
|
+
| `ESRData_GetAllCountriesData` | `get_top_destinations(commodity_code, market_year, field, n=10)` | `usda_esr_get_top_destinations` | alpha; slice |
|
|
138
|
+
| `ESRData_GetCountryData` | `get_weekly_series(commodity_code, country_code, market_year)` | `usda_esr_get_weekly_series` | alpha; slice |
|
|
139
|
+
| `ESRData_GetDataReleaseInfo` (`datareleasedates`) | `get_release_dates()` | `usda_esr_get_release_dates` | alpha |
|
|
140
|
+
| `ESRData_GetCommodities` (`commodities`) | `list_commodities(search)` | `usda_esr_list_commodities` | packaged; `list_*` task |
|
|
141
|
+
| `ESRData_GetCountries` (`countries`) | `list_countries(region_id, search)` | `usda_esr_list_countries` | packaged; `list_*` task |
|
|
142
|
+
| `ESRData_GetRegions` (`regions`) | `list_regions()` | `usda_esr_list_regions` | packaged; `list_*` task |
|
|
143
|
+
| `ESRData_GetUnitsOfMeasure` (`unitsOfMeasure`) | `list_units_of_measure()` | `usda_esr_list_units_of_measure` | packaged, `enums.UnitId`; `list_*` task |
|
|
144
|
+
|
|
145
|
+
All nine tasks are covered in 0.1.0, the first release. Alpha: the public surface may
|
|
146
|
+
change in a minor version before 1.0 (conventions §12); `CHANGELOG.md` lists every change.
|
|
147
|
+
|
|
148
|
+
Every request counts against api.data.gov's quota of 1,000 requests per hour per key,
|
|
149
|
+
shared by every package using the same `DATA_GOV_API_KEY`; the `list_*` tasks spend none.
|
|
150
|
+
The client keeps its own pace of one request per second; once the quota is spent it waits
|
|
151
|
+
for the quota to come back when that takes at most 30 s, and otherwise raises
|
|
152
|
+
`RateLimitError` with `retry_after` instead of sending.
|
|
153
|
+
|
|
154
|
+
## Upstream terms and attribution
|
|
155
|
+
|
|
156
|
+
Data comes from USDA FAS Export Sales Reporting (https://www.fas.usda.gov/programs/export-sales-reporting-program) under its own terms of use;
|
|
157
|
+
this package adds no rights to it. Documentation snapshot: `docs/upstream/`.
|
|
158
|
+
|
|
159
|
+
## Licence
|
|
160
|
+
|
|
161
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# xippios-usda-esr
|
|
2
|
+
|
|
3
|
+
Typed Python client, MCP server and FastAPI routes for
|
|
4
|
+
[USDA FAS Export Sales Reporting](https://www.fas.usda.gov/programs/export-sales-reporting-program), part of the
|
|
5
|
+
[xippios SDK family](https://github.com/xippios). Names and semantics follow the
|
|
6
|
+
upstream documentation; every response carries release metadata (source, endpoint,
|
|
7
|
+
retrieved_at, published_at, vintage).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
uv add xippios-usda-esr # client only
|
|
13
|
+
uv add "xippios-usda-esr[mcp]" # + MCP server
|
|
14
|
+
uv add "xippios-usda-esr[http]" # + FastAPI router
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Set `DATA_GOV_API_KEY` in the environment. Nothing is read from files.
|
|
18
|
+
|
|
19
|
+
## 30-second example
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from xippios.usda.esr import get_exports, get_release_dates
|
|
23
|
+
|
|
24
|
+
result = get_exports(104, 2024, 1220) # wheat white, market year 2024, to Canada
|
|
25
|
+
week = result.data[-1]
|
|
26
|
+
week.week_ending_date, week.accumulated_exports, week.unit_id # 2024-06-06, Decimal('16217'), 1
|
|
27
|
+
result.meta.vintage # "2024-06-06": the latest week ending date in the answer
|
|
28
|
+
result.meta.published_at # None: get_release_dates tells when ESR released the data
|
|
29
|
+
result.meta.retrieved_at, result.meta.request
|
|
30
|
+
|
|
31
|
+
releases = get_release_dates() # one record per commodity, no parameters
|
|
32
|
+
wheat = next(r for r in releases.data if r.commodity_code == 104)
|
|
33
|
+
wheat.market_year, wheat.market_year_start, wheat.release_time_stamp # 2027, 2026-06-01, ...
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Codes are ESR's own integers (commodity `104` wheat white, `401` corn, `801` soybeans;
|
|
37
|
+
country `1220` Canada, `2010` Mexico, `5880` Japan), checked against the lists packaged
|
|
38
|
+
in `reference/` before any call: ESR answers an unknown code with an empty list, so the
|
|
39
|
+
package refuses it and names the closest codes. A market year is ESR's, named by the year
|
|
40
|
+
it ends in and different per commodity (wheat 2024 is June 2023 to May 2024; corn and
|
|
41
|
+
soybeans run September to August, cotton August to July). Leave out the country for every
|
|
42
|
+
destination at once, one row per destination and week; the MCP server returns at most
|
|
43
|
+
200 rows per call, so pass a country there. Quantities are `Decimal` in Python and JSON
|
|
44
|
+
numbers over MCP and HTTP, in the unit `unit_id` names (`enums.UnitId`).
|
|
45
|
+
|
|
46
|
+
The slices each make the one request `get_exports` makes and only select and order its
|
|
47
|
+
records; nothing is excluded, so `9990` UNKNOWN ranks like a country when ESR sends it:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from xippios.usda.esr import get_latest_week, get_top_destinations, get_weekly_series
|
|
51
|
+
from xippios.usda.esr.models import ExportField
|
|
52
|
+
|
|
53
|
+
week = get_latest_week(1201, 2024) # cottonseed: the newest week, one row per destination
|
|
54
|
+
len(week.data), week.meta.vintage # 11, "2024-08-01"
|
|
55
|
+
top = get_top_destinations(1201, 2024, ExportField.OUTSTANDING_SALES, n=3)
|
|
56
|
+
[r.country_code for r in top.data] # [5800, 5880, 5230], largest first, ties in upstream order
|
|
57
|
+
series = get_weekly_series(104, 1220, 2024) # wheat white to Canada, oldest week first
|
|
58
|
+
len(series.data), series.meta.vintage # 54, "2024-06-06"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`field` takes upstream's names of the eight quantities (`"outstandingSales"`,
|
|
62
|
+
`"accumulatedExports"`, ...; `models.ExportField`), which the MCP and HTTP schemas list.
|
|
63
|
+
|
|
64
|
+
The `list_*` tasks look codes up in the packaged lists, without a call:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from xippios.usda.esr import list_commodities, list_countries
|
|
68
|
+
|
|
69
|
+
result = list_countries(region_id=11) # ESR's region WESTERN HEMISPHERE (list_regions)
|
|
70
|
+
[c.country_code for c in result.data][:3] # [1010, 1220, 1610], 40 in upstream order
|
|
71
|
+
result.meta.endpoint, result.meta.vintage # "ESRData_GetCountries", "2026-10-25" (fetched)
|
|
72
|
+
list_countries(search="united").data # 4120, 5200, 7830: code, name, description or GENC code
|
|
73
|
+
list_countries(search="deu").data # 4280 GERMANY, by its GENC code "DEU"
|
|
74
|
+
list_commodities(search="wheat").data # 101 to 107 and 201 Wheat Products
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`meta.vintage` of a list is the day the package fetched it (upstream gives these lists no
|
|
78
|
+
version), `meta.retrieved_at` when the task answered. Names are upstream's, padding
|
|
79
|
+
included: `country_name` is `"CANADA "`. The list tasks spend no request of the
|
|
80
|
+
api.data.gov quota.
|
|
81
|
+
|
|
82
|
+
## MCP
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"mcpServers": {
|
|
87
|
+
"usda-esr": {
|
|
88
|
+
"command": "uvx",
|
|
89
|
+
"args": ["--from", "xippios-usda-esr[mcp]", "xippios-usda-esr-mcp"],
|
|
90
|
+
"env": { "DATA_GOV_API_KEY": "..." }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Tools are read-only and named `usda_esr_<verb>_<noun>`. Results are capped, at
|
|
97
|
+
200 rows or 64 KB unless a tool has a cap of its own, with a note on how to see the rest;
|
|
98
|
+
`usda_esr_list_countries` has a cap of its own, 250 rows, so all 211 countries arrive.
|
|
99
|
+
`--http` serves streamable HTTP instead of stdio.
|
|
100
|
+
|
|
101
|
+
## Status
|
|
102
|
+
|
|
103
|
+
| Upstream operation | Task function | MCP tool | Status |
|
|
104
|
+
| --- | --- | --- | --- |
|
|
105
|
+
| `ESRData_GetCountryData` (`exports/commodityCode/{commodityCode}/countryCode/{countryCode}/marketYear/{marketYear}`) | `get_exports(commodity_code, market_year, country_code)` | `usda_esr_get_exports` | alpha |
|
|
106
|
+
| `ESRData_GetAllCountriesData` (`exports/commodityCode/{commodityCode}/allCountries/marketYear/{marketYear}`) | `get_exports(commodity_code, market_year)` | `usda_esr_get_exports` | alpha |
|
|
107
|
+
| `ESRData_GetAllCountriesData` | `get_latest_week(commodity_code, market_year)` | `usda_esr_get_latest_week` | alpha; slice |
|
|
108
|
+
| `ESRData_GetAllCountriesData` | `get_top_destinations(commodity_code, market_year, field, n=10)` | `usda_esr_get_top_destinations` | alpha; slice |
|
|
109
|
+
| `ESRData_GetCountryData` | `get_weekly_series(commodity_code, country_code, market_year)` | `usda_esr_get_weekly_series` | alpha; slice |
|
|
110
|
+
| `ESRData_GetDataReleaseInfo` (`datareleasedates`) | `get_release_dates()` | `usda_esr_get_release_dates` | alpha |
|
|
111
|
+
| `ESRData_GetCommodities` (`commodities`) | `list_commodities(search)` | `usda_esr_list_commodities` | packaged; `list_*` task |
|
|
112
|
+
| `ESRData_GetCountries` (`countries`) | `list_countries(region_id, search)` | `usda_esr_list_countries` | packaged; `list_*` task |
|
|
113
|
+
| `ESRData_GetRegions` (`regions`) | `list_regions()` | `usda_esr_list_regions` | packaged; `list_*` task |
|
|
114
|
+
| `ESRData_GetUnitsOfMeasure` (`unitsOfMeasure`) | `list_units_of_measure()` | `usda_esr_list_units_of_measure` | packaged, `enums.UnitId`; `list_*` task |
|
|
115
|
+
|
|
116
|
+
All nine tasks are covered in 0.1.0, the first release. Alpha: the public surface may
|
|
117
|
+
change in a minor version before 1.0 (conventions §12); `CHANGELOG.md` lists every change.
|
|
118
|
+
|
|
119
|
+
Every request counts against api.data.gov's quota of 1,000 requests per hour per key,
|
|
120
|
+
shared by every package using the same `DATA_GOV_API_KEY`; the `list_*` tasks spend none.
|
|
121
|
+
The client keeps its own pace of one request per second; once the quota is spent it waits
|
|
122
|
+
for the quota to come back when that takes at most 30 s, and otherwise raises
|
|
123
|
+
`RateLimitError` with `retry_after` instead of sending.
|
|
124
|
+
|
|
125
|
+
## Upstream terms and attribution
|
|
126
|
+
|
|
127
|
+
Data comes from USDA FAS Export Sales Reporting (https://www.fas.usda.gov/programs/export-sales-reporting-program) under its own terms of use;
|
|
128
|
+
this package adds no rights to it. Documentation snapshot: `docs/upstream/`.
|
|
129
|
+
|
|
130
|
+
## Licence
|
|
131
|
+
|
|
132
|
+
Apache-2.0. See [LICENSE](LICENSE).
|