tinyfish 0.6.0__tar.gz → 0.6.1__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.
Files changed (54) hide show
  1. {tinyfish-0.6.0 → tinyfish-0.6.1}/CHANGELOG.md +8 -0
  2. {tinyfish-0.6.0 → tinyfish-0.6.1}/PKG-INFO +1 -1
  3. {tinyfish-0.6.0 → tinyfish-0.6.1}/docs/exceptions-and-errors-guide.md +1 -1
  4. {tinyfish-0.6.0 → tinyfish-0.6.1}/docs/internal/exceptions-and-errors-guide.md +1 -1
  5. {tinyfish-0.6.0 → tinyfish-0.6.1}/pyproject.toml +1 -1
  6. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/_utils/client/_base.py +8 -5
  7. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/_utils/exceptions.py +49 -18
  8. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/wallet/types.py +6 -8
  9. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/test_errors.py +20 -0
  10. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/test_wallet.py +20 -4
  11. {tinyfish-0.6.0 → tinyfish-0.6.1}/.gitignore +0 -0
  12. {tinyfish-0.6.0 → tinyfish-0.6.1}/.pre-commit-config.yaml +0 -0
  13. {tinyfish-0.6.0 → tinyfish-0.6.1}/AGENTS.md +0 -0
  14. {tinyfish-0.6.0 → tinyfish-0.6.1}/CLAUDE.md +0 -0
  15. {tinyfish-0.6.0 → tinyfish-0.6.1}/README.md +0 -0
  16. {tinyfish-0.6.0 → tinyfish-0.6.1}/RELEASE.md +0 -0
  17. {tinyfish-0.6.0 → tinyfish-0.6.1}/docs/internal/api-integration-header.md +0 -0
  18. {tinyfish-0.6.0 → tinyfish-0.6.1}/docs/internal/publishing-private-guide.md +0 -0
  19. {tinyfish-0.6.0 → tinyfish-0.6.1}/docs/pagination-guide.md +0 -0
  20. {tinyfish-0.6.0 → tinyfish-0.6.1}/docs/proxy-and-browser-profiles.md +0 -0
  21. {tinyfish-0.6.0 → tinyfish-0.6.1}/docs/streaming-guide.md +0 -0
  22. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/__init__.py +0 -0
  23. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/_utils/__init__.py +0 -0
  24. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/_utils/client/__init__.py +0 -0
  25. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/_utils/client/async_.py +0 -0
  26. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/_utils/client/sync.py +0 -0
  27. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/_utils/resource.py +0 -0
  28. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/_utils/sse_parser.py +0 -0
  29. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/agent/__init__.py +0 -0
  30. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/agent/types.py +0 -0
  31. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/browser/__init__.py +0 -0
  32. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/browser/types.py +0 -0
  33. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/client.py +0 -0
  34. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/fetch/__init__.py +0 -0
  35. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/fetch/types.py +0 -0
  36. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/py.typed +0 -0
  37. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/runs/__init__.py +0 -0
  38. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/runs/types.py +0 -0
  39. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/search/__init__.py +0 -0
  40. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/search/types.py +0 -0
  41. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/vault/__init__.py +0 -0
  42. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/vault/types.py +0 -0
  43. {tinyfish-0.6.0 → tinyfish-0.6.1}/src/tinyfish/wallet/__init__.py +0 -0
  44. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/__init__.py +0 -0
  45. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/conftest.py +0 -0
  46. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/test_agent.py +0 -0
  47. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/test_browser.py +0 -0
  48. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/test_client.py +0 -0
  49. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/test_fetch.py +0 -0
  50. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/test_runs.py +0 -0
  51. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/test_search.py +0 -0
  52. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/test_vault.py +0 -0
  53. {tinyfish-0.6.0 → tinyfish-0.6.1}/tests/testing_guide.md +0 -0
  54. {tinyfish-0.6.0 → tinyfish-0.6.1}/uv.lock +0 -0
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.1](https://github.com/tinyfish-io/ux-labs/compare/sdk-py/v0.6.0...sdk-py/v0.6.1) (2026-08-12)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **sdk:** emit wallet types without vendor-internal fields ([#4257](https://github.com/tinyfish-io/ux-labs/issues/4257)) ([dfefbab](https://github.com/tinyfish-io/ux-labs/commit/dfefbab17420cf617cc1acd0184d580c7b597cdc))
9
+ * **wallet:** gate unreleased wallet reads behind wallet_enabled with typed 404 (PF-3513) ([#4245](https://github.com/tinyfish-io/ux-labs/issues/4245)) ([6d9dc56](https://github.com/tinyfish-io/ux-labs/commit/6d9dc5603996659c8eec8828308fb053d82ed8dc))
10
+
3
11
  ## [0.6.0](https://github.com/tinyfish-io/ux-labs/compare/sdk-py/v0.5.0...sdk-py/v0.6.0) (2026-08-11)
4
12
 
5
13
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinyfish
3
- Version: 0.6.0
3
+ Version: 0.6.1
4
4
  Summary: Official Python SDK for the TinyFish API
5
5
  Requires-Python: >=3.11
6
6
  Requires-Dist: httpx>=0.27.0
@@ -74,7 +74,7 @@ SDKError
74
74
  └─ APIError ← carries .request and .response
75
75
  ├─ APIConnectionError ← network failed
76
76
  │ └─ APITimeoutError ← specifically a timeout
77
- └─ APIStatusError ← carries .status_code too
77
+ └─ APIStatusError ← carries .status_code and .code (machine-readable, from error.code) too
78
78
  ├─ BadRequestError (400)
79
79
  ├─ AuthenticationError (401)
80
80
  ├─ PermissionDeniedError (403)
@@ -74,7 +74,7 @@ SDKError
74
74
  └─ APIError ← carries .request and .response
75
75
  ├─ APIConnectionError ← network failed
76
76
  │ └─ APITimeoutError ← specifically a timeout
77
- └─ APIStatusError ← carries .status_code too
77
+ └─ APIStatusError ← carries .status_code and .code (machine-readable, from error.code) too
78
78
  ├─ BadRequestError (400)
79
79
  ├─ AuthenticationError (401)
80
80
  ├─ PermissionDeniedError (403)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "tinyfish"
3
- version = "0.6.0"
3
+ version = "0.6.1"
4
4
  description = "Official Python SDK for the TinyFish API"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -151,17 +151,20 @@ class _BaseClient:
151
151
  else:
152
152
  error_class = error_map.get(response.status_code, APIStatusError)
153
153
 
154
- # Try to parse error message from JSON response
154
+ # Try to parse the message and machine-readable code from the JSON error body.
155
+ code: str | None = None
155
156
  try:
156
- error_data = response.json()
157
- message = error_data.get("error", {}).get("message", response.text)
157
+ error_data = response.json().get("error", {})
158
+ message = error_data.get("message", response.text)
159
+ raw_code = error_data.get("code")
160
+ code = raw_code if isinstance(raw_code, str) else None
158
161
  except Exception:
159
162
  message = response.text or f"HTTP {response.status_code}"
160
163
 
161
164
  if error_class is APIStatusError:
162
165
  # Fallback: no concrete subclass matched, so pass the raw status code.
163
- return error_class(message=message, response=response, status_code=response.status_code)
164
- return error_class(message=message, response=response)
166
+ return error_class(message=message, response=response, status_code=response.status_code, code=code)
167
+ return error_class(message=message, response=response, code=code)
165
168
 
166
169
  def _parse_response(
167
170
  self,
@@ -83,10 +83,13 @@ class APIStatusError(APIError):
83
83
  *,
84
84
  response: httpx.Response,
85
85
  status_code: int,
86
+ code: str | None = None,
86
87
  request: httpx.Request | None = None,
87
88
  ) -> None:
88
89
  super().__init__(message, request=request, response=response)
89
90
  self.status_code = status_code
91
+ #: Machine-readable error code from the response body's `error.code`, when the server sent one.
92
+ self.code = code
90
93
 
91
94
  def __repr__(self) -> str:
92
95
  return f"{self.__class__.__name__}(status_code={self.status_code}, message={self.message!r})"
@@ -95,57 +98,83 @@ class APIStatusError(APIError):
95
98
  class BadRequestError(APIStatusError):
96
99
  """400 Bad Request."""
97
100
 
98
- def __init__(self, message: str, *, response: httpx.Response, request: httpx.Request | None = None) -> None:
99
- super().__init__(message, response=response, status_code=int(httpx.codes.BAD_REQUEST), request=request)
101
+ def __init__(
102
+ self, message: str, *, response: httpx.Response, code: str | None = None, request: httpx.Request | None = None
103
+ ) -> None:
104
+ super().__init__(
105
+ message, response=response, status_code=int(httpx.codes.BAD_REQUEST), code=code, request=request
106
+ )
100
107
 
101
108
 
102
109
  class AuthenticationError(APIStatusError):
103
110
  """401 Unauthorized."""
104
111
 
105
- def __init__(self, message: str, *, response: httpx.Response, request: httpx.Request | None = None) -> None:
106
- super().__init__(message, response=response, status_code=int(httpx.codes.UNAUTHORIZED), request=request)
112
+ def __init__(
113
+ self, message: str, *, response: httpx.Response, code: str | None = None, request: httpx.Request | None = None
114
+ ) -> None:
115
+ super().__init__(
116
+ message, response=response, status_code=int(httpx.codes.UNAUTHORIZED), code=code, request=request
117
+ )
107
118
 
108
119
 
109
120
  class PermissionDeniedError(APIStatusError):
110
121
  """403 Forbidden."""
111
122
 
112
- def __init__(self, message: str, *, response: httpx.Response, request: httpx.Request | None = None) -> None:
113
- super().__init__(message, response=response, status_code=int(httpx.codes.FORBIDDEN), request=request)
123
+ def __init__(
124
+ self, message: str, *, response: httpx.Response, code: str | None = None, request: httpx.Request | None = None
125
+ ) -> None:
126
+ super().__init__(message, response=response, status_code=int(httpx.codes.FORBIDDEN), code=code, request=request)
114
127
 
115
128
 
116
129
  class NotFoundError(APIStatusError):
117
130
  """404 Not Found."""
118
131
 
119
- def __init__(self, message: str, *, response: httpx.Response, request: httpx.Request | None = None) -> None:
120
- super().__init__(message, response=response, status_code=int(httpx.codes.NOT_FOUND), request=request)
132
+ def __init__(
133
+ self, message: str, *, response: httpx.Response, code: str | None = None, request: httpx.Request | None = None
134
+ ) -> None:
135
+ super().__init__(message, response=response, status_code=int(httpx.codes.NOT_FOUND), code=code, request=request)
121
136
 
122
137
 
123
138
  class RequestTimeoutError(APIStatusError):
124
139
  """408 Request Timeout."""
125
140
 
126
- def __init__(self, message: str, *, response: httpx.Response, request: httpx.Request | None = None) -> None:
127
- super().__init__(message, response=response, status_code=int(httpx.codes.REQUEST_TIMEOUT), request=request)
141
+ def __init__(
142
+ self, message: str, *, response: httpx.Response, code: str | None = None, request: httpx.Request | None = None
143
+ ) -> None:
144
+ super().__init__(
145
+ message, response=response, status_code=int(httpx.codes.REQUEST_TIMEOUT), code=code, request=request
146
+ )
128
147
 
129
148
 
130
149
  class ConflictError(APIStatusError):
131
150
  """409 Conflict."""
132
151
 
133
- def __init__(self, message: str, *, response: httpx.Response, request: httpx.Request | None = None) -> None:
134
- super().__init__(message, response=response, status_code=int(httpx.codes.CONFLICT), request=request)
152
+ def __init__(
153
+ self, message: str, *, response: httpx.Response, code: str | None = None, request: httpx.Request | None = None
154
+ ) -> None:
155
+ super().__init__(message, response=response, status_code=int(httpx.codes.CONFLICT), code=code, request=request)
135
156
 
136
157
 
137
158
  class UnprocessableEntityError(APIStatusError):
138
159
  """422 Unprocessable Entity."""
139
160
 
140
- def __init__(self, message: str, *, response: httpx.Response, request: httpx.Request | None = None) -> None:
141
- super().__init__(message, response=response, status_code=int(httpx.codes.UNPROCESSABLE_ENTITY), request=request)
161
+ def __init__(
162
+ self, message: str, *, response: httpx.Response, code: str | None = None, request: httpx.Request | None = None
163
+ ) -> None:
164
+ super().__init__(
165
+ message, response=response, status_code=int(httpx.codes.UNPROCESSABLE_ENTITY), code=code, request=request
166
+ )
142
167
 
143
168
 
144
169
  class RateLimitError(APIStatusError):
145
170
  """429 Too Many Requests."""
146
171
 
147
- def __init__(self, message: str, *, response: httpx.Response, request: httpx.Request | None = None) -> None:
148
- super().__init__(message, response=response, status_code=int(httpx.codes.TOO_MANY_REQUESTS), request=request)
172
+ def __init__(
173
+ self, message: str, *, response: httpx.Response, code: str | None = None, request: httpx.Request | None = None
174
+ ) -> None:
175
+ super().__init__(
176
+ message, response=response, status_code=int(httpx.codes.TOO_MANY_REQUESTS), code=code, request=request
177
+ )
149
178
 
150
179
 
151
180
  class InternalServerError(APIStatusError):
@@ -155,5 +184,7 @@ class InternalServerError(APIStatusError):
155
184
  is preserved in the status_code attribute for accurate monitoring/alerting.
156
185
  """
157
186
 
158
- def __init__(self, message: str, *, response: httpx.Response, request: httpx.Request | None = None) -> None:
159
- super().__init__(message, response=response, status_code=response.status_code, request=request)
187
+ def __init__(
188
+ self, message: str, *, response: httpx.Response, code: str | None = None, request: httpx.Request | None = None
189
+ ) -> None:
190
+ super().__init__(message, response=response, status_code=response.status_code, code=code, request=request)
@@ -44,21 +44,19 @@ WalletAutoReload = Annotated[
44
44
 
45
45
 
46
46
  class WalletMeter(BaseModel):
47
- """One priced product on the caller's Metronome contract."""
47
+ """One priced product on the caller's rate contract."""
48
48
 
49
- product_id: str = Field(..., description="Metronome product ID")
50
49
  label: str = Field(..., description="Human-readable meter label")
51
50
  unit_amount: str = Field(..., description="Per-unit rate, decimal string")
52
- currency: str = Field(..., description="Currency code")
51
+ currency: str = Field(..., description="ISO 4217 currency code, e.g. USD")
53
52
  per: str | None = Field(None, description="Billable unit this meter charges per. Absent when unlabeled.")
54
53
 
55
54
 
56
55
  class WalletRates(BaseModel):
57
- """Every priced product on the caller's Metronome contract, read live."""
56
+ """Every priced product on the caller's rate contract, read live."""
58
57
 
59
58
  meters: list[WalletMeter] = Field(..., description="Priced products on the contract")
60
59
  as_of: str = Field(..., description="ISO timestamp the rates were read")
61
- source: Literal["metronome-contract"] = Field(..., description="Rate provenance")
62
60
 
63
61
 
64
62
  class WalletPendingTopUp(BaseModel):
@@ -74,8 +72,8 @@ class WalletResponse(BaseModel):
74
72
  available_balance: str = Field(
75
73
  ..., description="Current spendable balance. A negative value means the wallet is overdrawn."
76
74
  )
77
- currency: str = Field(..., description="Currency code")
78
- as_of: str = Field(..., description="ISO timestamp the balance was read")
75
+ currency: str = Field(..., description="ISO 4217 currency code, e.g. USD")
76
+ as_of: str = Field(..., description="ISO timestamp when the wallet was read")
79
77
  auto_reload: WalletAutoReload | None = Field(
80
78
  None, description="None means the auto-reload read failed, not that it is unconfigured"
81
79
  )
@@ -83,5 +81,5 @@ class WalletResponse(BaseModel):
83
81
  None, description="None means no in-flight top-up, or the ledger read failed"
84
82
  )
85
83
  rates: WalletRates | None = Field(
86
- None, description="None means the rates read failed, or the wallet has no Metronome contract yet"
84
+ None, description="None means the rates read failed, or the wallet has no rate contract yet"
87
85
  )
@@ -101,6 +101,26 @@ def test_exception_message_fallback_to_text(client: TinyFish, respx_mock: MockRo
101
101
  assert exc.value.message # non-empty
102
102
 
103
103
 
104
+ # The response body's error.code is captured on the exception, not silently dropped
105
+ @pytest.mark.respx(base_url=BASE_URL)
106
+ def test_exception_code_captured_from_json(client: TinyFish, respx_mock: MockRouter):
107
+ respx_mock.post(_PATH).mock(
108
+ return_value=httpx.Response(404, json={"error": {"code": "FEATURE_NOT_AVAILABLE", "message": "nope"}})
109
+ )
110
+ with pytest.raises(NotFoundError) as exc:
111
+ client.agent.run(**_BODY)
112
+ assert exc.value.code == "FEATURE_NOT_AVAILABLE"
113
+
114
+
115
+ # When the body carries no code, the attribute is None rather than a stale/wrong value
116
+ @pytest.mark.respx(base_url=BASE_URL)
117
+ def test_exception_code_none_when_absent(client: TinyFish, respx_mock: MockRouter):
118
+ respx_mock.post(_PATH).mock(return_value=httpx.Response(404, json=_err_json()))
119
+ with pytest.raises(NotFoundError) as exc:
120
+ client.agent.run(**_BODY)
121
+ assert exc.value.code is None
122
+
123
+
104
124
  # httpx timeout is wrapped as APITimeoutError
105
125
  @pytest.mark.respx(base_url=BASE_URL)
106
126
  def test_timeout_raises(client: TinyFish, respx_mock: MockRouter):
@@ -10,7 +10,7 @@ from pydantic import ValidationError
10
10
  from respx import MockRouter
11
11
 
12
12
  from tests.conftest import BASE_URL
13
- from tinyfish import AsyncTinyFish, AuthenticationError, TinyFish
13
+ from tinyfish import AsyncTinyFish, AuthenticationError, NotFoundError, TinyFish
14
14
  from tinyfish.wallet.types import WalletAutoReloadState, WalletResponse
15
15
 
16
16
  # ─── Constants ────────────────────────────────────────────────────────────────
@@ -21,7 +21,6 @@ _AS_OF = "2026-08-10T18:04:11.220Z"
21
21
 
22
22
  def _meter(**overrides: Any) -> dict[str, Any]:
23
23
  base: dict[str, Any] = {
24
- "product_id": "prod_agent",
25
24
  "label": "Agent steps",
26
25
  "unit_amount": "0.016000",
27
26
  "currency": "USD",
@@ -34,7 +33,6 @@ def _rates(**overrides: Any) -> dict[str, Any]:
34
33
  base: dict[str, Any] = {
35
34
  "meters": [_meter()],
36
35
  "as_of": _AS_OF,
37
- "source": "metronome-contract",
38
36
  }
39
37
  return {**base, **overrides}
40
38
 
@@ -69,7 +67,6 @@ def test_get_returns_full_shape(client: TinyFish, respx_mock: MockRouter):
69
67
  assert result.pending_top_up is None
70
68
  assert result.rates is not None
71
69
  assert len(result.rates.meters) == 1
72
- assert result.rates.source == "metronome-contract"
73
70
 
74
71
 
75
72
  @pytest.mark.respx(base_url=BASE_URL)
@@ -181,6 +178,25 @@ def test_get_401(client: TinyFish, respx_mock: MockRouter):
181
178
  client.wallet.get()
182
179
 
183
180
 
181
+ @pytest.mark.respx(base_url=BASE_URL)
182
+ def test_get_feature_not_available(client: TinyFish, respx_mock: MockRouter):
183
+ respx_mock.get(_WALLET_PATH).mock(
184
+ return_value=httpx.Response(
185
+ 404,
186
+ json={
187
+ "error": {
188
+ "code": "FEATURE_NOT_AVAILABLE",
189
+ "message": "Wallet is not available for your account yet.",
190
+ }
191
+ },
192
+ )
193
+ )
194
+ with pytest.raises(NotFoundError) as exc:
195
+ client.wallet.get()
196
+ assert exc.value.code == "FEATURE_NOT_AVAILABLE"
197
+ assert exc.value.message == "Wallet is not available for your account yet."
198
+
199
+
184
200
  # ═══════════════════════════════════════════════════════════════════════════════
185
201
  # wallet.get — async
186
202
  # ═══════════════════════════════════════════════════════════════════════════════
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