Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 0.1.5 — 2026-11-13

The README, the docstrings and `access_info()` now say what the site and its MCP server say: building, calibrating and downloading
models needs model access or a demo, and accounts are by invitation, for a named research collaboration or a funded study.

- `access_info()`: `source` reads "Accounts are by invitation, for a named research collaboration or a funded study.", and the
`free_account` note opens with "Building, calibrating and downloading models needs model access or a demo.", as the MCP
server's `get_access_info` returns them.
- The fallback refusal note says `Client.whoami()` reports your account's access.
- `Client.wait()`'s timeout names the build: "build <id> not terminal after ...".
- The README's section is "Build and download models", and its AI agents section takes the MCP server's sentence: the model, data and
build tools need model access.
- Method, argument and field names are unchanged: `order()`, `orders()`, `status()`, `order_id`, `paid_plans`, `pricing_url`.

## 0.1.4 — 2026-11-07

In November 2026 SWATGenX became invitation only: accounts are by invitation, for a named research collaboration or a funded study,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "swatgenx"
version = "0.1.4"
version = "0.1.5"
description = "Python client for SWATGenX: SWAT+ watershed models built from national data for any USGS gauge in the continental US"
readme = "README.md"
requires-python = ">=3.9"
Expand Down
8 changes: 4 additions & 4 deletions src/swatgenx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
sg.groundwater_at(42.73, -84.55, api_key="...") # nearest well + lithology log
sg.pfas_stations(huc8="04050006", api_key="...") # PFAS stations (8-digit HUC)

Building and downloading models needs an invited account or a demo, and an API key
Building and downloading models needs model access or a demo, and an API key
(request access at https://www.swatgenx.com/signup; once we have approved the request,
open dashboard -> API keys):

Expand All @@ -22,8 +22,8 @@
c.status(order["order_id"])
c.download("04124500", vpuid="0406", dest="model.zip")

Accounts are by invitation, for a named research collaboration or a funded study; plans are
not sold online, and access_info() returns these rules. Calibration runs on cloud compute
Accounts are by invitation, for a named research collaboration or a funded study, and
access_info() returns these rules. Calibration runs on cloud compute
from an account's calibration credit; calibration we do for you, and a MODFLOW 6 groundwater
model, are part of a study (https://www.swatgenx.com/work-with-us). AI agents can use the
same platform via MCP: https://www.swatgenx.com/mcp
Expand All @@ -40,7 +40,7 @@
pfas_summary,
)

__version__ = "0.1.4"
__version__ = "0.1.5"
__all__ = [
"Client", "SwatGenXError", "access_info", "calibration", "catalog",
"groundwater_at", "groundwater_summary", "pfas_stations", "pfas_summary",
Expand Down
32 changes: 16 additions & 16 deletions src/swatgenx/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
surface the website and the MCP server (https://www.swatgenx.com/mcp) use. The example-model
catalog, the inventory summaries and access_info() need no account. The map's data (well records,
PFAS stations) needs an API key whose account may see it, and actions that create state (model
orders, downloads) need an invited account or a demo; the Client class carries the key.
builds, downloads) need model access or a demo; the Client class carries the key.
Authentication, ownership and allocations are enforced server-side.
"""
from __future__ import annotations
Expand All @@ -16,11 +16,11 @@
import requests

BASE = os.environ.get("SWATGENX_BASE_URL", "https://www.swatgenx.com")
_UA = {"User-Agent": "swatgenx-python/0.1.4"}
_UA = {"User-Agent": "swatgenx-python/0.1.5"}


class SwatGenXError(RuntimeError):
"""API error with the server's message and, when relevant, upgrade guidance."""
"""API error with the server's message and, when relevant, the site's access note."""

def __init__(self, message: str, status: int | None = None, detail: Any = None):
super().__init__(message)
Expand All @@ -33,7 +33,7 @@ def __init__(self, message: str, status: int | None = None, detail: Any = None):
# 0.1.4: the MCP server's access_note (Q1616 Am.6); Client.whoami() stands for get_access_info.
_ACCESS_NOTE = (
"This action exceeds your current access or fair-use allocation. "
"Client.whoami() reports your account's plan. Work that is part of a study is quoted at "
"Client.whoami() reports your account's access. Work that is part of a study is quoted at "
"https://www.swatgenx.com/work-with-us, and calibration runs on account credit."
)

Expand Down Expand Up @@ -145,9 +145,9 @@ def pfas_summary() -> dict:


