xippios-usda-psd 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_psd-0.1.0/.gitignore +23 -0
- xippios_usda_psd-0.1.0/CHANGELOG.md +108 -0
- xippios_usda_psd-0.1.0/LICENSE +201 -0
- xippios_usda_psd-0.1.0/PKG-INFO +183 -0
- xippios_usda_psd-0.1.0/README.md +154 -0
- xippios_usda_psd-0.1.0/docs/upstream/FETCHED.md +62 -0
- xippios_usda_psd-0.1.0/docs/upstream/openapi/backend-docs-v1.json +306 -0
- xippios_usda_psd-0.1.0/docs/upstream/openapi/portal-document.json +310 -0
- xippios_usda_psd-0.1.0/pyproject.toml +98 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/__init__.py +38 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/_client.py +394 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/_version.py +10 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/api/PSDData_GetCommodities.py +31 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/api/PSDData_GetCommodityAttributes.py +33 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/api/PSDData_GetCommodityDataByYear.py +43 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/api/PSDData_GetCountries.py +32 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/api/PSDData_GetCountryCommodityDataByYear.py +51 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/api/PSDData_GetDataReleaseInfo.py +38 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/api/PSDData_GetRegions.py +31 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/api/PSDData_GetUnitsOfMeasure.py +31 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/api/PSDData_GetWorldCommodityDataByYear.py +43 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/api/__init__.py +35 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/enums.py +153 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/errors.py +82 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/http.py +14 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/mcp.py +29 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/models.py +243 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/params.py +248 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/py.typed +0 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/reference/README.md +51 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/reference/commodities.json +259 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/reference/commodityAttributes.json +347 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/reference/countries.json +1513 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/reference/regions.json +67 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/reference/unitsOfMeasure.json +175 -0
- xippios_usda_psd-0.1.0/src/xippios/usda/psd/tasks.py +734 -0
- xippios_usda_psd-0.1.0/tests/conftest.py +39 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCommodities/all.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCommodities/invalid_key.json +58 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCommodities/over_rate_limit.json +66 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCommodityAttributes/all.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCommodityDataByYear/corn_all_2023.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCommodityDataByYear/wheat_all_2023.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCommodityDataByYear/year_1900.json +70 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCountries/all.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCountryCommodityDataByYear/no_data_valid_codes.json +70 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCountryCommodityDataByYear/unknown_commodity.json +70 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCountryCommodityDataByYear/unknown_country.json +70 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCountryCommodityDataByYear/unknown_year.json +70 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCountryCommodityDataByYear/wheat_us_2021.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCountryCommodityDataByYear/wheat_us_2022.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetCountryCommodityDataByYear/wheat_us_2023.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetDataReleaseInfo/wheat.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetRegions/all.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetUnitsOfMeasure/all.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetWorldCommodityDataByYear/soybeans_world_2023.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetWorldCommodityDataByYear/wheat_world_2023.json +74 -0
- xippios_usda_psd-0.1.0/tests/fixtures/PSDData_GetWorldCommodityDataByYear/year_1900.json +70 -0
- xippios_usda_psd-0.1.0/tests/fixtures/README.md +9 -0
- xippios_usda_psd-0.1.0/tests/test_adapters.py +46 -0
- xippios_usda_psd-0.1.0/tests/test_api.py +173 -0
- xippios_usda_psd-0.1.0/tests/test_client.py +545 -0
- xippios_usda_psd-0.1.0/tests/test_layout.py +20 -0
- xippios_usda_psd-0.1.0/tests/test_lists.py +304 -0
- xippios_usda_psd-0.1.0/tests/test_live.py +129 -0
- xippios_usda_psd-0.1.0/tests/test_params.py +262 -0
- xippios_usda_psd-0.1.0/tests/test_slices.py +676 -0
- xippios_usda_psd-0.1.0/tests/test_tasks.py +385 -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,108 @@
|
|
|
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-24
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Scaffold from [sdk-template](https://github.com/xippios/sdk-template): configured
|
|
14
|
+
client for USDA FAS PSD Online, MCP server and FastAPI router wired to the task
|
|
15
|
+
layer, test harness, CI and publishing.
|
|
16
|
+
- Upstream documentation snapshot in `docs/upstream/` (2026-10-23): the PSD part of
|
|
17
|
+
the FAS Open Data Services Swagger 2.0 document as the portal loads it
|
|
18
|
+
(`openapi/portal-document.json`) and as the API serves it itself
|
|
19
|
+
(`openapi/backend-docs-v1.json`), nine `/api/psd/` operations each, the
|
|
20
|
+
ESR and GATS paths left out. `FETCHED.md` records the full documents' sizes and
|
|
21
|
+
sha256 and the pages that hold no documentation text.
|
|
22
|
+
- `scripts/refresh_upstream.py`: regenerates the snapshot reproducibly, stdlib only and
|
|
23
|
+
without a key (`uv run scripts/refresh_upstream.py`).
|
|
24
|
+
- Endpoint wrappers for the nine PSD operations, named after the snapshot's
|
|
25
|
+
operationIds: the five reference lists (`PSDData_GetCommodities`, `PSDData_GetCountries`,
|
|
26
|
+
`PSDData_GetRegions`, `PSDData_GetUnitsOfMeasure`, `PSDData_GetCommodityAttributes`),
|
|
27
|
+
the data by country, for every country and for the world
|
|
28
|
+
(`PSDData_GetCountryCommodityDataByYear`, `PSDData_GetCommodityDataByYear`,
|
|
29
|
+
`PSDData_GetWorldCommodityDataByYear`) and the release dates
|
|
30
|
+
(`PSDData_GetDataReleaseInfo`). Models mirror the recorded records: `CommodityData`
|
|
31
|
+
with `value` as `Decimal` and attribute and unit ids as plain `int`, so a new upstream
|
|
32
|
+
id never fails an answer, and `DataReleaseInfo`.
|
|
33
|
+
- Tasks `get_data(commodity_code, market_year, country_code=None)` (one country, or every
|
|
34
|
+
country through the `country/all` path), `get_world_data(commodity_code, market_year)`
|
|
35
|
+
and `get_release_dates(commodity_code, market_year=None, country_code=None)`, as MCP
|
|
36
|
+
tools `usda_psd_get_data`, `usda_psd_get_world_data`, `usda_psd_get_release_dates`
|
|
37
|
+
and HTTP routes. Codes and the market year are checked before any call. The data
|
|
38
|
+
tasks set `meta.vintage` to the PSD release that last revised the result, the latest
|
|
39
|
+
`calendarYear`-`month` of its records (`"2026-07"`), and leave `meta.published_at`
|
|
40
|
+
empty: PSD gives a month, no day. A market year without data is `NoDataForYear`,
|
|
41
|
+
a `NotFoundError`, naming commodity, country and year. `get_release_dates` filters
|
|
42
|
+
upstream's full list by market year and country, for polling over MCP.
|
|
43
|
+
- Tasks `list_commodities(search=None)`, `list_countries(region_code=None, search=None)`,
|
|
44
|
+
`list_regions()`, `list_units_of_measure()` and `list_commodity_attributes(search=None)`,
|
|
45
|
+
as MCP tools `usda_psd_list_*` and HTTP routes. They answer from the packaged lists
|
|
46
|
+
without an upstream call, records in upstream order and unchanged; `meta.endpoint` is
|
|
47
|
+
the operation the list was fetched from, `meta.vintage` the day it was fetched
|
|
48
|
+
(`"2026-10-23"`), `meta.retrieved_at` when the task answered, `meta.request` the
|
|
49
|
+
filters. `search` keeps records whose code or name (for countries also the GENC code)
|
|
50
|
+
contains the text, ignoring case;
|
|
51
|
+
`region_code` keeps the countries of one region, exactly (`"R15"`, which
|
|
52
|
+
`PSDData_GetRegions` lacks, included; an unknown region is an empty list), so agents
|
|
53
|
+
can see past the MCP cap of 200 rows (251 countries). Live tests check each packaged
|
|
54
|
+
list against the live one.
|
|
55
|
+
- Slices, as MCP tools `usda_psd_get_*` and HTTP routes, composing the existing
|
|
56
|
+
wrappers and packaged lists, records unchanged (ADR-0003):
|
|
57
|
+
`get_balance_sheet(commodity_code, country_code, market_year)` pivots one country-year
|
|
58
|
+
into one `BalanceSheet` record, lossless, its `attributes` keyed by the packaged
|
|
59
|
+
attribute name (with the id for an id whose name the list gives to several ids, so a key
|
|
60
|
+
is the same in every answer of a package version; `"attribute <id>"` for an id the list
|
|
61
|
+
lacks), each `BalanceSheetEntry` with its own `unit_id`; an empty answer is
|
|
62
|
+
`NotFoundError`. `get_time_series(commodity_code, country_code, attribute_id,
|
|
63
|
+
start_year, end_year)` makes one request per market year from 1960 on, at most 100
|
|
64
|
+
market years per call, oldest first, and leaves a year without data (`NoDataForYear`)
|
|
65
|
+
or without the attribute out, no gap filled; any other error is raised.
|
|
66
|
+
`get_top_countries(commodity_code, market_year, attribute_id, n=10)` ranks the
|
|
67
|
+
`country/all` records of one attribute by value, ties in upstream order, groupings
|
|
68
|
+
such as `E4` included; `meta.vintage` is the latest release among every record ranked.
|
|
69
|
+
`get_latest_release(commodity_code)` keeps the records of the newest release, with
|
|
70
|
+
that release as `meta.vintage`; over MCP at most 200 rows, `get_release_dates` serves
|
|
71
|
+
any part of the list in full.
|
|
72
|
+
- `errors.NoDataForYear`, a `NotFoundError`: `classify` raises it for PSD's empty
|
|
73
|
+
`text/plain` 404 on a data path, the answer for a market year without data, and the
|
|
74
|
+
data tasks raise it again naming commodity, country and year; the gateway's
|
|
75
|
+
`NOT_FOUND` stays a plain `NotFoundError` and reaches the caller unchanged.
|
|
76
|
+
- `params.validate_attribute_id` and `params.attribute_names`: attribute ids are checked
|
|
77
|
+
against the packaged `commodityAttributes` list before any call; `UnknownCode` names
|
|
78
|
+
the closest ids and takes an integer value and its own reason.
|
|
79
|
+
- Client (ADR-0010): `classify` maps api.data.gov's `API_KEY_*` answers to `AuthError`
|
|
80
|
+
naming the code and `DATA_GOV_API_KEY`, a 429 to `RateLimitError` (`Retry-After`, else
|
|
81
|
+
one hour), the gateway's `NOT_FOUND` to `NotFoundError` and PSD's empty-body 404 to
|
|
82
|
+
`NoDataForYear`, a `NotFoundError`. The
|
|
83
|
+
client keeps 60 requests per minute, one at a time, asks for JSON, and records the
|
|
84
|
+
gateway's `x-ratelimit-*` headers in `quota()`, never from a cache hit. Once the
|
|
85
|
+
hourly quota is spent it waits before the next request when the wait is within
|
|
86
|
+
`RetryPolicy.backoff_max`, and otherwise raises `RateLimitError` with `retry_after`
|
|
87
|
+
without sending; a request the cache can answer is never delayed or refused.
|
|
88
|
+
- Packaged reference data: the five lists under `reference/` with provenance, written by
|
|
89
|
+
`scripts/refresh_reference.py` through `api/`; `enums.AttributeId` and `enums.UnitId`
|
|
90
|
+
(`IntEnum`, named after upstream's names); `params.validate_commodity_code`,
|
|
91
|
+
`validate_country_code` (raising `errors.UnknownCode` with the closest packaged codes,
|
|
92
|
+
or a hint for `"all"` and `"00"`) and `validate_market_year`.
|
|
93
|
+
- Recorded fixtures: the five lists; wheat US, wheat and corn for every country, wheat
|
|
94
|
+
and soybeans world, all 2023; wheat US 2021 and 2022 for the time series; the wheat
|
|
95
|
+
release dates; an unknown commodity, country and market year; valid codes without
|
|
96
|
+
data (wheat, Bermuda, 2023: 200 `[]`); market year 1900 for every country and the
|
|
97
|
+
world (404, empty body); an invalid key; and the gateway's 429 (`OVER_RATE_LIMIT`,
|
|
98
|
+
`Retry-After: 3151`, `x-ratelimit-remaining: 0`), recorded after spending the hourly
|
|
99
|
+
quota. `CLAUDE.md` records what each answered.
|
|
100
|
+
- `scripts/check-siblings.sh` and the CI job `siblings`: this wheel and
|
|
101
|
+
`xippios-usda-nass` install side by side, import, pass `uv pip check`, and add no
|
|
102
|
+
`__init__.py` to `xippios/` or `xippios/usda/` (ADR-0006).
|
|
103
|
+
|
|
104
|
+
### Removed
|
|
105
|
+
|
|
106
|
+
- The template's live reachability test `test_upstream_answers`: it sent the key to `/`,
|
|
107
|
+
which the gateway answers 404, spending a quota call. Each task has its own live smoke
|
|
108
|
+
test instead, twelve in all.
|
|
@@ -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,183 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: xippios-usda-psd
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed client, MCP tools and HTTP routes for USDA FAS PSD Online
|
|
5
|
+
Project-URL: Homepage, https://github.com/xippios/sdk-usda-psd
|
|
6
|
+
Project-URL: Upstream, https://apps.fas.usda.gov/psdonline/
|
|
7
|
+
Project-URL: Changelog, https://github.com/xippios/sdk-usda-psd/blob/main/CHANGELOG.md
|
|
8
|
+
Project-URL: Issues, https://github.com/xippios/sdk-usda-psd/issues
|
|
9
|
+
Author: XIPPIOS GmbH
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agriculture,httpx,mcp,pydantic,sdk,usda-psd
|
|
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.1.0
|
|
22
|
+
Provides-Extra: http
|
|
23
|
+
Requires-Dist: xippios-core[http]>=0.1.0; extra == 'http'
|
|
24
|
+
Provides-Extra: mcp
|
|
25
|
+
Requires-Dist: xippios-core[mcp]>=0.1.0; extra == 'mcp'
|
|
26
|
+
Provides-Extra: testing
|
|
27
|
+
Requires-Dist: xippios-core[testing]>=0.1.0; extra == 'testing'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# xippios-usda-psd
|
|
31
|
+
|
|
32
|
+
Typed Python client, MCP server and FastAPI routes for
|
|
33
|
+
[USDA FAS PSD Online](https://apps.fas.usda.gov/psdonline/), 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-psd # client only
|
|
42
|
+
uv add "xippios-usda-psd[mcp]" # + MCP server
|
|
43
|
+
uv add "xippios-usda-psd[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.psd import get_data
|
|
52
|
+
from xippios.usda.psd.enums import AttributeId
|
|
53
|
+
|
|
54
|
+
result = get_data("0410000", 2023, "US") # wheat, market year 2023, United States
|
|
55
|
+
production = next(r for r in result.data if r.attribute_id == AttributeId.PRODUCTION)
|
|
56
|
+
production.value, production.unit_id # Decimal('49095.0'), 8 (UnitId._1000_MT)
|
|
57
|
+
result.meta.vintage # "2026-07": the PSD release that last revised these figures
|
|
58
|
+
result.meta.published_at # None: PSD gives a month, no day
|
|
59
|
+
result.meta.retrieved_at, result.meta.request
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Codes are PSD's own (commodity `0410000` wheat, `0440000` corn, `2222000` soybeans;
|
|
63
|
+
country `US`, `BR`, `E4`), checked against the lists packaged in `reference/` before any
|
|
64
|
+
call. Leave out the country for every country at once, or use `get_world_data` for the
|
|
65
|
+
world total. `attribute_id` and `unit_id` are PSD's integer ids; `enums.AttributeId` and
|
|
66
|
+
`enums.UnitId` name the packaged ones and compare equal to them. The MCP server returns
|
|
67
|
+
at most 200 rows per call, and every country at once is up to about 1,900 rows, so pass a
|
|
68
|
+
country there. `get_release_dates` tells when PSD last revised each country and market
|
|
69
|
+
year; compare it with a stored `meta.vintage` to fetch only what changed.
|
|
70
|
+
|
|
71
|
+
The `list_*` tasks look codes up in the packaged lists, without a call:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from xippios.usda.psd import list_commodities, list_countries
|
|
75
|
+
|
|
76
|
+
result = list_countries(region_code="R01") # PSD's region North America (list_regions)
|
|
77
|
+
[c.country_code for c in result.data] # ["CA", "GL", "MX", "SB", "US"], upstream order
|
|
78
|
+
result.meta.endpoint, result.meta.vintage # "PSDData_GetCountries", "2026-10-23" (fetched)
|
|
79
|
+
list_countries(search="united").data # TC, UK, US: code, name or GENC code, ignoring case
|
|
80
|
+
list_countries(search="usa").data # US United States, by its GENC code "USA"
|
|
81
|
+
list_commodities(search="soybean").data # meal, oil and oilseed, each also "(Local)"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`meta.vintage` of a list is the day the package fetched it (upstream gives these lists no
|
|
85
|
+
version), `meta.retrieved_at` when the task answered. Over MCP `usda_psd_list_countries`
|
|
86
|
+
stops at 200 of its 251 countries, before the United States; pass `region_code` or
|
|
87
|
+
`search` there.
|
|
88
|
+
|
|
89
|
+
The slices answer the common questions from the same operations. They select, order or
|
|
90
|
+
pivot upstream's records and change none: no derived totals, no unit conversion, no gap
|
|
91
|
+
filling.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from xippios.usda.psd import (
|
|
95
|
+
get_balance_sheet,
|
|
96
|
+
get_latest_release,
|
|
97
|
+
get_time_series,
|
|
98
|
+
get_top_countries,
|
|
99
|
+
)
|
|
100
|
+
from xippios.usda.psd.enums import AttributeId
|
|
101
|
+
|
|
102
|
+
sheet = get_balance_sheet("0410000", "US", 2023).data # wheat, United States, one request
|
|
103
|
+
list(sheet.attributes) # ["Area Harvested", "Beginning Stocks", "Production", ...], 15
|
|
104
|
+
sheet.attributes["Production"] # attribute_id=28, unit_id=8 (1000 MT), value=Decimal("49095.0")
|
|
105
|
+
|
|
106
|
+
series = get_time_series("0440000", "US", AttributeId.PRODUCTION, 2021, 2023) # 3 requests
|
|
107
|
+
[(r.market_year, r.value) for r in series.data] # one record per year with data, oldest first
|
|
108
|
+
|
|
109
|
+
top = get_top_countries("2222000", 2023, AttributeId.PRODUCTION, n=5) # soybeans, one request
|
|
110
|
+
[r.country_code for r in top.data] # largest first; "E4" (EU) and aggregates rank too
|
|
111
|
+
|
|
112
|
+
latest = get_latest_release("0410000") # the countries and market years of the newest release
|
|
113
|
+
latest.meta.vintage # "2026-10", comparable with get_data's meta.vintage
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`get_balance_sheet` keys each entry by the attribute's upstream name; an id whose name
|
|
117
|
+
upstream gives to several ids (`"Total Disappearance"` is 126 and 173) always carries the
|
|
118
|
+
id, `"Total Disappearance (126)"`, and each entry keeps its own `unit_id`.
|
|
119
|
+
`get_time_series` starts at 1960 at the earliest, spans at most 100 market years per
|
|
120
|
+
call, spends one request per market year,
|
|
121
|
+
leaves a year without data out, and counts against the hourly quota like every other
|
|
122
|
+
request.
|
|
123
|
+
`get_top_countries` excludes nothing: PSD's groupings (`E4` European Union, `T3` Africa,
|
|
124
|
+
NEC, ...) rank alongside countries; filter with `list_countries` if you must.
|
|
125
|
+
|
|
126
|
+
## MCP
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"mcpServers": {
|
|
131
|
+
"usda-psd": {
|
|
132
|
+
"command": "uvx",
|
|
133
|
+
"args": ["--from", "xippios-usda-psd[mcp]", "xippios-usda-psd-mcp"],
|
|
134
|
+
"env": { "DATA_GOV_API_KEY": "..." }
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Tools are read-only and named `usda_psd_<verb>_<noun>`. Results are capped at
|
|
141
|
+
200 rows or 64 KB with a note on how to narrow the query. `--http` serves streamable
|
|
142
|
+
HTTP instead of stdio.
|
|
143
|
+
|
|
144
|
+
## Status
|
|
145
|
+
|
|
146
|
+
| Upstream operation | Task function | MCP tool | Status |
|
|
147
|
+
| --- | --- | --- | --- |
|
|
148
|
+
| `PSDData_GetCountryCommodityDataByYear` (`commodity/{commodityCode}/country/{countryCode}/year/{marketYear}`) | `get_data(commodity_code, market_year, country_code)` | `usda_psd_get_data` | alpha |
|
|
149
|
+
| `PSDData_GetCommodityDataByYear` (`commodity/{commodityCode}/country/all/year/{marketYear}`) | `get_data(commodity_code, market_year)` | `usda_psd_get_data` | alpha |
|
|
150
|
+
| `PSDData_GetWorldCommodityDataByYear` (`commodity/{commodityCode}/world/year/{marketYear}`) | `get_world_data(commodity_code, market_year)` | `usda_psd_get_world_data` | alpha |
|
|
151
|
+
| `PSDData_GetDataReleaseInfo` (`commodity/{commodityCode}/dataReleaseDates`) | `get_release_dates(commodity_code, market_year, country_code)` | `usda_psd_get_release_dates` | alpha |
|
|
152
|
+
| `PSDData_GetCommodities` (`commodities`) | `list_commodities(search)` | `usda_psd_list_commodities` | packaged; `list_*` task |
|
|
153
|
+
| `PSDData_GetCountries` (`countries`) | `list_countries(region_code, search)` | `usda_psd_list_countries` | packaged; `list_*` task |
|
|
154
|
+
| `PSDData_GetRegions` (`regions`) | `list_regions()` | `usda_psd_list_regions` | packaged; `list_*` task |
|
|
155
|
+
| `PSDData_GetUnitsOfMeasure` (`unitsOfMeasure`) | `list_units_of_measure()` | `usda_psd_list_units_of_measure` | packaged; `list_*` task |
|
|
156
|
+
| `PSDData_GetCommodityAttributes` (`commodityAttributes`) | `list_commodity_attributes(search)` | `usda_psd_list_commodity_attributes` | packaged; `list_*` task |
|
|
157
|
+
|
|
158
|
+
The slices: task-shaped functions over the operations above, no new endpoint.
|
|
159
|
+
|
|
160
|
+
| Upstream operation | Task function | MCP tool | Example | Status |
|
|
161
|
+
| --- | --- | --- | --- | --- |
|
|
162
|
+
| `PSDData_GetCountryCommodityDataByYear`, one request | `get_balance_sheet(commodity_code, country_code, market_year)` | `usda_psd_get_balance_sheet` | `get_balance_sheet("0410000", "US", 2023)`: wheat US 2023 as one record, 15 attributes | alpha |
|
|
163
|
+
| `PSDData_GetCountryCommodityDataByYear`, one request per market year | `get_time_series(commodity_code, country_code, attribute_id, start_year, end_year)` | `usda_psd_get_time_series` | `get_time_series("0440000", "US", 28, 2021, 2023)`: US corn production, three years | alpha |
|
|
164
|
+
| `PSDData_GetCommodityDataByYear`, one request | `get_top_countries(commodity_code, market_year, attribute_id, n=10)` | `usda_psd_get_top_countries` | `get_top_countries("2222000", 2023, 28, n=5)`: the five largest soybean producers | alpha |
|
|
165
|
+
| `PSDData_GetDataReleaseInfo`, one request | `get_latest_release(commodity_code)` | `usda_psd_get_latest_release` | `get_latest_release("0410000")`: what wheat's newest release revised; MCP returns at most 200 rows, a release adding a market year can exceed that (wheat 2026-10: 146), `get_release_dates(commodity_code, market_year=..., country_code=...)` returns any part in full | alpha |
|
|
166
|
+
|
|
167
|
+
All twelve tasks are covered in 0.1.0, the first release. Alpha: the public surface may
|
|
168
|
+
change in a minor version before 1.0 (conventions §12); `CHANGELOG.md` lists every change.
|
|
169
|
+
|
|
170
|
+
Every request counts against api.data.gov's quota of 1,000 requests per hour per key,
|
|
171
|
+
shared by every package using the same `DATA_GOV_API_KEY`; the `list_*` tasks spend none.
|
|
172
|
+
The client keeps its own pace of one request per second; once the quota is spent it waits
|
|
173
|
+
for the quota to come back when that takes at most 30 s, and otherwise raises
|
|
174
|
+
`RateLimitError` with `retry_after` instead of sending.
|
|
175
|
+
|
|
176
|
+
## Upstream terms and attribution
|
|
177
|
+
|
|
178
|
+
Data comes from USDA FAS PSD Online (https://apps.fas.usda.gov/psdonline/) under its own terms of use;
|
|
179
|
+
this package adds no rights to it. Documentation snapshot: `docs/upstream/`.
|
|
180
|
+
|
|
181
|
+
## Licence
|
|
182
|
+
|
|
183
|
+
Apache-2.0. See [LICENSE](LICENSE).
|