eolas-data 1.13.0__tar.gz → 1.14.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.
- {eolas_data-1.13.0 → eolas_data-1.14.0}/CHANGELOG.md +28 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/PKG-INFO +2 -2
- {eolas_data-1.13.0 → eolas_data-1.14.0}/README.md +1 -1
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/__init__.py +5 -1
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/cli.py +27 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/client.py +64 -1
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/exceptions.py +30 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/meta.py +9 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/pyproject.toml +1 -1
- eolas_data-1.14.0/tests/conftest.py +7 -0
- eolas_data-1.14.0/tests/test_plan_notices.py +120 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/.github/workflows/catalog-drift.yml +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/.github/workflows/pre-release.yml +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/.github/workflows/publish.yml +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/.github/workflows/smoke.yml +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/.github/workflows/test.yml +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/.gitignore +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/LICENSE +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/_dataset_names.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/_regen_names.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/cdc.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/console.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/dataset.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/library.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/mcp_server.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/reshape.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/rows.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/schedule.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/eolas_data/search.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/scripts/check_client_contract.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/scripts/preflight.sh +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/fixtures/source_helpers.json +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_as_arrow.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_cdc_roundtrip.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_changes_http.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_cli.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_client.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_date_filter.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_geometry_param.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_get_local.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_keyring.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_library.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_mcp_integration.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_mcp_protocol.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_mcp_server.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_meta.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_preview_dimensions.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_progress.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_reshape.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_reshape_integration.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_resilience.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_rows.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_schedule.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_search.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_smoke_live.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_source_helpers.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_sync_bulk.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_sync_changes.py +0 -0
- {eolas_data-1.13.0 → eolas_data-1.14.0}/tests/test_truncation.py +0 -0
|
@@ -3,6 +3,34 @@
|
|
|
3
3
|
All notable changes to `eolas-data` are recorded here. This project follows
|
|
4
4
|
[Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## 1.14.0
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **Pro trial notices.** The server's `X-Eolas-Notice` header (trial row cap and
|
|
11
|
+
end date, "large pulls are paginated and slow on trial", Free-plan sunset) is
|
|
12
|
+
now shown once per `Client` as a `PlanNotice` warning (a `UserWarning`
|
|
13
|
+
subclass). Silence it with
|
|
14
|
+
`warnings.filterwarnings("ignore", category=eolas_data.PlanNotice)`.
|
|
15
|
+
- **`Client.me()`** returns the calling key's plan and limits from `GET /v1/me`.
|
|
16
|
+
- **`eolas auth set-key` / `save-key`** print your plan and any trial notice after
|
|
17
|
+
saving. This is best effort: offline it is skipped silently, and
|
|
18
|
+
`EOLAS_NO_NOTICE=1` turns it off.
|
|
19
|
+
- **`PlanError`** (subclass of `APIError`, with `.code` and `.upgrade_url`) is
|
|
20
|
+
raised for plan refusals. `bulk_not_in_plan` (403) means bulk and `/changes`
|
|
21
|
+
aren't in the trial. `trial_expired` (402) means the trial has ended and
|
|
22
|
+
metadata still works. `trial_soft_cap` (429) means the trial allowance is used
|
|
23
|
+
up. Existing `except APIError` handlers still catch it.
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- **README and PyPI description match the current plans.** They described the
|
|
28
|
+
retired Free plan ("10 requests/month"). They now describe the 14-day Pro trial
|
|
29
|
+
(no card, 50,000 rows per request, about 1,000 requests, no bulk or `/changes`)
|
|
30
|
+
and Pro at NZD $49/month.
|
|
31
|
+
- **"Datasets", not "series".** The `search()` docstring calls eolas datasets
|
|
32
|
+
"datasets". (#17)
|
|
33
|
+
|
|
6
34
|
## 1.13.0
|
|
7
35
|
|
|
8
36
|
### Changed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: eolas-data
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.14.0
|
|
4
4
|
Summary: Python client for the eolas.nz statistical data API (NZ + OECD; Australia on roadmap)
|
|
5
5
|
Project-URL: Homepage, https://eolas.nz
|
|
6
6
|
Project-URL: Documentation, https://docs.eolas.nz/
|
|
@@ -87,7 +87,7 @@ client.search("cpi") # expands aliases; surfaces rbnz_m1_prices before nz_cpi
|
|
|
87
87
|
meta = client.info("rbnz_m1_prices")
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
Get an API key at <https://eolas.nz/signup>.
|
|
90
|
+
Get an API key at <https://eolas.nz/signup>. Every new account starts with a 14-day Pro trial, with no credit card: up to 50,000 rows per request and about 1,000 requests, without bulk downloads or the `/changes` feed. Pro (NZD $49/month) is unlimited. See [plans and pricing](https://eolas.nz/#pricing).
|
|
91
91
|
|
|
92
92
|
## Quick setup (workstation)
|
|
93
93
|
|
|
@@ -35,7 +35,7 @@ client.search("cpi") # expands aliases; surfaces rbnz_m1_prices before nz_cpi
|
|
|
35
35
|
meta = client.info("rbnz_m1_prices")
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
Get an API key at <https://eolas.nz/signup>.
|
|
38
|
+
Get an API key at <https://eolas.nz/signup>. Every new account starts with a 14-day Pro trial, with no credit card: up to 50,000 rows per request and about 1,000 requests, without bulk downloads or the `/changes` feed. Pro (NZD $49/month) is unlimited. See [plans and pricing](https://eolas.nz/#pricing).
|
|
39
39
|
|
|
40
40
|
## Quick setup (workstation)
|
|
41
41
|
|
|
@@ -15,6 +15,8 @@ from .exceptions import (
|
|
|
15
15
|
ChangesUpgradeRequired,
|
|
16
16
|
EolasError,
|
|
17
17
|
NotFoundError,
|
|
18
|
+
PlanError,
|
|
19
|
+
PlanNotice,
|
|
18
20
|
RateLimitError,
|
|
19
21
|
ReshapeError,
|
|
20
22
|
WatermarkExpired,
|
|
@@ -28,7 +30,7 @@ from .reshape import pivot_longer, pivot_wider
|
|
|
28
30
|
try:
|
|
29
31
|
__version__ = _pkg_version("eolas-data")
|
|
30
32
|
except PackageNotFoundError: # pragma: no cover - uninstalled source checkout
|
|
31
|
-
__version__ = "1.
|
|
33
|
+
__version__ = "1.14.0"
|
|
32
34
|
|
|
33
35
|
__all__ = [
|
|
34
36
|
"Client",
|
|
@@ -40,6 +42,8 @@ __all__ = [
|
|
|
40
42
|
"RateLimitError",
|
|
41
43
|
"NotFoundError",
|
|
42
44
|
"APIError",
|
|
45
|
+
"PlanError",
|
|
46
|
+
"PlanNotice",
|
|
43
47
|
"BulkUpgradeRequired",
|
|
44
48
|
"BulkLicenceRestricted",
|
|
45
49
|
"BulkNotYetAvailable",
|
|
@@ -976,6 +976,31 @@ def _mask(key: str) -> str:
|
|
|
976
976
|
return key[:8] + "…" if len(key) > 8 else key
|
|
977
977
|
|
|
978
978
|
|
|
979
|
+
def _show_plan_notice(key: str) -> None:
|
|
980
|
+
"""One-time plan message after saving a key (trial row cap / end date).
|
|
981
|
+
|
|
982
|
+
Best effort: any network or API failure is silent, so saving a key never
|
|
983
|
+
fails because of it. Set EOLAS_NO_NOTICE=1 to skip the lookup.
|
|
984
|
+
"""
|
|
985
|
+
if os.environ.get("EOLAS_NO_NOTICE"):
|
|
986
|
+
return
|
|
987
|
+
try:
|
|
988
|
+
import warnings
|
|
989
|
+
|
|
990
|
+
from .client import Client
|
|
991
|
+
|
|
992
|
+
with warnings.catch_warnings():
|
|
993
|
+
warnings.simplefilter("ignore")
|
|
994
|
+
info = Client(api_key=key, timeout=(3, 5)).me()
|
|
995
|
+
except Exception:
|
|
996
|
+
return
|
|
997
|
+
notice = info.get("notice")
|
|
998
|
+
if notice:
|
|
999
|
+
typer.echo(f"plan: {info.get('plan')} - {notice}")
|
|
1000
|
+
elif info.get("plan"):
|
|
1001
|
+
typer.echo(f"plan: {info['plan']}")
|
|
1002
|
+
|
|
1003
|
+
|
|
979
1004
|
@auth_app.command("set-key")
|
|
980
1005
|
def auth_set_key(
|
|
981
1006
|
api_key: str = typer.Option(
|
|
@@ -991,6 +1016,7 @@ def auth_set_key(
|
|
|
991
1016
|
CONFIG_FILE.write_text(json.dumps({"api_key": api_key}, indent=2) + "\n")
|
|
992
1017
|
CONFIG_FILE.chmod(0o600)
|
|
993
1018
|
typer.echo(f"saved {CONFIG_FILE}")
|
|
1019
|
+
_show_plan_notice(api_key)
|
|
994
1020
|
|
|
995
1021
|
|
|
996
1022
|
@auth_app.command("save-key")
|
|
@@ -1040,6 +1066,7 @@ def auth_save_key(
|
|
|
1040
1066
|
_bail(f"keyring write failed: {exc}", EXIT_GENERIC)
|
|
1041
1067
|
|
|
1042
1068
|
typer.echo(f"saved key {_mask(key)} to OS keyring (service={_KEYRING_SERVICE!r})")
|
|
1069
|
+
_show_plan_notice(key)
|
|
1043
1070
|
|
|
1044
1071
|
|
|
1045
1072
|
@auth_app.command("clear-key")
|
|
@@ -30,6 +30,8 @@ from .exceptions import (
|
|
|
30
30
|
ChangesUpgradeRequired,
|
|
31
31
|
EolasError,
|
|
32
32
|
NotFoundError,
|
|
33
|
+
PlanError,
|
|
34
|
+
PlanNotice,
|
|
33
35
|
RateLimitError,
|
|
34
36
|
WatermarkExpired,
|
|
35
37
|
)
|
|
@@ -86,6 +88,29 @@ class _TimeoutSession(requests.Session):
|
|
|
86
88
|
# is what GeoParquet bulk artifacts carry as their WKB column.
|
|
87
89
|
_GEOMETRY_COLUMNS = frozenset({"geometry_wkt", "geometry"})
|
|
88
90
|
|
|
91
|
+
# Server plan refusals, keyed by X-Eolas-Error-Code (see PlanError).
|
|
92
|
+
_PLAN_ERROR_CODES = frozenset({"bulk_not_in_plan", "trial_expired", "trial_soft_cap"})
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _plan_error_from(resp) -> Optional[PlanError]:
|
|
96
|
+
"""Return a PlanError when *resp* is a plan refusal, else None."""
|
|
97
|
+
code = (resp.headers.get("X-Eolas-Error-Code") or "").strip()
|
|
98
|
+
if resp.status_code not in (402, 403, 429) or code not in _PLAN_ERROR_CODES:
|
|
99
|
+
return None
|
|
100
|
+
try:
|
|
101
|
+
detail = resp.json().get("detail", "")
|
|
102
|
+
except Exception:
|
|
103
|
+
detail = ""
|
|
104
|
+
if not isinstance(detail, str) or not detail:
|
|
105
|
+
detail = resp.headers.get("X-Eolas-Notice") or {
|
|
106
|
+
"bulk_not_in_plan": "Bulk downloads and /changes are not included in your plan.",
|
|
107
|
+
"trial_expired": "Your eolas trial has ended. Metadata stays available.",
|
|
108
|
+
"trial_soft_cap": "Your trial request allowance is used up.",
|
|
109
|
+
}[code]
|
|
110
|
+
return PlanError(resp.status_code, f"{detail} (upgrade: https://eolas.nz/pricing)"
|
|
111
|
+
if "pricing" not in detail else detail, code=code)
|
|
112
|
+
|
|
113
|
+
|
|
89
114
|
_SIDECAR_SCHEMA_VERSION = 1
|
|
90
115
|
_SIDECAR_SCHEMA_VERSION_CDC = 2
|
|
91
116
|
|
|
@@ -282,6 +307,35 @@ class Client:
|
|
|
282
307
|
# every call).
|
|
283
308
|
self._arrow_supported: Optional[bool] = None
|
|
284
309
|
self._meta_cache: dict[str, dict] = {}
|
|
310
|
+
# Plan notices (trial row cap / end date / Free sunset) ride on every
|
|
311
|
+
# response as X-Eolas-Notice. Surface each distinct one once per Client
|
|
312
|
+
# as a PlanNotice warning — no extra request.
|
|
313
|
+
self._seen_notices: set[str] = set()
|
|
314
|
+
self._session.hooks["response"].append(self._on_response)
|
|
315
|
+
|
|
316
|
+
def _on_response(self, resp, *args, **kwargs):
|
|
317
|
+
try:
|
|
318
|
+
notice = resp.headers.get("X-Eolas-Notice")
|
|
319
|
+
except Exception:
|
|
320
|
+
return resp
|
|
321
|
+
if notice and notice not in self._seen_notices:
|
|
322
|
+
self._seen_notices.add(notice)
|
|
323
|
+
import warnings
|
|
324
|
+
|
|
325
|
+
warnings.warn(notice, PlanNotice, stacklevel=2)
|
|
326
|
+
return resp
|
|
327
|
+
|
|
328
|
+
def me(self) -> dict:
|
|
329
|
+
"""Return the calling key's plan and limits (``GET /v1/me``).
|
|
330
|
+
|
|
331
|
+
Keys: ``plan`` (``"trial"``, ``"free_legacy"``, ``"expired"``,
|
|
332
|
+
``"free"``, ``"pro"``, ``"enterprise"``), ``trial_ends_at``,
|
|
333
|
+
``plan_sunset_at``, ``row_cap``, ``bulk``, ``changes``,
|
|
334
|
+
``requests_used``, ``requests_allowance``, ``notice``, ``upgrade_url``.
|
|
335
|
+
"""
|
|
336
|
+
resp = self._session.get(f"{self._base}/v1/me")
|
|
337
|
+
self._raise_for_status(resp)
|
|
338
|
+
return resp.json()
|
|
285
339
|
|
|
286
340
|
def __repr__(self) -> str:
|
|
287
341
|
masked = self._key[:8] + "..." if len(self._key) > 8 else self._key
|
|
@@ -309,7 +363,7 @@ class Client:
|
|
|
309
363
|
"""Search datasets by name, title, or description.
|
|
310
364
|
|
|
311
365
|
Common aliases are expanded (e.g. ``"HLFS"`` → labour-force datasets,
|
|
312
|
-
``"OCR"`` → official cash rate
|
|
366
|
+
``"OCR"`` → official cash rate datasets).
|
|
313
367
|
"""
|
|
314
368
|
from .search import filter_datasets
|
|
315
369
|
|
|
@@ -1444,6 +1498,9 @@ class Client:
|
|
|
1444
1498
|
resp = self._session.get(url, params=params)
|
|
1445
1499
|
if resp.status_code == 200:
|
|
1446
1500
|
return resp
|
|
1501
|
+
plan_err = _plan_error_from(resp)
|
|
1502
|
+
if plan_err is not None:
|
|
1503
|
+
raise plan_err
|
|
1447
1504
|
if resp.status_code == 402:
|
|
1448
1505
|
try:
|
|
1449
1506
|
detail = resp.json().get("detail", "")
|
|
@@ -1733,6 +1790,9 @@ class Client:
|
|
|
1733
1790
|
"""Like ``_raise_for_status`` but handles the extra bulk refusal codes."""
|
|
1734
1791
|
if resp.status_code == 200:
|
|
1735
1792
|
return
|
|
1793
|
+
plan_err = _plan_error_from(resp)
|
|
1794
|
+
if plan_err is not None:
|
|
1795
|
+
raise plan_err
|
|
1736
1796
|
if resp.status_code == 402:
|
|
1737
1797
|
try:
|
|
1738
1798
|
detail = resp.json().get("detail", "")
|
|
@@ -2916,6 +2976,9 @@ class Client:
|
|
|
2916
2976
|
def _raise_for_status(resp: requests.Response) -> None:
|
|
2917
2977
|
if resp.status_code == 200:
|
|
2918
2978
|
return
|
|
2979
|
+
plan_err = _plan_error_from(resp)
|
|
2980
|
+
if plan_err is not None:
|
|
2981
|
+
raise plan_err
|
|
2919
2982
|
if resp.status_code == 401:
|
|
2920
2983
|
raise AuthenticationError(
|
|
2921
2984
|
"Invalid or missing API key. Set the EOLAS_API_KEY environment "
|
|
@@ -20,6 +20,36 @@ class APIError(EolasError):
|
|
|
20
20
|
super().__init__(f"HTTP {status_code}: {message}")
|
|
21
21
|
|
|
22
22
|
|
|
23
|
+
class PlanError(APIError):
|
|
24
|
+
"""The calling key's plan does not include this request.
|
|
25
|
+
|
|
26
|
+
Raised for the server's plan refusals, identified by ``X-Eolas-Error-Code``:
|
|
27
|
+
|
|
28
|
+
- ``bulk_not_in_plan`` (403): bulk Parquet/CSV and ``/changes`` are not in
|
|
29
|
+
the Pro trial (or a grandfathered Free key).
|
|
30
|
+
- ``trial_expired`` (402): the trial has ended; metadata still works.
|
|
31
|
+
- ``trial_soft_cap`` (429): the trial request allowance is used up (only
|
|
32
|
+
when the server enforces the cap).
|
|
33
|
+
|
|
34
|
+
Attributes:
|
|
35
|
+
code: The server error code above.
|
|
36
|
+
upgrade_url: Where to upgrade (https://eolas.nz/pricing).
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self, status_code: int, message: str, code: str = "",
|
|
40
|
+
upgrade_url: str = "https://eolas.nz/pricing"):
|
|
41
|
+
self.code = code
|
|
42
|
+
self.upgrade_url = upgrade_url
|
|
43
|
+
super().__init__(status_code, message)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class PlanNotice(UserWarning):
|
|
47
|
+
"""Warning category for plan notices (trial row cap, end date, Free sunset).
|
|
48
|
+
|
|
49
|
+
Silence with ``warnings.filterwarnings("ignore", category=PlanNotice)``.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
|
|
23
53
|
# ---------------------------------------------------------------------------
|
|
24
54
|
# Bulk-download-specific exceptions (subclass APIError so callers that
|
|
25
55
|
# catch APIError still catch these; callers that want to handle bulk refusals
|
|
@@ -77,6 +77,15 @@ def truncation_message(
|
|
|
77
77
|
f"; limit={int(user_limit)} returned the latest rows WITHIN that "
|
|
78
78
|
"slice, not the dataset's most recent rows"
|
|
79
79
|
)
|
|
80
|
+
if plan in ("trial", "free_legacy"):
|
|
81
|
+
# Bulk files aren't in the trial: don't point at get_local()/sync_bulk().
|
|
82
|
+
msg += (
|
|
83
|
+
". Check df.eolas_meta['truncated']. On the trial, large pulls are "
|
|
84
|
+
"capped per request and must be paged with start=/end=, which is slow. "
|
|
85
|
+
"Upgrade to Pro for bulk Parquet/CSV downloads (get_local()/sync_bulk()): "
|
|
86
|
+
"https://eolas.nz/pricing."
|
|
87
|
+
)
|
|
88
|
+
return msg
|
|
80
89
|
msg += (
|
|
81
90
|
". Check df.eolas_meta['truncated']. Use start=/end= to narrow, "
|
|
82
91
|
"get_local()/sync_bulk() for the whole table, or upgrade at "
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "eolas-data"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.14.0"
|
|
8
8
|
description = "Python client for the eolas.nz statistical data API (NZ + OECD; Australia on roadmap)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Trial / plan notices and PlanError (eolas-data 1.14.0)."""
|
|
2
|
+
import warnings
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
import responses as resp_lib
|
|
6
|
+
from typer.testing import CliRunner
|
|
7
|
+
|
|
8
|
+
from eolas_data import Client, PlanError, PlanNotice
|
|
9
|
+
from eolas_data.exceptions import APIError
|
|
10
|
+
|
|
11
|
+
BASE = "https://api.eolas.nz"
|
|
12
|
+
NOTICE = ("Pro trial: 50,000 rows/request, no bulk downloads; ends 2026-10-28. "
|
|
13
|
+
"Large pulls are paginated and slow on trial - upgrade: https://eolas.nz/pricing")
|
|
14
|
+
|
|
15
|
+
ME = {"plan": "trial", "trial_ends_at": "2026-10-28T00:00:00Z", "row_cap": 50000,
|
|
16
|
+
"bulk": False, "changes": False, "notice": NOTICE,
|
|
17
|
+
"upgrade_url": "https://eolas.nz/pricing"}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@resp_lib.activate
|
|
21
|
+
def test_me_returns_plan():
|
|
22
|
+
resp_lib.add(resp_lib.GET, f"{BASE}/v1/me", json=ME, headers={"X-Eolas-Notice": NOTICE})
|
|
23
|
+
with warnings.catch_warnings():
|
|
24
|
+
warnings.simplefilter("ignore")
|
|
25
|
+
assert Client(api_key="vs_t").me()["plan"] == "trial"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@resp_lib.activate
|
|
29
|
+
def test_notice_header_warns_once_per_client():
|
|
30
|
+
resp_lib.add(resp_lib.GET, f"{BASE}/v1/me", json=ME, headers={"X-Eolas-Notice": NOTICE})
|
|
31
|
+
c = Client(api_key="vs_t")
|
|
32
|
+
with pytest.warns(PlanNotice, match="Pro trial"):
|
|
33
|
+
c.me()
|
|
34
|
+
with warnings.catch_warnings():
|
|
35
|
+
warnings.simplefilter("error", PlanNotice)
|
|
36
|
+
c.me() # same notice: not repeated
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@resp_lib.activate
|
|
40
|
+
def test_no_notice_no_warning():
|
|
41
|
+
resp_lib.add(resp_lib.GET, f"{BASE}/v1/me", json={**ME, "plan": "pro", "notice": None})
|
|
42
|
+
with warnings.catch_warnings():
|
|
43
|
+
warnings.simplefilter("error", PlanNotice)
|
|
44
|
+
Client(api_key="vs_t").me()
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.parametrize("status,code", [
|
|
48
|
+
(402, "trial_expired"), (403, "bulk_not_in_plan"), (429, "trial_soft_cap"),
|
|
49
|
+
])
|
|
50
|
+
@resp_lib.activate
|
|
51
|
+
def test_plan_refusals_raise_plan_error(status, code):
|
|
52
|
+
resp_lib.add(resp_lib.GET, f"{BASE}/v1/me", status=status,
|
|
53
|
+
json={"detail": "Not in your plan. https://eolas.nz/pricing"},
|
|
54
|
+
headers={"X-Eolas-Error-Code": code})
|
|
55
|
+
with pytest.raises(PlanError) as ei:
|
|
56
|
+
Client(api_key="vs_t").me()
|
|
57
|
+
assert ei.value.code == code and ei.value.status_code == status
|
|
58
|
+
assert isinstance(ei.value, APIError) # existing `except APIError` still catches it
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_bulk_status_raises_plan_error():
|
|
62
|
+
import requests
|
|
63
|
+
|
|
64
|
+
r = requests.Response()
|
|
65
|
+
r.status_code = 403
|
|
66
|
+
r.headers["X-Eolas-Error-Code"] = "bulk_not_in_plan"
|
|
67
|
+
r._content = b'{"detail": "Bulk not included in the eolas trial."}'
|
|
68
|
+
with pytest.raises(PlanError, match="pricing"):
|
|
69
|
+
Client._raise_for_bulk_status(r)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_plain_403_is_not_plan_error():
|
|
73
|
+
import requests
|
|
74
|
+
from eolas_data.exceptions import AuthenticationError
|
|
75
|
+
|
|
76
|
+
r = requests.Response()
|
|
77
|
+
r.status_code = 403
|
|
78
|
+
r._content = b'{"detail": "API key is inactive."}'
|
|
79
|
+
with pytest.raises(AuthenticationError):
|
|
80
|
+
Client._raise_for_status(r)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@resp_lib.activate
|
|
84
|
+
def test_set_key_prints_plan_notice(monkeypatch, tmp_path):
|
|
85
|
+
from eolas_data import cli
|
|
86
|
+
|
|
87
|
+
monkeypatch.delenv("EOLAS_NO_NOTICE", raising=False)
|
|
88
|
+
monkeypatch.setattr(cli, "CONFIG_DIR", tmp_path)
|
|
89
|
+
monkeypatch.setattr(cli, "CONFIG_FILE", tmp_path / "config.json")
|
|
90
|
+
resp_lib.add(resp_lib.GET, f"{BASE}/v1/me", json=ME)
|
|
91
|
+
out = CliRunner().invoke(cli.app, ["auth", "set-key", "--key", "vs_trialkey"])
|
|
92
|
+
assert out.exit_code == 0
|
|
93
|
+
assert "plan: trial" in out.output and "paginated" in out.output
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_set_key_survives_offline(monkeypatch, tmp_path):
|
|
97
|
+
from eolas_data import cli
|
|
98
|
+
|
|
99
|
+
monkeypatch.delenv("EOLAS_NO_NOTICE", raising=False)
|
|
100
|
+
monkeypatch.setattr(cli, "CONFIG_DIR", tmp_path)
|
|
101
|
+
monkeypatch.setattr(cli, "CONFIG_FILE", tmp_path / "config.json")
|
|
102
|
+
with resp_lib.RequestsMock(): # no registered URL -> connection error
|
|
103
|
+
out = CliRunner().invoke(cli.app, ["auth", "set-key", "--key", "vs_k"])
|
|
104
|
+
assert out.exit_code == 0 and "saved" in out.output
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@pytest.mark.parametrize("plan", ["trial", "free_legacy"])
|
|
108
|
+
def test_trial_truncation_warning_says_slow_and_upgrade_for_bulk(plan):
|
|
109
|
+
from eolas_data.meta import truncation_message
|
|
110
|
+
|
|
111
|
+
msg = truncation_message("big", {"truncated": True, "row_cap": 50000, "plan": plan})
|
|
112
|
+
assert "50,000 rows" in msg and "slow" in msg and "bulk Parquet/CSV" in msg
|
|
113
|
+
assert "pricing" in msg
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_pro_truncation_warning_unchanged():
|
|
117
|
+
from eolas_data.meta import truncation_message
|
|
118
|
+
|
|
119
|
+
msg = truncation_message("big", {"truncated": True, "row_cap": 50000, "plan": "free"})
|
|
120
|
+
assert "get_local()/sync_bulk() for the whole table" in msg and "slow" not in msg
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|