def access_info() -> dict:
"""How SWATGenX access works. Since 2026-11-07 the site is invitation only and sells no plan online, so the site's plans API
answers 404 and this returns the invitation rules with an empty plan list; when that API answers, each plan is its name and the
models it keeps (None = by quote), never a price. These are the words the site's MCP server's get_access_info returns."""
"""How SWATGenX access works. Since 2026-11-07 the site is invitation only and sells no model access online, so the site's
/api/billing/plans answers 404 and this returns the invitation rules with an empty paid_plans list; when that API answers,
each entry is a name and the models it keeps (None = by quote). These are the words the site's MCP server's get_access_info returns."""
try:
body = _request("GET", "/api/billing/plans")
except SwatGenXError as e:
Expand All @@ -162,9 +162,9 @@ def access_info() -> dict:
live = isinstance(body, dict) and isinstance(body.get("plans"), list)
return {
"source": ("live: https://www.swatgenx.com/api/billing/plans" if live else
"Plans are not sold online; accounts are by invitation, for a named research collaboration or a funded study."),
"Accounts are by invitation, for a named research collaboration or a funded study."),
"pricing_url": "https://www.swatgenx.com/contact",
"free_account": {"note": "Building, calibrating and downloading models needs an invited account or a demo. "
"free_account": {"note": "Building, calibrating and downloading models needs model access or a demo. "
"Request access at https://www.swatgenx.com/signup."},
"paid_plans": plans,
"calibration": ("Calibration runs on cloud compute from an account's calibration credit; credit is not sold online. "
Expand Down Expand Up @@ -192,7 +192,7 @@ def __init__(self, api_key: str | None = None):

# -- account
def whoami(self) -> dict:
"""Subscription status for the key's account."""
"""The key's account and its access."""
return _request("GET", "/api/user/subscription-status", key=self.api_key)

# -- data that needs an account
Expand All @@ -208,8 +208,8 @@ def pfas_stations(self, bbox: str | None = None, huc12: str | None = None, huc8:
# -- ordering
def order(self, usgs_station: str | None = None, huc12_outlet: str | None = None,
force_rebuild: bool = False) -> dict:
"""Order a real SWAT+ model build (consumes your fair-use allocation).
Provide either a USGS gauge id or a 12-digit HUC12 outlet. Returns the order
"""Request a real SWAT+ model build (it counts against your fair-use allocation).
Provide either a USGS gauge id or a 12-digit HUC12 outlet. Returns the build's
record incl. order_id; typical build 20 min - 2 h."""
if huc12_outlet:
return _request("POST", "/api/model-settings/explorer-watershed", key=self.api_key,
Expand All @@ -222,19 +222,19 @@ def order(self, usgs_station: str | None = None, huc12_outlet: str | None = None
raise SwatGenXError("provide usgs_station or huc12_outlet")

def status(self, order_id: str) -> dict:
"""State/stage/timing of a build order."""
"""State, stage and timing of a build."""
return _request("GET", f"/api/model-orders/{str(order_id).strip()}", key=self.api_key)

def orders(self) -> dict:
"""All of your build orders, newest first."""
"""All of your builds, newest first."""
return _request("GET", "/api/model-orders", key=self.api_key)

# The server's terminal order states (web_application/app/model_order_queue.py STATE_*). Everything else, including
# QUEUED_APP, DISPATCHING, RUNNING and any state this client does not know yet, means "keep waiting".
TERMINAL_STATES = frozenset({"SUCCESS", "FAILURE", "CANCELLED", "ORPHANED"})

def wait(self, order_id: str, poll_seconds: int = 60, timeout_hours: float = 4.0) -> dict:
"""Block until an order reaches a terminal state; returns the final status() record.
"""Block until a build reaches a terminal state; returns the final status() record.

GET /api/model-orders/<id> nests the record under "order" ({"status": "success", "order": {"state": ...}}).
Until 2026-10-09 this read a top-level "state" that the route never sends, so it could only end at the deadline,
Expand All @@ -247,7 +247,7 @@ def wait(self, order_id: str, poll_seconds: int = 60, timeout_hours: float = 4.0
if state in self.TERMINAL_STATES:
return rec
if time.time() > deadline:
raise SwatGenXError(f"order {order_id} not terminal after {timeout_hours} h "
raise SwatGenXError(f"build {order_id} not terminal after {timeout_hours} h "
f"(last state: {state or 'unknown'})")
time.sleep(max(10, poll_seconds))

Expand Down
6 changes: 4 additions & 2 deletions tests/test_access_info_invitation_014.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

import swatgenx.client as c

INVITE = ("Plans are not sold online; accounts are by invitation, for a named research collaboration or a funded study.")
# 0.1.5 re-pin (was "Plans are not sold online; accounts are by invitation, ..."): the MCP server's get_access_info source.
INVITE = ("Accounts are by invitation, for a named research collaboration or a funded study.")


def _not_found(method, path, **kw):
Expand Down Expand Up @@ -57,7 +58,8 @@ def test_R3_the_access_words_are_the_mcp_servers(monkeypatch):
monkeypatch.setattr(c, "_request", _not_found)
info = c.access_info()
# BROKEN: 'needs a developer plan or a demo' and 'Request developer access ... once we have verified you'.
assert info["free_account"]["note"] == ("Building, calibrating and downloading models needs an invited account or a demo. "
# 0.1.5 re-pin (was "needs an invited account or a demo."): the MCP server's words.
assert info["free_account"]["note"] == ("Building, calibrating and downloading models needs model access or a demo. "
"Request access at https://www.swatgenx.com/signup.")
assert info["calibration"] == ("Calibration runs on cloud compute from an account's calibration credit; credit is not sold "
"online. Calibration we do for you is part of a study.")
Expand Down
6 changes: 4 additions & 2 deletions tests/test_access_words_013.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def test_403_without_a_message_falls_back_to_the_access_note(monkeypatch):
c.pfas_summary()
assert str(e.value) == c._ACCESS_NOTE and e.value.status == 429
# 0.1.4 re-pin (Lane GM's 0.1.4 words; was "access_info() lists the developer plans"): the MCP server's access_note.
assert "Client.whoami() reports your account's plan" in c._ACCESS_NOTE and "/pricing" not in c._ACCESS_NOTE
# 0.1.5 re-pin (Lane GM's 0.1.5 words; was "reports your account's plan").
assert "Client.whoami() reports your account's access" in c._ACCESS_NOTE and "/pricing" not in c._ACCESS_NOTE


def test_no_typed_plan_or_free_account_words_remain():
Expand All @@ -63,7 +64,8 @@ def test_access_info_free_account_states_no_allowance(monkeypatch):
assert info["paid_plans"][0]["plan"] == "Developer" # CONTROL: the payload was read
assert "model_orders_per_day" not in info["free_account"] and "models_kept" not in info["free_account"], info
# 0.1.4 re-pin (invitation only, 2026-11-07; was "needs a developer plan or a demo."): the MCP server's Q1616 Am.6 words.
assert info["free_account"]["note"].startswith("Building, calibrating and downloading models needs an invited account or a demo.")
# 0.1.5 re-pin (was "needs an invited account or a demo."): the MCP server's words.
assert info["free_account"]["note"].startswith("Building, calibrating and downloading models needs model access or a demo.")
assert info["pricing_url"] == "https://www.swatgenx.com/contact" # 0.1.4 re-pin (was /pricing/developer)
assert info["calibration"].startswith("Calibration runs on cloud compute from an account's calibration credit") # 0.1.4 re-pin
assert info["swat_with_modflow6"].startswith("Part of a study we do for you")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def test_access_info_reads_the_live_plans():
if r.status_code == 404:
# 0.1.4: invitation only, plans not sold online. CONTROL: the live API really answers 404 (read above), so the empty list is
# the site's state and not a reader that saw nothing.
assert names == set() and a["source"].startswith("Plans are not sold online"), a
# 0.1.5 re-pin (was startswith("Plans are not sold online")): the MCP server's get_access_info source.
assert names == set() and a["source"].startswith("Accounts are by invitation"), a
else:
assert r.status_code == 200, r.status_code
want = {x.get("display_name") or x.get("plan_name") for x in r.json().get("plans") or []}
Expand Down
9 changes: 5 additions & 4 deletions tests/test_shipped_text_014.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ def test_the_invitation_words_and_controls():
s = _shipped()
count = {k: len(re.findall(r"invitation", _flat(v), re.I)) for k, v in s.items() if k in ("README.md", "__init__.py", "client.py")}
assert count == {"README.md": 2, "__init__.py": 1, "client.py": 3}, count
assert "Client.whoami() reports your account's plan" in _flat(s["client.py"])
# 0.1.5 re-pin (Lane GM's 0.1.5 words; was "reports your account's plan"): the MCP server's access_note.
assert "Client.whoami() reports your account's access" in _flat(s["client.py"])
assert s["README.md"].count("pip install swatgenx") == 1 # CONTROL
assert "https://www.swatgenx.com/mcp" in s["README.md"] and "https://www.swatgenx.com/mcp" in s["__init__.py"]
assert "swatgenx.com/signup" in s["README.md"] and "swatgenx.com/signup" in s["__init__.py"] # CONTROL: the census sees URLs


def test_version_is_014():
assert swatgenx.__version__ == "0.1.4" and 'version = "0.1.4"' in (_ROOT / "pyproject.toml").read_text()
assert swatgenx.client._UA["User-Agent"] == "swatgenx-python/0.1.4"
def test_version_moved_to_015():
# The version rows moved to test_shipped_text_015.py (0.1.5); this file keeps the 0.1.4 entry's census.
assert swatgenx.__version__ != "0.1.3"
Loading
Loading