Metadata-Version: 2.5
Name: xippios-usda-gats
Version: 0.4.0
Summary: Typed client, MCP tools and HTTP routes for USDA FAS Global Agricultural Trade System
Project-URL: Homepage, https://github.com/xippios/sdk-usda-gats
Project-URL: Upstream, https://apps.fas.usda.gov/gats/default.aspx
Project-URL: Changelog, https://github.com/xippios/sdk-usda-gats/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/xippios/sdk-usda-gats/issues
Author: XIPPIOS GmbH
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: httpx,mcp,pydantic,sdk,usda-gats
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: xippios-core~=0.5.0
Requires-Dist: xippios-usda-fas~=0.1.0
Provides-Extra: http
Requires-Dist: xippios-core[http]~=0.5.0; extra == 'http'
Provides-Extra: mcp
Requires-Dist: xippios-core[mcp]~=0.5.0; extra == 'mcp'
Provides-Extra: testing
Requires-Dist: xippios-core[testing]~=0.5.0; extra == 'testing'
Description-Content-Type: text/markdown

# xippios-usda-gats

Typed Python client, MCP server and FastAPI routes for
[USDA FAS Global Agricultural Trade System](https://apps.fas.usda.gov/gats/default.aspx), part of the
[xippios SDK family](https://github.com/xippios). Names and semantics follow the
upstream documentation; every response carries its metadata (source, endpoint,
retrieved_at, request), and the data tasks the release time of what they answer. It
depends on `xippios-usda-fas`, the shared package of the USDA FAS sources, for the
api.data.gov gateway and the kit of its snapshot script.

## Scope

Of GATS's API the package wraps all nineteen operations that its documentation lists
(`docs/upstream/`): the Census exports, imports and re-exports of one partner in one month,
the same by US customs district, the UN Trade exports, imports and re-exports of one
reporter in one year, the four release lists and the six lists of codes, five of which the
package ships and refreshes before each release. GATS documents path parameters alone,
`partnerCode`, `year` and `month` for the Census operations and `reporterCode` and `year`
for the UN Trade operations, and the tasks take every one. The documentation lists XML
beside JSON among the forms that each operation produces; the package asks for JSON, so XML
is the one documented choice that a caller cannot make
(https://github.com/xippios/sdk-usda-gats/issues/64). What the package adds is one partner's
series over months and filters that select records of an answer, of a release list and of
the packaged lists. It ranks no partner, sums no record and picks no month for the caller:
a caller reads every record as GATS sends it. What the package observed of GATS that the
documentation does not say, each note with its probe, stands in `docs/upstream/OBSERVED.md`.

## Install

```bash
uv add xippios-usda-gats            # client only
uv add "xippios-usda-gats[mcp]"     # + MCP server
uv add "xippios-usda-gats[http]"    # + FastAPI router
```

Set `DATA_GOV_API_KEY` in the environment. Nothing is read from files.

## 30-second example

```python
from xippios.usda.gats import get_census_exports, get_census_release_dates
from xippios.usda.gats.models import ProductType

result = get_census_exports("CH", 2026, 8, hs10_code="02")  # US exports to China, August 2026
len(result.data)  # 26: the month's HS10 products of chapter 02, of 777 in all
row = result.data[0]
row.hs10_code, row.value, row.quantity1  # "0201206000", Decimal("30819.0"), Decimal("1018.0")
result.meta.vintage  # "2026-10-06T08:00:00": the month's release time, as upstream states it
result.meta.published_at  # datetime(2026, 10, 6, 8, 0): that time, without a zone
result.meta.published_at_naive  # True: upstream prints its release times without one
result.meta.request  # {"partner_code": "CH", "year": 2026, "month": 8, "hs10_code": "02"}
result.meta.retrieved_at

releases = get_census_release_dates(ProductType.X)  # X exports, M imports
releases.data[0]  # statistical_year_month="202608", release_time_stamp=2026-10-06 08:00 (naive)
this_year = get_census_release_dates(ProductType.X, statistical_year_month="2026")
len(this_year.data)  # 8: 202608 back to 202601; an unreleased or pre-1967 year gives []
```

`partner_code` is GATS's own two-character code, not ISO (`"CH"` China, `"MX"` Mexico,
`"JA"` Japan, `"IC"` Iceland), checked against the countries list packaged in `reference/`
before any call, since GATS answers an unknown code with an empty list, as it answers a
listed partner without trade. An unknown code is refused, naming close codes (an ISO or
GENC code leads to its partner code first: `"CHN"` names `CH` before `CN`) or pointing to
`list_countries` when none is close. Of the 26 codes
GATS marks discontinued (`discontinuedOn`), the 7 that are no other code's parent hold no
trade after their last month: a Census task answers such a month with an empty list and
sends no request, its note in `meta.notes` naming the code's month, the listed codes of the
same name and the code's own parent where it has one. `"D1"` (Denmark) ended in 198712, so
2026-08 answers `[]` with a note naming `9U` and `DA`, while 1987-06 is fetched. The other
19 are parents, codes other records name as their `countryParentCode` (`"SZ"` Switzerland,
the parent of `SR` and `LS`), and pass for every month, as do the two-digit codes of region
`R99`, `"01"` (Caribbean,nes) to `"18"` (ASEAN). `month` is 1 to 12 and `year` four digits;
`hs10_code` keeps the products whose code starts with it, a full ten-digit code for one
product or a prefix such as a chapter, applied after the one data request.
`get_census_imports` takes the same arguments and adds five consumption and CIF fields per
record; `get_census_reexports` answers the exports' record for US re-exports.

A parent answers for its children under its own code, as the two recorded ones did, so
the package accepts every parent for every month (`docs/upstream/OBSERVED.md`, "A parent
code answers for its children"); `"01"` and `"18"` answered an empty list, which means no
data, as for any listed partner without trade, and the package assumes no member list for
the region codes ("The region codes `01` and `18` answer the empty list").

The customs-district forms answer the same partner-month by US customs district, one
record per district and HS10 code, and take `customs_district_id` too, checked against
the packaged districts list (an unknown id names the nearest listed ones):

```python
from xippios.usda.gats import get_customs_district_imports

fillets = get_customs_district_imports("IC", 2026, 8, hs10_code="0304", customs_district_id=10)
len(fillets.data)  # 13: fish fillets from Iceland through New York, of 51 in all districts
```

Each data task makes two requests, a release list and the month, or fewer while the
client's cache holds them: the list for an hour, the month for five minutes, so a
narrower filter on a month already read sends no request. The imports forms check the
imports list; the exports forms and the re-exports forms check the exports list, the
latter by assumption, since upstream publishes no re-export release list. A month not
released yet raises `NotFoundError` naming the latest released and saying that the
release list was read and no data requested. A month before January 1967, where both
lists begin, is a period GATS holds no data for: the exports and imports forms answer it
with an empty list and a note that names what the list holds, sending no data request,
while the re-exports and customs-district forms, whose list is another flow's, refuse
every month it lacks, naming the list read and the assumption. A listed partner without
trade in a released month is an empty list. `meta.vintage` of the exports and imports
forms is the month's release time from that list, as upstream states it
(`"2026-10-06T08:00:00"` for August 2026): upstream's identifier of the release that
last revised the figures, since Census applies corrections once a year and the list
records only each month's latest release. The re-exports and customs-district forms leave
`meta.vintage` and `meta.published_at` empty, since the list states the release of
another flow. The month itself is in `meta.request` and in
every record's `date`. For up to an hour after a release the cached list may still give
a revised month the previous release's time, or refuse a month just released, and the
refusal says when the list was fetched: an accepted lag. `meta.published_at` is the same
release time parsed and kept without a zone, since FAS states none for its release times,
with `meta.published_at_naive` set; `get_census_release_dates` returns them as upstream
states them, every month's or, with `statistical_year_month`, one year's or one month's, a
prefix of upstream's field of that name applied after the one request and recorded in
`meta.request`.

### Month series

The three series tasks answer one partner over a range of months, at most 60 in Python
and over HTTP and 24 over MCP by default (the ceiling is process-wide, see [MCP](#mcp)),
as one flat list in month order; every record carries its month in `date`:

```python
from xippios.usda.gats import get_census_import_series

fish = get_census_import_series(  # fish from Iceland
    "IC", start_year=2026, start_month=7, end_year=2026, end_month=8, hs10_code="03"
)
len(fish.data)  # 85: 42 records for July, then 43 for August, each month in upstream order
row = fish.data[0]
row.date, row.hs10_code, row.value  # "202607", "0302140003", Decimal("1252640.0")
fish.meta.vintage  # "2026-10-06T08:00:00": the newest release among the months, August's
fish.meta.request  # the six arguments: partner_code, start_year, ..., hs10_code="03"
```

`get_census_export_series`, `get_census_import_series` and `get_census_reexport_series` take
`partner_code` by position and `start_year`, `start_month`, `end_year`, `end_month` and
`hs10_code`, which filters every month, by name. Everything is checked before the first
request, the partner code for the start and for the end month; a start after the end, or a
range longer than the ceiling in force, is refused, naming the ceiling. The months after the
last of a discontinued code that is no other code's parent are passed over without a request
and named in a note (`"D1"` for 1987-06 to 1988-01 fetches the seven months to 198712),
while a parent code passes for every month. The flow's release list is read once: a range
with a month not released yet raises `NotFoundError` naming that month and the latest
released, rather than returning the months that are, and the exports and imports series pass
over the months before January 1967 in a note, while the re-exports series refuses every
month the list lacks. `meta.vintage` of the exports and imports series is the newest release
time among the range's months, which across Census's annual revision can be an earlier
month's than the end month's (2025-12 to 2026-02 gives December's revised
`2026-06-24T08:00:00`); `get_census_release_dates` has each month's own.

**Pacing.** A series spends one keyed request per month, plus the release list unless
the client's cache holds it, and sends them one after another at the client's pace of
one request per second, never at once: 60 months take about a minute and 60 of the
key's 1,000 requests per hour. A quota spent partway raises `RateLimitError`, naming the
months answered before it, and none of the months is returned.

## UN Trade data

> **The UN half of GATS is frozen.** Both UN Trade release lists end with statistical year
> 2019, and their newest release is dated 2021-01-18: no later year has appeared since
> (`docs/upstream/OBSERVED.md`, "The UN Trade release lists end in 2019"). The package
> wraps this data faithfully, as GATS serves it, so that a product-level comparison with
> UN Comtrade is possible elsewhere; it maps no code. Reporter, partner and HS6 codes stay
> GATS's own (`list_countries`, `list_hs6_commodities`), not UN Comtrade's and not ISO.

GATS serves trade "as reported by UN COMTrade", one reporter and one statistical year per
request, one record per partner and HS6 code:

```python
from xippios.usda.gats import get_un_exports, get_un_release_dates
from xippios.usda.gats.models import ProductType

fish = get_un_exports("IC", 2019, hs6_code="03")  # Iceland's 2019 exports, HS chapter 03
len(fish.data)  # 1024 records, partner by partner, of 3,980 for the whole year
row = fish.data[0]
row.partner_country_code, row.hs6_code, row.value  # "AE", "030211", Decimal("10620.0")
fish.meta.vintage  # "2020-06-03T05:50:46": Iceland 2019's release time in the exports list
fish.meta.request  # {"reporter_code": "IC", "year": 2019, "hs6_code": "03"}: the filters given

coverage = get_un_release_dates(ProductType.X, reporter_code="IC")
[r.statistical_year for r in coverage.data]  # ["2019", "2018", ..., "1989"]: 31 years
```

`get_un_exports`, `get_un_imports` and `get_un_reexports` take `reporter_code` and `year`
by position and two filters by name, applied after the one data request:
`partner_country_code`, upstream's field that it reads (exact), and `hs6_code` (a full
code from the packaged HS6 list, or a prefix of 1 to 5 digits). The
records keep GATS's codes as the data carries them, older ones included: the UN data uses
`AS` (Australia), `DA` (Denmark), `IT` (Italy), `NO` (Norway) and `NZ` (New Zealand) for
later years, which the countries list marks discontinued in 1987, and never their
successors of the same name (`A2`, `N3`, ...), as `docs/upstream/OBSERVED.md` notes. So the
UN tasks check both country codes for membership in the packaged list only; the Census
tasks' discontinuation rule does not apply. An ISO or GENC code that several listed codes
share is refused naming first the codes the flow's UN release list holds as reporters:
`"AUS"` names `AS` before `A2`, `"FRA"` names `F1` before `FR`. The lists follow no rule
on the codes themselves (the parent reports for Australia, its child for France, both for
Germany), so such a refusal reads the list first, still before the data request, and comes unranked when the list
cannot be read; the Census tasks keep the current code first. Before the data request a
task checks the reporter-year against the flow's UN release list, which the client keeps
for a day, the feed being frozen: the imports task the imports list, the exports task
and, by assumption, the re-exports task the
exports list, since upstream publishes no re-export list. GATS answers an unknown
reporter, a future year and an unreleased year alike with an empty list, so a year after
the latest the list holds for any reporter raises `NotFoundError` naming the reporter's
listed years and the latest year, saying that the release list was read and no data
requested. A reporter-year the list lacks at or before that year is a period GATS holds
no data for: the exports and imports tasks answer it with an empty list and a note naming
the same, sending no data request, while the re-exports task, whose list is another
flow's, refuses it. A listed reporter-year without trade is an empty list (Iceland's 2019
re-exports). `meta.vintage` of the exports and imports tasks is the reporter-year's
release time as upstream states it, and `meta.published_at` that time parsed, naive, as
for the Census tasks; the re-exports task leaves both empty. The client keeps a
reporter-year's answer for a day. One reporter-year can be large, India's 2016 exports more
than the 16 MiB the cache stores (`docs/upstream/OBSERVED.md`, "One UN Trade answer is a
reporter's whole year").
`get_un_release_dates(product_type, *, reporter_code=None, statistical_year=None)`
returns either list, one record per reporter and year, newest year first.

## Reference lists

Five GATS lists ship with the package under `reference/`, and their `list_*` tasks
answer from them without a call; `meta.retrieved_at` is when the package fetched the
list, and `meta.vintage` stays empty, since upstream gives the lists no version:

```python
from xippios.usda.gats import list_countries, list_hs6_commodities
from xippios.usda.gats.enums import UnitOfMeasureId

list_countries(search="CHN").data  # [Country(country_code="CH", ..., iso3_code="CHN", ...)]
list_countries(region_code="R05").data  # CA, GL, MX, SB, US (North America)
list_hs6_commodities(hs6_code="0201").data  # the three HS6 codes of heading 0201
UnitOfMeasureId.KILOGRAMS  # 47, the unit id of the data records
```

`list_regions()` (15), `list_countries(*, region_code=None, search=None)` (322 codes,
current and discontinued; `search` on the code, the name, the ISO and the GENC code, and a
`region_code` the packaged regions list lacks refused naming the closest),
`list_hs6_commodities(*, search=None, hs6_code=None)` (2,909; `search` on the code, the
name and the description, `hs6_code` a prefix of the code, as `list_commodities`'
`hs10_code`), `list_units_of_measure()` (108, ids 0 to 107, which `enums.UnitOfMeasureId`
names) and `list_customs_districts()` (53, e.g. 10 NEW YORK, N.Y.).

The HS10 list is not packaged: 24,936 records and about 7.6 MB. `list_commodities(*,
search=None, hs10_code=None, product_type=None)` fetches it live, in one request the client keeps for
a day and parses into records once for that day, and filters it: `search` on the name
and the description, `hs10_code` a prefix of the code, `product_type` exact.
Upstream's product types are `"X"` (exports), `"M"` (imports), `"T"` and `"B"`; upstream
documents none of them, and the `T` and `B` records carry seven-digit codes padded with
three spaces, kept as sent (`docs/upstream/OBSERVED.md`, "The HS10 commodities list"). A
product type that no record carries is refused once the list is read, naming those it
carries. On a
cache hit `meta.retrieved_at` is when the list was fetched.

## MCP

```json
{
  "mcpServers": {
    "usda-gats": {
      "command": "uvx",
      "args": ["--from", "xippios-usda-gats[mcp]", "xippios-usda-gats-mcp"],
      "env": { "DATA_GOV_API_KEY": "..." }
    }
  }
}
```

Tools are read-only and named `usda_gats_<verb>_<noun>`. Results are capped, at 200 rows or
64 KB unless a tool has a cap of its own, with a note on the rows left out that names the
tool's filters: one partner-month is one row per HS10 product (777 rows for exports to China
in August 2026, 3,294 for imports, 1,697 by customs district), so the notes of the Census
data tools name `hs10_code`, and those of the customs-district tools `customs_district_id`
too, while a cut series shows its newest rows and its note says the rows run oldest month
first and names `hs10_code` and fewer months; `usda_gats_list_hs6_commodities` names
`search` and `hs6_code`, `usda_gats_list_commodities` its three filters. Those two, the two
release-date tools and the three Census month tools without a district take `offset`, the
rows already shown, and answer the next rows from the packaged list or the client's cache
without a request, the note of a cut answer naming the `offset` to continue with: all 777
rows of exports to China in August 2026 arrive in four calls, the three after the first
sending no request. The customs-district tools take no `offset`, since no list keeps their
answer, one row per code and district, within the cache's 16 MiB, so their two filters
narrow a cut answer. The UN
Trade data tools name `partner_country_code` and `hs6_code` (one reporter-year is one row
per partner and HS6 code, 3,980 rows for Iceland's 2019 exports), and
`usda_gats_get_un_release_dates` names `reporter_code` and `statistical_year` (3,796
reporter-years in the exports list). `usda_gats_list_countries` has a cap of its own, 400
rows or 100,000 bytes, so its 322 codes arrive whole. `usda_gats_get_census_release_dates`
returns the newest 200 months, more than sixteen years, with a note that says so and names
`statistical_year_month`, which keeps one year's months or one month, and `offset`. Every
answer names its codes in `meta.names`, the partners, reporters, districts, HS6 codes and
units, from the packaged lists, and those it was asked for too, so an answer without rows
names them. `--http` serves streamable HTTP instead of stdio.

`--series-months MONTHS` sets the most months one series tool call spans, a whole number
from 1 to 60. The server starts with 24: two years, 24 requests, about 24 seconds at the
client's pace of one request per second. The Python API and the HTTP router allow 60, five
years and about a minute (`tasks.SERIES`, core's `Ceiling`). A longer range is refused
before any request, with a message that names the ceiling in force and, below 60,
`--series-months`, and says that nothing was sent; a value outside 1 to 60 stops the
server at start with exit status 2.
For five-year series over MCP, append `"--series-months", "60"` to the `args` above.

The entry point `xippios-usda-gats-mcp` sets the 24, or the `--series-months` given:
core's `main` applies the option through the hooks `tasks.mcp_add_options` and
`tasks.mcp_apply_options`. `xippios.usda.gats.mcp.build()` returns the tool set the entry
point serves, with both hooks, so a host that serves it applies the option as the entry
point does: `tools.apply_options(tools.option_defaults())` sets the 24. A host that
imports `xippios.usda.gats.mcp.server` and serves it another way applies no option and
keeps 60. The ceiling is process-wide
(`tasks.SERIES.value`, `tasks.SERIES.set(months)`), so a Python or HTTP call
made inside an MCP server's process meets the MCP ceiling too: one ceiling, and one MCP
server, per process.

## Status

| Upstream operation | Task function | MCP tool | Status |
| --- | --- | --- | --- |
| `GATSData_GetCensusExports` (`censusExports/partnerCode/{partnerCode}/year/{year}/month/{month}`) | `get_census_exports(partner_code, year, month, *, hs10_code=None)` | `usda_gats_get_census_exports` | alpha |
| `GATSData_GetCensusImport` (`censusImports/partnerCode/{partnerCode}/year/{year}/month/{month}`) | `get_census_imports(partner_code, year, month, *, hs10_code=None)` | `usda_gats_get_census_imports` | alpha |
| `GATSData_GetCensusReExports` (`censusReExports/partnerCode/{partnerCode}/year/{year}/month/{month}`) | `get_census_reexports(partner_code, year, month, *, hs10_code=None)` | `usda_gats_get_census_reexports` | alpha |
| `GATSData_GetCensusExports`, one request per month | `get_census_export_series(partner_code, *, start_year, start_month, end_year, end_month, hs10_code=None)`, at most 60 months in Python and over HTTP, 24 on the MCP server by default | `usda_gats_get_census_export_series` | alpha |
| `GATSData_GetCensusImport`, one request per month | `get_census_import_series(partner_code, *, start_year, start_month, end_year, end_month, hs10_code=None)`, at most 60 months in Python and over HTTP, 24 on the MCP server by default | `usda_gats_get_census_import_series` | alpha |
| `GATSData_GetCensusReExports`, one request per month | `get_census_reexport_series(partner_code, *, start_year, start_month, end_year, end_month, hs10_code=None)`, at most 60 months in Python and over HTTP, 24 on the MCP server by default | `usda_gats_get_census_reexport_series` | alpha |
| `GATSData_GetCustomsDistrictsExports` (`customsDistrictExports/partnerCode/{partnerCode}/year/{year}/month/{month}`) | `get_customs_district_exports(partner_code, year, month, *, hs10_code=None, customs_district_id=None)` | `usda_gats_get_customs_district_exports` | alpha |
| `GATSData_GetCustomsDistrictsImports` (`customsDistrictImports/partnerCode/{partnerCode}/year/{year}/month/{month}`) | `get_customs_district_imports(partner_code, year, month, *, hs10_code=None, customs_district_id=None)` | `usda_gats_get_customs_district_imports` | alpha |
| `GATSData_GetCustomsDistrictsReExports` (`customsDistrictReExports/partnerCode/{partnerCode}/year/{year}/month/{month}`) | `get_customs_district_reexports(partner_code, year, month, *, hs10_code=None, customs_district_id=None)` | `usda_gats_get_customs_district_reexports` | alpha |
| `GATSData_GetCensusExportDataReleaseInfo` (`census/data/exports/dataReleaseDates`) | `get_census_release_dates("X", *, statistical_year_month=None)`; read by the exports and re-exports tasks and series too | `usda_gats_get_census_release_dates` | alpha |
| `GATSData_GetCensusImportDataReleaseInfo` (`census/data/imports/dataReleaseDates`) | `get_census_release_dates("M", *, statistical_year_month=None)`; read by the imports tasks and series too | `usda_gats_get_census_release_dates` | alpha |
| `GATSData_GetUNTradeExports` (`UNTradeExports/reporterCode/{reporterCode}/year/{year}`) | `get_un_exports(reporter_code, year, *, partner_country_code=None, hs6_code=None)` | `usda_gats_get_un_exports` | frozen, last release 2021-01-18 |
| `GATSData_GetUNTradeImports` (`UNTradeImports/reporterCode/{reporterCode}/year/{year}`) | `get_un_imports(reporter_code, year, *, partner_country_code=None, hs6_code=None)` | `usda_gats_get_un_imports` | frozen, last release 2021-01-18 |
| `GATSData_GetUNTradeReExports` (`UNTradeReExports/reporterCode/{reporterCode}/year/{year}`) | `get_un_reexports(reporter_code, year, *, partner_country_code=None, hs6_code=None)` | `usda_gats_get_un_reexports` | frozen, last release 2021-01-18 |
| `GATSData_GetUNTradeExportDataReleaseInfo` (`UNTrade/data/exports/dataReleaseDates`) | `get_un_release_dates("X", *, reporter_code=None, statistical_year=None)`; read by the UN exports and re-exports tasks too | `usda_gats_get_un_release_dates` | frozen, last release 2021-01-18 |
| `GATSData_GetUNTradeImportDataReleaseInfo` (`UNTrade/data/imports/dataReleaseDates`) | `get_un_release_dates("M", *, reporter_code=None, statistical_year=None)`; read by the UN imports task too | `usda_gats_get_un_release_dates` | frozen, last release 2021-01-18 |
| `GATSData_GetCommodities` (`commodities`) | `list_commodities(*, search=None, hs10_code=None, product_type=None)`, live, cached for a day | `usda_gats_list_commodities` | alpha |
| `GATSData_GetRegions` (`regions`) | `list_regions()`, packaged as `reference/regions.json` | `usda_gats_list_regions` | alpha |
| `GATSData_GetCountries` (`countries`) | `list_countries(*, region_code=None, search=None)`, packaged as `reference/countries.json`, which checks the Census `partner_code` and the UN Trade `reporter_code` and `partner_country_code` filter | `usda_gats_list_countries` | alpha |
| `GATSData_GetHS6Commodities` (`HS6Commodities`) | `list_hs6_commodities(*, search=None, hs6_code=None)`, packaged as `reference/HS6Commodities.json`, which checks a six-digit UN Trade `hs6_code` | `usda_gats_list_hs6_commodities` | alpha |
| `GATSData_GetUnitsOfMeasure` (`unitsOfMeasure`) | `list_units_of_measure()`, packaged as `reference/unitsOfMeasure.json`; `enums.UnitOfMeasureId` | `usda_gats_list_units_of_measure` | alpha |
| `GATSData_GetCustomsDistricts` (`customsDistricts`) | `list_customs_districts()`, packaged as `reference/customsDistricts.json`, which checks `customs_district_id` | `usda_gats_list_customs_districts` | alpha |

All nineteen operations of the snapshot (`docs/upstream/`) are wrapped, with the same
twenty tasks as 0.2.0, on xippios-core 0.5.x (`~=0.5.0`) and xippios-usda-fas 0.1.x
(`~=0.1.0`): six Census data tasks, three month series, the Census release dates, four UN
Trade tasks and six list tasks.
Alpha: the public surface may change in a minor version before 1.0 (conventions §12);
`CHANGELOG.md` lists every change. The UN Trade tasks wrap a frozen series (conventions
§4): their rows name the feed's last release, 2021-01-18, as `docs/upstream/OBSERVED.md`
notes with its probe.

Every request counts against api.data.gov's quota of 1,000 requests per hour per key,
shared by every package using the same `DATA_GOV_API_KEY` (xippios-usda-psd and
xippios-usda-esr among them); an answer from the client's cache spends none. The client
caches every answer: a Census month for five minutes, core's default, the two Census
release lists for an hour, every UN Trade answer for a day, since that feed is frozen, and
the HS10 commodities list for a day; it stores a body of up to 16 MiB, twice core's
default, so that the 7.6 MB commodities list stays cached if it grows, and a larger
answer, as India's 2016 UN Trade exports, is not stored. A month series spends one request per
month. The client keeps its own pace of one request per second; once the quota is spent
it waits for the quota to come back when that takes at most 30 s, and otherwise raises
`RateLimitError` with `retry_after` instead of sending.

## Upstream terms and attribution

Data comes from USDA FAS Global Agricultural Trade System (https://apps.fas.usda.gov/gats/default.aspx) under its own terms of use;
this package adds no rights to it. Documentation snapshot: `docs/upstream/`.

## Workflows

`ci.yml` runs ruff, its format check, mypy, pytest and pre-commit on Python 3.12, 3.13 and
3.14, requires a changelog entry of every pull request but Dependabot's and refuses a
fixture file over 256 KiB that a pull request adds or changes. It runs on every pull request and,
called by `publish.yml`, once for a release, and its job `ci` is the check the
organization's ruleset requires. It is handed no secret, and no variable switches it off.

`publish.yml` is the release train (conventions §12): on a push to `main` whose
`pyproject.toml` names a version that has no tag yet and has its section in `CHANGELOG.md`,
it runs `ci.yml`, refuses a core pinned to git, tags the merge commit, builds the package
and, once a reviewer of the environment `pypi` approves the run, publishes it to PyPI by
trusted publishing. Every push to `main` and a dispatch start it, and a push that brings no
release ends quietly. It is handed no secret: the step that tells a release is handed the
job's token as `GH_TOKEN`, the tag goes with the job's token and PyPI trusts the workflow
itself. Its job `tag` holds the one checkout of the repository that keeps its credentials,
since it pushes the tag with the job's token; every other checkout sets
`persist-credentials: false` (conventions §13). No variable switches it off.

`live.yml` runs every `live` test against the upstream with `--tb=short --assert=plain`, so
its public log holds neither a failing test's arguments nor the values an assertion compared.
It runs every night at 02:57 UTC and on demand, never on a pull request.
Its pytest step alone is handed `XIPPIOS_LIVE_TESTS` and, each from the secret of the same
name, `DATA_GOV_API_KEY`, so the checkout, setup-uv and `uv sync` see none.
A variable `WORKFLOW_LIVE` of `off`, the repository's over the organization's, switches it off.

`conventions.yml` calls the organization's review of a pull request against the documents
listed under Documents below, the check `conventions / conventions`, when a pull request
opens, is pushed to, reopens or is edited, and on a push to `main` or a dispatch the review
of the range of commits, `range / range`. It hands the review the organization's
secret of the model's key, by name. A variable `WORKFLOW_CONVENTIONS` of `off`, the
repository's over the organization's, switches both off.

`adr-index.yml` calls the organization's check of the ADR index, `adr-index / adr-index`,
which runs `scripts/adr_index.py --check`, when a pull request opens, is pushed to or
reopens. It hands over nothing, and the called workflow reads its switch itself: a variable
`WORKFLOW_ADR_INDEX` of `off`, the repository's over the organization's, skips the check.

`siblings.yml` runs `.github/scripts/check-siblings.sh`, which installs the wheel beside
every sibling on PyPI under the same provider namespace that shares its core minor and
beside the source packages it depends on, and proves that the namespace levels stay portions
(sdk-core ADR-0006, sdk-core ADR-0021). It runs on every pull request and push to `main`, a
check the ruleset does not require, in a workflow of its own, since `ci.yml` is core's file,
which `publish.yml` calls for a release. It hands the script the job's read-only token as
`GITHUB_TOKEN`, for the listing of the organization's repositories, since GitHub limits the
calls of a runner without one. A variable `WORKFLOW_SIBLINGS` of `off`, the repository's
over the organization's, switches it off.

## Documents

- sdk-core: [docs/conventions.md](https://github.com/xippios/sdk-core/blob/main/docs/conventions.md) — the conventions every xippios source package follows: its layout, names, results, tests and releases.
- sdk-core: [docs/adr.md](https://github.com/xippios/sdk-core/blob/main/docs/adr.md) — the index of the family's architecture decisions, which the conventions cite.
- sdk-core: [docs/definition-of-done.md](https://github.com/xippios/sdk-core/blob/main/docs/definition-of-done.md) — what a change satisfies before its pull request is opened.
- sdk-core: [docs/review-checklist.md](https://github.com/xippios/sdk-core/blob/main/docs/review-checklist.md) — what the review of a pull request checks, in order.
- sdk-usda-gats: [docs/adr.md](https://github.com/xippios/sdk-usda-gats/blob/main/docs/adr.md) — the index of this package's own decisions, generated from the records in `docs/adr/`.
- sdk-usda-gats: [docs/upstream/FETCHED.md](https://github.com/xippios/sdk-usda-gats/blob/main/docs/upstream/FETCHED.md) — the snapshot of the upstream documentation, the reference for names, parameters and semantics.

## Licence

Apache-2.0. See [LICENSE](https://github.com/xippios/sdk-usda-gats/blob/main/LICENSE).
