tinyfish 0.4.0__tar.gz → 0.5.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.
- {tinyfish-0.4.0 → tinyfish-0.5.0}/CHANGELOG.md +7 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/PKG-INFO +6 -2
- {tinyfish-0.4.0 → tinyfish-0.5.0}/README.md +5 -1
- {tinyfish-0.4.0 → tinyfish-0.5.0}/pyproject.toml +1 -1
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/_utils/client/_base.py +38 -5
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/_utils/client/async_.py +3 -3
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/_utils/client/sync.py +3 -3
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/client.py +4 -4
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/fetch/__init__.py +2 -2
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/search/__init__.py +2 -2
- {tinyfish-0.4.0 → tinyfish-0.5.0}/tests/test_client.py +85 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/tests/test_fetch.py +12 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/tests/test_search.py +14 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/uv.lock +1 -1
- {tinyfish-0.4.0 → tinyfish-0.5.0}/.gitignore +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/.pre-commit-config.yaml +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/AGENTS.md +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/CLAUDE.md +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/RELEASE.md +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/docs/exceptions-and-errors-guide.md +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/docs/internal/api-integration-header.md +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/docs/internal/exceptions-and-errors-guide.md +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/docs/internal/publishing-private-guide.md +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/docs/pagination-guide.md +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/docs/proxy-and-browser-profiles.md +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/docs/streaming-guide.md +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/__init__.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/_utils/__init__.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/_utils/client/__init__.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/_utils/exceptions.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/_utils/resource.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/_utils/sse_parser.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/agent/__init__.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/agent/types.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/browser/__init__.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/browser/types.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/fetch/types.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/py.typed +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/runs/__init__.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/runs/types.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/search/types.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/vault/__init__.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/src/tinyfish/vault/types.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/tests/__init__.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/tests/conftest.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/tests/test_agent.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/tests/test_browser.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/tests/test_errors.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/tests/test_runs.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/tests/test_vault.py +0 -0
- {tinyfish-0.4.0 → tinyfish-0.5.0}/tests/testing_guide.md +0 -0
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.5.0](https://github.com/tinyfish-io/ux-labs/compare/sdk-py/v0.4.0...sdk-py/v0.5.0) (2026-08-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **sdk:** send Search and Fetch to their own hosts ([#4008](https://github.com/tinyfish-io/ux-labs/issues/4008)) ([813b4df](https://github.com/tinyfish-io/ux-labs/commit/813b4dfec7a72f1f0771237798c63a1708cb5cee))
|
|
9
|
+
|
|
3
10
|
## [0.4.0](https://github.com/tinyfish-io/ux-labs/compare/sdk-py/v0.3.0...sdk-py/v0.4.0) (2026-07-23)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tinyfish
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Official Python SDK for the TinyFish API
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Requires-Dist: httpx>=0.27.0
|
|
@@ -384,7 +384,11 @@ All seven methods (`agent.run()`, `agent.queue()`, `agent.stream()`, `fetch.get_
|
|
|
384
384
|
```python
|
|
385
385
|
client = TinyFish(
|
|
386
386
|
api_key="your-api-key", # optional — or set TINYFISH_API_KEY env var
|
|
387
|
-
base_url=
|
|
387
|
+
base_url=None, # optional — omit it: Search and Fetch then use
|
|
388
|
+
# https://api.search.tinyfish.ai and
|
|
389
|
+
# https://api.fetch.tinyfish.ai; any explicit value
|
|
390
|
+
# keeps every product on it. Do not pass a product host
|
|
391
|
+
# here — it serves at the root, so /v1/search would 404
|
|
388
392
|
timeout=600.0, # optional — seconds (default: 600)
|
|
389
393
|
max_retries=2, # optional — retry attempts (default: 2)
|
|
390
394
|
)
|
|
@@ -374,7 +374,11 @@ All seven methods (`agent.run()`, `agent.queue()`, `agent.stream()`, `fetch.get_
|
|
|
374
374
|
```python
|
|
375
375
|
client = TinyFish(
|
|
376
376
|
api_key="your-api-key", # optional — or set TINYFISH_API_KEY env var
|
|
377
|
-
base_url=
|
|
377
|
+
base_url=None, # optional — omit it: Search and Fetch then use
|
|
378
|
+
# https://api.search.tinyfish.ai and
|
|
379
|
+
# https://api.fetch.tinyfish.ai; any explicit value
|
|
380
|
+
# keeps every product on it. Do not pass a product host
|
|
381
|
+
# here — it serves at the root, so /v1/search would 404
|
|
378
382
|
timeout=600.0, # optional — seconds (default: 600)
|
|
379
383
|
max_retries=2, # optional — retry attempts (default: 2)
|
|
380
384
|
)
|
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import os
|
|
6
6
|
from importlib.metadata import version as _pkg_version
|
|
7
|
-
from typing import Any, TypeVar
|
|
7
|
+
from typing import Any, Literal, TypeVar
|
|
8
8
|
|
|
9
9
|
import httpx
|
|
10
10
|
from pydantic import BaseModel
|
|
@@ -32,6 +32,21 @@ _RETRY_MULTIPLIER: float = 0.5
|
|
|
32
32
|
_RETRY_MAX_WAIT: float = 8.0
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
def _sanitize_client_header(value: str) -> str:
|
|
36
|
+
"""Non-printable chars raise in httpx; 128 is the server cap (client_name varchar(128))."""
|
|
37
|
+
return "".join(ch for ch in value if 32 <= ord(ch) <= 126).strip()[:128]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
DEFAULT_BASE_URL = "https://agent.tinyfish.ai"
|
|
41
|
+
|
|
42
|
+
# Search and Fetch have their own hostnames, which serve the API at the root path. They are
|
|
43
|
+
# the entry points that run through the API gateway; DEFAULT_BASE_URL is not.
|
|
44
|
+
PRODUCT_BASE_URLS = {
|
|
45
|
+
"search": "https://api.search.tinyfish.ai",
|
|
46
|
+
"fetch": "https://api.fetch.tinyfish.ai",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
35
50
|
class _BaseClient:
|
|
36
51
|
"""Shared logic for sync and async clients. Not for direct use."""
|
|
37
52
|
|
|
@@ -39,16 +54,19 @@ class _BaseClient:
|
|
|
39
54
|
self,
|
|
40
55
|
*,
|
|
41
56
|
api_key: str | None,
|
|
42
|
-
base_url: str,
|
|
57
|
+
base_url: str | None,
|
|
43
58
|
max_retries: int = _DEFAULT_MAX_RETRIES,
|
|
44
59
|
) -> None:
|
|
45
60
|
"""
|
|
46
61
|
Args:
|
|
47
62
|
api_key: API key for authentication. If None, falls back to the
|
|
48
63
|
TINYFISH_API_KEY environment variable.
|
|
49
|
-
base_url: Base URL for all API requests
|
|
64
|
+
base_url: Base URL for all API requests. When set, every product is
|
|
65
|
+
reached on it; when None, Search and Fetch use their own hosts.
|
|
50
66
|
max_retries: Default max retry attempts (default: 2)
|
|
51
67
|
"""
|
|
68
|
+
base_url = (base_url or "").strip() or None
|
|
69
|
+
|
|
52
70
|
# If no key was passed explicitly, try the environment variable.
|
|
53
71
|
# This lets users do `export TINYFISH_API_KEY=xxx` and omit api_key
|
|
54
72
|
# entirely when constructing the client.
|
|
@@ -62,9 +80,17 @@ class _BaseClient:
|
|
|
62
80
|
# and do not appear in autocomplete or when someone inspects the object
|
|
63
81
|
# casually (e.g. vars(client) in a debug session).
|
|
64
82
|
self._api_key = resolved_key
|
|
65
|
-
self._base_url = base_url
|
|
83
|
+
self._base_url = base_url or DEFAULT_BASE_URL
|
|
84
|
+
self._use_product_hosts = base_url is None
|
|
66
85
|
self._max_retries = max_retries
|
|
67
86
|
|
|
87
|
+
def product_url(self, product: Literal["search", "fetch"]) -> str:
|
|
88
|
+
"""Where to send a Search or Fetch request: the product host, or a path on an
|
|
89
|
+
explicitly configured base URL."""
|
|
90
|
+
if self._use_product_hosts:
|
|
91
|
+
return f"{PRODUCT_BASE_URLS[product]}/"
|
|
92
|
+
return f"/v1/{product}"
|
|
93
|
+
|
|
68
94
|
def __repr__(self) -> str:
|
|
69
95
|
# Mask the key so that logging `repr(client)` never writes a live secret
|
|
70
96
|
# to stdout, log files, or error tracking services. We keep the first 8
|
|
@@ -74,13 +100,20 @@ class _BaseClient:
|
|
|
74
100
|
return f"{self.__class__.__name__}(base_url={self._base_url!r}, api_key={masked!r})"
|
|
75
101
|
|
|
76
102
|
def _build_default_headers(self) -> dict[str, str]:
|
|
77
|
-
|
|
103
|
+
headers = {
|
|
78
104
|
"Content-Type": "application/json",
|
|
79
105
|
"Accept": "application/json",
|
|
80
106
|
"X-API-Key": self._api_key,
|
|
81
107
|
"User-Agent": f"tinyfish-python/{_pkg_version('tinyfish')}",
|
|
82
108
|
"X-TF-Request-Origin": "tinyfish-python",
|
|
83
109
|
}
|
|
110
|
+
client_name = _sanitize_client_header(os.environ.get("TF_CLIENT_NAME", ""))
|
|
111
|
+
client_version = _sanitize_client_header(os.environ.get("TF_CLIENT_VERSION", ""))
|
|
112
|
+
if client_name:
|
|
113
|
+
headers["X-TF-Client-Name"] = client_name
|
|
114
|
+
if client_version:
|
|
115
|
+
headers["X-TF-Client-Version"] = client_version
|
|
116
|
+
return headers
|
|
84
117
|
|
|
85
118
|
@staticmethod
|
|
86
119
|
def _inject_integration(json: dict[str, Any] | None) -> dict[str, Any] | None:
|
|
@@ -28,21 +28,21 @@ class BaseAsyncAPIClient(_BaseClient):
|
|
|
28
28
|
self,
|
|
29
29
|
*,
|
|
30
30
|
api_key: str,
|
|
31
|
-
base_url: str,
|
|
31
|
+
base_url: str | None,
|
|
32
32
|
timeout: float = _DEFAULT_TIMEOUT,
|
|
33
33
|
max_retries: int = _DEFAULT_MAX_RETRIES,
|
|
34
34
|
) -> None:
|
|
35
35
|
"""
|
|
36
36
|
Args:
|
|
37
37
|
api_key: API key for authentication
|
|
38
|
-
base_url: Base URL for all API requests
|
|
38
|
+
base_url: Base URL for all API requests. None uses per-product hosts.
|
|
39
39
|
timeout: Default timeout in seconds (default: 600.0)
|
|
40
40
|
max_retries: Default max retry attempts (default: 2)
|
|
41
41
|
"""
|
|
42
42
|
super().__init__(api_key=api_key, base_url=base_url, max_retries=max_retries)
|
|
43
43
|
|
|
44
44
|
self._client = httpx.AsyncClient(
|
|
45
|
-
base_url=
|
|
45
|
+
base_url=self._base_url,
|
|
46
46
|
timeout=timeout,
|
|
47
47
|
headers=self._build_default_headers(),
|
|
48
48
|
)
|
|
@@ -28,21 +28,21 @@ class BaseSyncAPIClient(_BaseClient):
|
|
|
28
28
|
self,
|
|
29
29
|
*,
|
|
30
30
|
api_key: str,
|
|
31
|
-
base_url: str,
|
|
31
|
+
base_url: str | None,
|
|
32
32
|
timeout: float = _DEFAULT_TIMEOUT,
|
|
33
33
|
max_retries: int = _DEFAULT_MAX_RETRIES,
|
|
34
34
|
) -> None:
|
|
35
35
|
"""
|
|
36
36
|
Args:
|
|
37
37
|
api_key: API key for authentication
|
|
38
|
-
base_url: Base URL for all API requests
|
|
38
|
+
base_url: Base URL for all API requests. None uses per-product hosts.
|
|
39
39
|
timeout: Default timeout in seconds (default: 600.0)
|
|
40
40
|
max_retries: Default max retry attempts (default: 2)
|
|
41
41
|
"""
|
|
42
42
|
super().__init__(api_key=api_key, base_url=base_url, max_retries=max_retries)
|
|
43
43
|
|
|
44
44
|
self._client = httpx.Client(
|
|
45
|
-
base_url=
|
|
45
|
+
base_url=self._base_url,
|
|
46
46
|
timeout=timeout,
|
|
47
47
|
headers=self._build_default_headers(),
|
|
48
48
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""TinyFish SDK client."""
|
|
2
2
|
|
|
3
3
|
from tinyfish._utils.client import BaseAsyncAPIClient, BaseSyncAPIClient
|
|
4
|
-
from tinyfish._utils.client._base import _DEFAULT_TIMEOUT
|
|
4
|
+
from tinyfish._utils.client._base import _DEFAULT_TIMEOUT, DEFAULT_BASE_URL
|
|
5
5
|
|
|
6
6
|
from .agent import AgentResource, AsyncAgentResource
|
|
7
7
|
from .browser import AsyncBrowserResource, BrowserResource
|
|
@@ -12,7 +12,7 @@ from .vault import AsyncVaultResource, VaultResource
|
|
|
12
12
|
|
|
13
13
|
__all__ = ["TinyFish", "AsyncTinyFish"]
|
|
14
14
|
|
|
15
|
-
API_BASE_URL =
|
|
15
|
+
API_BASE_URL = DEFAULT_BASE_URL
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class TinyFish(BaseSyncAPIClient):
|
|
@@ -38,7 +38,7 @@ class TinyFish(BaseSyncAPIClient):
|
|
|
38
38
|
# the TINYFISH_API_KEY environment variable and raise a clear ValueError
|
|
39
39
|
# if neither is set.
|
|
40
40
|
api_key: str | None = None,
|
|
41
|
-
base_url: str =
|
|
41
|
+
base_url: str | None = None,
|
|
42
42
|
timeout: float = _DEFAULT_TIMEOUT,
|
|
43
43
|
max_retries: int = 2,
|
|
44
44
|
):
|
|
@@ -77,7 +77,7 @@ class AsyncTinyFish(BaseAsyncAPIClient):
|
|
|
77
77
|
# the TINYFISH_API_KEY environment variable and raise a clear ValueError
|
|
78
78
|
# if neither is set.
|
|
79
79
|
api_key: str | None = None,
|
|
80
|
-
base_url: str =
|
|
80
|
+
base_url: str | None = None,
|
|
81
81
|
timeout: float = _DEFAULT_TIMEOUT,
|
|
82
82
|
max_retries: int = 2,
|
|
83
83
|
):
|
|
@@ -97,7 +97,7 @@ class FetchResource(BaseSyncAPIResource):
|
|
|
97
97
|
if_modified_since=if_modified_since,
|
|
98
98
|
include_etag_and_last_modified=include_etag_and_last_modified,
|
|
99
99
|
)
|
|
100
|
-
return self._post("
|
|
100
|
+
return self._post(self._client.product_url("fetch"), json=body, cast_to=FetchResponse)
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
class AsyncFetchResource(BaseAsyncAPIResource):
|
|
@@ -177,7 +177,7 @@ class AsyncFetchResource(BaseAsyncAPIResource):
|
|
|
177
177
|
if_modified_since=if_modified_since,
|
|
178
178
|
include_etag_and_last_modified=include_etag_and_last_modified,
|
|
179
179
|
)
|
|
180
|
-
return await self._post("
|
|
180
|
+
return await self._post(self._client.product_url("fetch"), json=body, cast_to=FetchResponse)
|
|
181
181
|
|
|
182
182
|
|
|
183
183
|
def _validate_purpose(purpose: str | None) -> None:
|
|
@@ -183,7 +183,7 @@ class SearchResource(BaseSyncAPIResource):
|
|
|
183
183
|
pub_year_max=pub_year_max,
|
|
184
184
|
page=page,
|
|
185
185
|
)
|
|
186
|
-
return self._get("
|
|
186
|
+
return self._get(self._client.product_url("search"), params=params, cast_to=SearchQueryResponse)
|
|
187
187
|
|
|
188
188
|
|
|
189
189
|
class AsyncSearchResource(BaseAsyncAPIResource):
|
|
@@ -257,4 +257,4 @@ class AsyncSearchResource(BaseAsyncAPIResource):
|
|
|
257
257
|
pub_year_max=pub_year_max,
|
|
258
258
|
page=page,
|
|
259
259
|
)
|
|
260
|
-
return await self._get("
|
|
260
|
+
return await self._get(self._client.product_url("search"), params=params, cast_to=SearchQueryResponse)
|
|
@@ -227,3 +227,88 @@ async def test_async_integration_in_body_via_env(respx_mock: MockRouter):
|
|
|
227
227
|
|
|
228
228
|
body = json.loads(route.calls[0].request.content)
|
|
229
229
|
assert body["api_integration"] == "dify"
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
# ─── TF_CLIENT_NAME / TF_CLIENT_VERSION env vars ──────────────────────────
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
# TF_CLIENT_NAME / TF_CLIENT_VERSION env vars are sent as client headers
|
|
236
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
237
|
+
def test_client_headers_via_env(respx_mock: MockRouter):
|
|
238
|
+
with mock.patch.dict(os.environ, {"TF_CLIENT_NAME": "claude-code", "TF_CLIENT_VERSION": "1.2.3"}):
|
|
239
|
+
c = TinyFish(api_key=API_KEY, base_url=BASE_URL, max_retries=0)
|
|
240
|
+
route = respx_mock.post(_PATH).mock(return_value=httpx.Response(200, json=_RUN_OK))
|
|
241
|
+
c.agent.run(**_BODY)
|
|
242
|
+
headers = route.calls[0].request.headers
|
|
243
|
+
assert headers["x-tf-client-name"] == "claude-code"
|
|
244
|
+
assert headers["x-tf-client-version"] == "1.2.3"
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
# Without TF_CLIENT_NAME / TF_CLIENT_VERSION, client headers are absent
|
|
248
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
249
|
+
def test_no_client_headers_by_default(respx_mock: MockRouter):
|
|
250
|
+
with mock.patch.dict(os.environ, {}, clear=False):
|
|
251
|
+
os.environ.pop("TF_CLIENT_NAME", None)
|
|
252
|
+
os.environ.pop("TF_CLIENT_VERSION", None)
|
|
253
|
+
c = TinyFish(api_key=API_KEY, base_url=BASE_URL, max_retries=0)
|
|
254
|
+
route = respx_mock.post(_PATH).mock(return_value=httpx.Response(200, json=_RUN_OK))
|
|
255
|
+
c.agent.run(**_BODY)
|
|
256
|
+
headers = route.calls[0].request.headers
|
|
257
|
+
assert "x-tf-client-name" not in headers
|
|
258
|
+
assert "x-tf-client-version" not in headers
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
# Async client sends client headers when env vars are set
|
|
262
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
263
|
+
async def test_async_client_headers_via_env(respx_mock: MockRouter):
|
|
264
|
+
with mock.patch.dict(os.environ, {"TF_CLIENT_NAME": "claude-desktop", "TF_CLIENT_VERSION": "0.9"}):
|
|
265
|
+
route = respx_mock.post(_PATH).mock(return_value=httpx.Response(200, json=_RUN_OK))
|
|
266
|
+
async with AsyncTinyFish(api_key=API_KEY, base_url=BASE_URL, max_retries=0) as c:
|
|
267
|
+
await c.agent.run(**_BODY)
|
|
268
|
+
headers = route.calls[0].request.headers
|
|
269
|
+
assert headers["x-tf-client-name"] == "claude-desktop"
|
|
270
|
+
assert headers["x-tf-client-version"] == "0.9"
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
# Whitespace-only env vars are treated as unset; unsafe chars are stripped
|
|
274
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
275
|
+
def test_client_headers_sanitized(respx_mock: MockRouter):
|
|
276
|
+
with mock.patch.dict(os.environ, {"TF_CLIENT_NAME": " ", "TF_CLIENT_VERSION": "1.2.3\n"}):
|
|
277
|
+
c = TinyFish(api_key=API_KEY, base_url=BASE_URL, max_retries=0)
|
|
278
|
+
route = respx_mock.post(_PATH).mock(return_value=httpx.Response(200, json=_RUN_OK))
|
|
279
|
+
c.agent.run(**_BODY)
|
|
280
|
+
headers = route.calls[0].request.headers
|
|
281
|
+
assert "x-tf-client-name" not in headers
|
|
282
|
+
assert headers["x-tf-client-version"] == "1.2.3"
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
# Values over the 128-char server cap are truncated client-side
|
|
286
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
287
|
+
def test_client_headers_truncated_to_128(respx_mock: MockRouter):
|
|
288
|
+
with mock.patch.dict(os.environ, {"TF_CLIENT_NAME": "n" * 200, "TF_CLIENT_VERSION": "v" * 200}):
|
|
289
|
+
c = TinyFish(api_key=API_KEY, base_url=BASE_URL, max_retries=0)
|
|
290
|
+
route = respx_mock.post(_PATH).mock(return_value=httpx.Response(200, json=_RUN_OK))
|
|
291
|
+
c.agent.run(**_BODY)
|
|
292
|
+
headers = route.calls[0].request.headers
|
|
293
|
+
assert headers["x-tf-client-name"] == "n" * 128
|
|
294
|
+
assert headers["x-tf-client-version"] == "v" * 128
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def test_search_and_fetch_default_to_their_own_hosts():
|
|
298
|
+
client = TinyFish(api_key="sk-test")
|
|
299
|
+
|
|
300
|
+
assert client.product_url("search") == "https://api.search.tinyfish.ai/"
|
|
301
|
+
assert client.product_url("fetch") == "https://api.fetch.tinyfish.ai/"
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def test_explicit_base_url_keeps_every_product_on_it():
|
|
305
|
+
client = TinyFish(api_key="sk-test", base_url="http://127.0.0.1:4010")
|
|
306
|
+
|
|
307
|
+
assert client.product_url("search") == "/v1/search"
|
|
308
|
+
assert client.product_url("fetch") == "/v1/fetch"
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def test_blank_base_url_behaves_like_omitted():
|
|
312
|
+
client = TinyFish(api_key="sk-test", base_url=" ")
|
|
313
|
+
|
|
314
|
+
assert client.product_url("search") == "https://api.search.tinyfish.ai/"
|
|
@@ -481,3 +481,15 @@ async def test_async_get_contents_401(async_client: AsyncTinyFish, respx_mock: M
|
|
|
481
481
|
async with async_client as c:
|
|
482
482
|
with pytest.raises(AuthenticationError):
|
|
483
483
|
await c.fetch.get_contents(["https://example.com"])
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
@pytest.mark.respx
|
|
487
|
+
def test_default_client_calls_the_fetch_host(respx_mock: MockRouter) -> None:
|
|
488
|
+
"""Pins the wire, not the URL builder — see the search-host test."""
|
|
489
|
+
route = respx_mock.post("https://api.fetch.tinyfish.ai/").mock(
|
|
490
|
+
return_value=httpx.Response(200, json={"results": [], "errors": []})
|
|
491
|
+
)
|
|
492
|
+
|
|
493
|
+
TinyFish(api_key="sk-test", max_retries=0).fetch.get_contents(urls=["https://example.com"])
|
|
494
|
+
|
|
495
|
+
assert route.called
|
|
@@ -528,3 +528,17 @@ async def test_async_query_401(async_client: AsyncTinyFish, respx_mock: MockRout
|
|
|
528
528
|
respx_mock.get(_SEARCH_PATH).mock(return_value=httpx.Response(401, json={"error": {"message": "unauthorized"}}))
|
|
529
529
|
with pytest.raises(AuthenticationError):
|
|
530
530
|
await _do_query(async_client, "test")
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
@pytest.mark.respx
|
|
534
|
+
def test_default_client_calls_the_search_host(respx_mock: MockRouter) -> None:
|
|
535
|
+
"""The URL builder is unit-tested elsewhere; this pins the wire, so a resource that
|
|
536
|
+
forgets product_url cannot silently fall back to the old host."""
|
|
537
|
+
route = respx_mock.get("https://api.search.tinyfish.ai/").mock(
|
|
538
|
+
return_value=httpx.Response(200, json=_search_response())
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
TinyFish(api_key="sk-test", max_retries=0).search.query("agentql pricing")
|
|
542
|
+
|
|
543
|
+
assert route.called
|
|
544
|
+
assert route.calls[0].request.url.params["query"] == "agentql pricing"
|
|
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
|