tinyfish 0.2.2__tar.gz → 0.2.3__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 (35) hide show
  1. tinyfish-0.2.3/PKG-INFO +344 -0
  2. {tinyfish-0.2.2 → tinyfish-0.2.3}/pyproject.toml +2 -1
  3. {tinyfish-0.2.2 → tinyfish-0.2.3}/uv.lock +1 -1
  4. tinyfish-0.2.2/PKG-INFO +0 -8
  5. {tinyfish-0.2.2 → tinyfish-0.2.3}/.gitignore +0 -0
  6. {tinyfish-0.2.2 → tinyfish-0.2.3}/README.md +0 -0
  7. {tinyfish-0.2.2 → tinyfish-0.2.3}/RELEASE.md +0 -0
  8. {tinyfish-0.2.2 → tinyfish-0.2.3}/docs/exceptions-and-errors-guide.md +0 -0
  9. {tinyfish-0.2.2 → tinyfish-0.2.3}/docs/internal/exceptions-and-errors-guide.md +0 -0
  10. {tinyfish-0.2.2 → tinyfish-0.2.3}/docs/internal/publishing-private-guide.md +0 -0
  11. {tinyfish-0.2.2 → tinyfish-0.2.3}/docs/pagination-guide.md +0 -0
  12. {tinyfish-0.2.2 → tinyfish-0.2.3}/docs/proxy-and-browser-profiles.md +0 -0
  13. {tinyfish-0.2.2 → tinyfish-0.2.3}/docs/streaming-guide.md +0 -0
  14. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/__init__.py +0 -0
  15. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/_utils/__init__.py +0 -0
  16. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/_utils/client/__init__.py +0 -0
  17. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/_utils/client/_base.py +0 -0
  18. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/_utils/client/async_.py +0 -0
  19. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/_utils/client/sync.py +0 -0
  20. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/_utils/exceptions.py +0 -0
  21. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/_utils/resource.py +0 -0
  22. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/_utils/sse_parser.py +0 -0
  23. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/agent/__init__.py +0 -0
  24. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/agent/types.py +0 -0
  25. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/client.py +0 -0
  26. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/py.typed +0 -0
  27. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/runs/__init__.py +0 -0
  28. {tinyfish-0.2.2 → tinyfish-0.2.3}/src/tinyfish/runs/types.py +0 -0
  29. {tinyfish-0.2.2 → tinyfish-0.2.3}/tests/__init__.py +0 -0
  30. {tinyfish-0.2.2 → tinyfish-0.2.3}/tests/conftest.py +0 -0
  31. {tinyfish-0.2.2 → tinyfish-0.2.3}/tests/test_agent.py +0 -0
  32. {tinyfish-0.2.2 → tinyfish-0.2.3}/tests/test_client.py +0 -0
  33. {tinyfish-0.2.2 → tinyfish-0.2.3}/tests/test_errors.py +0 -0
  34. {tinyfish-0.2.2 → tinyfish-0.2.3}/tests/test_runs.py +0 -0
  35. {tinyfish-0.2.2 → tinyfish-0.2.3}/tests/testing_guide.md +0 -0
@@ -0,0 +1,344 @@
1
+ Metadata-Version: 2.4
2
+ Name: tinyfish
3
+ Version: 0.2.3
4
+ Summary: Official Python SDK for the TinyFish API
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: httpx>=0.27.0
7
+ Requires-Dist: pydantic>=2.0.0
8
+ Requires-Dist: tenacity>=8.0.0
9
+ Description-Content-Type: text/markdown
10
+
11
+ # TinyFish Python SDK
12
+
13
+ The official Python SDK for [TinyFish](https://agent.tinyfish.ai)
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install tinyfish
19
+ ```
20
+
21
+ Requires Python 3.11+.
22
+
23
+ ## Get your API key
24
+
25
+ Sign up and grab your key at [agent.tinyfish.ai/api-keys](https://agent.tinyfish.ai/api-keys).
26
+
27
+ ## Quickstart
28
+
29
+ ```python
30
+ from tinyfish import TinyFish
31
+
32
+ client = TinyFish(api_key="your-api-key")
33
+
34
+ response = client.agent.run(
35
+ goal="What is the current Bitcoin price?",
36
+ url="https://www.coinbase.com/price/bitcoin",
37
+ )
38
+ print(response.result)
39
+ ```
40
+
41
+ Or set the `TINYFISH_API_KEY` environment variable and omit `api_key`:
42
+
43
+ ```python
44
+ client = TinyFish()
45
+ ```
46
+
47
+ ## Methods
48
+
49
+ Every method below is available on both `TinyFish` (sync) and `AsyncTinyFish` (async). Async versions have the same signatures — just `await` them.
50
+
51
+ | Method | Description | Returns | Blocks? |
52
+ |--------|-------------|---------|---------|
53
+ | [`agent.run()`](#agentrun--block-until-done) | Run an automation, wait for the result | `AgentRunResponse` | Yes |
54
+ | [`agent.queue()`](#agentqueue--fire-and-forget) | Start an automation, return immediately | `AgentRunAsyncResponse` | No |
55
+ | [`agent.stream()`](#agentstream--real-time-events) | Stream live SSE events as the agent works | `AgentStream` | No |
56
+ | [`runs.get()`](#runsget--retrieve-a-single-run) | Retrieve a single run by ID | `Run` | — |
57
+ | [`runs.list()`](#runslist--list-and-filter-runs) | List runs with filtering, sorting, pagination | `RunListResponse` | — |
58
+
59
+ ---
60
+
61
+ ### `agent.run()` — block until done
62
+
63
+ Sends the automation and waits for it to finish. Returns the full result in one shot.
64
+
65
+ ```python
66
+ from tinyfish import TinyFish, RunStatus, BrowserProfile, ProxyConfig, ProxyCountryCode
67
+
68
+ client = TinyFish()
69
+
70
+ response = client.agent.run(
71
+ goal="Extract the top 5 headlines", # required — what to do on the page
72
+ url="https://news.ycombinator.com", # required — URL to open
73
+ browser_profile=BrowserProfile.STEALTH, # optional — "lite" (default) or "stealth"
74
+ proxy_config=ProxyConfig( # optional — proxy settings
75
+ enabled=True,
76
+ country_code=ProxyCountryCode.US, # optional — US, GB, CA, DE, FR, JP, AU
77
+ ),
78
+ )
79
+
80
+ if response.status == RunStatus.COMPLETED:
81
+ print(response.result)
82
+ else:
83
+ print(f"Failed: {response.error.message}")
84
+ ```
85
+
86
+ **Returns `AgentRunResponse`:**
87
+
88
+ | Field | Type | Description |
89
+ |-------|------|-------------|
90
+ | `status` | `RunStatus` | `COMPLETED`, `FAILED`, etc. |
91
+ | `run_id` | `str \| None` | Unique run identifier |
92
+ | `result` | `dict \| None` | Extracted data (`None` if failed) |
93
+ | `error` | `RunError \| None` | Error details (`None` if succeeded) |
94
+ | `num_of_steps` | `int` | Number of steps the agent took |
95
+ | `started_at` | `datetime \| None` | When the run started |
96
+ | `finished_at` | `datetime \| None` | When the run finished |
97
+
98
+ ---
99
+
100
+ ### `agent.queue()` — fire and forget
101
+
102
+ Starts the automation in the background and returns a `run_id` immediately. Poll with `runs.get()` when you're ready for the result.
103
+
104
+ ```python
105
+ import time
106
+ from tinyfish import TinyFish, RunStatus
107
+
108
+ client = TinyFish()
109
+
110
+ queued = client.agent.queue(
111
+ goal="Extract the top 5 headlines", # required — what to do on the page
112
+ url="https://news.ycombinator.com", # required — URL to open
113
+ browser_profile=None, # optional — "lite" (default) or "stealth"
114
+ proxy_config=None, # optional — proxy settings
115
+ )
116
+ print(f"Run started: {queued.run_id}")
117
+
118
+ # Poll for completion
119
+ while True:
120
+ run = client.runs.get(queued.run_id)
121
+ if run.status in (RunStatus.COMPLETED, RunStatus.FAILED):
122
+ break
123
+ time.sleep(5)
124
+
125
+ print(run.result)
126
+ ```
127
+
128
+ **Returns `AgentRunAsyncResponse`:**
129
+
130
+ | Field | Type | Description |
131
+ |-------|------|-------------|
132
+ | `run_id` | `str \| None` | Run ID to poll with `runs.get()` |
133
+ | `error` | `RunError \| None` | Error if queuing itself failed |
134
+
135
+ ---
136
+
137
+ ### `agent.stream()` — real-time events
138
+
139
+ Opens a Server-Sent Events stream. You get live progress updates as the agent works, plus a WebSocket URL for a live browser preview.
140
+
141
+ ```python
142
+ from tinyfish import TinyFish, CompleteEvent, ProgressEvent
143
+
144
+ client = TinyFish()
145
+
146
+ with client.agent.stream(
147
+ goal="Extract the top 5 headlines", # required — what to do on the page
148
+ url="https://news.ycombinator.com", # required — URL to open
149
+ browser_profile=None, # optional — "lite" (default) or "stealth"
150
+ proxy_config=None, # optional — proxy settings
151
+ on_started=lambda e: print(f"Started: {e.run_id}"), # optional — called when run starts
152
+ on_streaming_url=lambda e: print(f"Watch: {e.streaming_url}"), # optional — called with live browser URL
153
+ on_progress=lambda e: print(f" > {e.purpose}"), # optional — called on each step
154
+ on_heartbeat=lambda e: None, # optional — called on keepalive pings
155
+ on_complete=lambda e: print(f"Done: {e.status}"), # optional — called when run finishes
156
+ ) as stream:
157
+ for event in stream:
158
+ # Callbacks fire automatically during iteration.
159
+ # You can also inspect events directly:
160
+ if isinstance(event, CompleteEvent):
161
+ print(event.result_json)
162
+ ```
163
+
164
+ **Returns `AgentStream`** — a context manager you iterate over. Events arrive in order: `STARTED` → `STREAMING_URL` → `PROGRESS` (repeated) → `COMPLETE`.
165
+
166
+ See the [Streaming Guide](docs/streaming-guide.md) for the full event lifecycle, event types, and advanced patterns.
167
+
168
+ ---
169
+
170
+ ### `runs.get()` — retrieve a single run
171
+
172
+ Fetch the full details of a run by its ID.
173
+
174
+ ```python
175
+ run = client.runs.get(
176
+ "run_abc123", # required — the run ID
177
+ )
178
+
179
+ print(run.status) # PENDING, RUNNING, COMPLETED, FAILED, CANCELLED
180
+ print(run.result)
181
+ print(run.goal)
182
+ print(run.streaming_url) # live browser URL (while RUNNING)
183
+ print(run.browser_config) # proxy/browser settings that were used
184
+ ```
185
+
186
+ **Returns `Run`:**
187
+
188
+ | Field | Type | Description |
189
+ |-------|------|-------------|
190
+ | `run_id` | `str` | Unique identifier |
191
+ | `status` | `RunStatus` | `PENDING`, `RUNNING`, `COMPLETED`, `FAILED`, `CANCELLED` |
192
+ | `goal` | `str` | The goal that was given |
193
+ | `result` | `dict \| None` | Extracted data (`None` if not completed) |
194
+ | `error` | `RunError \| None` | Error details (`None` if succeeded) |
195
+ | `streaming_url` | `str \| None` | Live browser URL (available while running) |
196
+ | `browser_config` | `BrowserConfig \| None` | Proxy/browser settings used |
197
+ | `created_at` | `datetime` | When the run was created |
198
+ | `started_at` | `datetime \| None` | When execution started |
199
+ | `finished_at` | `datetime \| None` | When execution finished |
200
+
201
+ **Raises:** `ValueError` if `run_id` is empty. `NotFoundError` if no run exists with that ID.
202
+
203
+ ---
204
+
205
+ ### `runs.list()` — list and filter runs
206
+
207
+ List runs with optional filtering, sorting, and cursor-based pagination. All parameters are optional.
208
+
209
+ ```python
210
+ from tinyfish import RunStatus, SortDirection
211
+
212
+ response = client.runs.list(
213
+ status=RunStatus.COMPLETED, # optional — filter by status
214
+ goal="headlines", # optional — filter by goal text
215
+ created_after="2025-01-01T00:00:00Z", # optional — ISO 8601 lower bound
216
+ created_before="2025-12-31T23:59:59Z", # optional — ISO 8601 upper bound
217
+ sort_direction=SortDirection.DESC, # optional — "asc" or "desc"
218
+ limit=10, # optional — max runs per page
219
+ cursor=None, # optional — pagination cursor from previous response
220
+ )
221
+
222
+ for run in response.data:
223
+ print(f"{run.run_id} | {run.goal}")
224
+
225
+ # Pagination
226
+ if response.pagination.has_more:
227
+ next_page = client.runs.list(cursor=response.pagination.next_cursor)
228
+ ```
229
+
230
+ **Returns `RunListResponse`:**
231
+
232
+ | Field | Type | Description |
233
+ |-------|------|-------------|
234
+ | `data` | `list[Run]` | List of runs |
235
+ | `pagination.total` | `int` | Total runs matching filters |
236
+ | `pagination.has_more` | `bool` | Whether more pages exist |
237
+ | `pagination.next_cursor` | `str \| None` | Pass to `cursor=` for the next page |
238
+
239
+ See the [Pagination Guide](docs/pagination-guide.md) for full pagination loop examples.
240
+
241
+ ---
242
+
243
+ ## Sync vs Async
244
+
245
+ Use `AsyncTinyFish` when you're in an async context (FastAPI, aiohttp, etc.):
246
+
247
+ **Sync:**
248
+
249
+ ```python
250
+ from tinyfish import TinyFish
251
+
252
+ client = TinyFish()
253
+ response = client.agent.run(goal="...", url="...")
254
+ ```
255
+
256
+ **Async:**
257
+
258
+ ```python
259
+ from tinyfish import AsyncTinyFish
260
+
261
+ client = AsyncTinyFish()
262
+ response = await client.agent.run(goal="...", url="...")
263
+ ```
264
+
265
+ All five methods (`agent.run()`, `agent.queue()`, `agent.stream()`, `runs.get()`, `runs.list()`) work the same way — same parameters, just `await`-ed.
266
+
267
+ ## Configuration
268
+
269
+ ### Client options
270
+
271
+ ```python
272
+ client = TinyFish(
273
+ api_key="your-api-key", # optional — or set TINYFISH_API_KEY env var
274
+ base_url="https://agent.tinyfish.ai", # optional — default shown
275
+ timeout=600.0, # optional — seconds (default: 600)
276
+ max_retries=2, # optional — retry attempts (default: 2)
277
+ )
278
+ ```
279
+
280
+ The SDK retries `408`, `429`, and `5xx` errors automatically with exponential backoff (0.5s multiplier, max 8s wait).
281
+
282
+ ### Browser profiles
283
+
284
+ Control the browser environment with `browser_profile`:
285
+
286
+ - **`lite`** (default) — fast, lightweight. Good for most sites.
287
+ - **`stealth`** — anti-detection mode. Use for sites with bot protection.
288
+
289
+ ```python
290
+ from tinyfish import BrowserProfile
291
+
292
+ response = client.agent.run(
293
+ goal="...",
294
+ url="...",
295
+ browser_profile=BrowserProfile.STEALTH,
296
+ )
297
+ ```
298
+
299
+ ### Proxy configuration
300
+
301
+ Route requests through a proxy, optionally pinned to a country:
302
+
303
+ ```python
304
+ from tinyfish import ProxyConfig, ProxyCountryCode
305
+
306
+ response = client.agent.run(
307
+ goal="...",
308
+ url="...",
309
+ proxy_config=ProxyConfig(enabled=True, country_code=ProxyCountryCode.US),
310
+ )
311
+ ```
312
+
313
+ Available countries: `US`, `GB`, `CA`, `DE`, `FR`, `JP`, `AU`.
314
+
315
+ See the [Proxy & Browser Profiles Guide](docs/proxy-and-browser-profiles.md) for more details.
316
+
317
+ ## Error handling
318
+
319
+ ```python
320
+ from tinyfish import TinyFish, AuthenticationError, RateLimitError, SDKError
321
+
322
+ client = TinyFish()
323
+
324
+ try:
325
+ response = client.agent.run(goal="...", url="...")
326
+ except AuthenticationError:
327
+ print("Invalid API key")
328
+ except RateLimitError:
329
+ print("Rate limited (retries exhausted)")
330
+ except SDKError:
331
+ print("Something else went wrong")
332
+ ```
333
+
334
+ The SDK automatically retries transient errors (`408`, `429`, `5xx`) up to `max_retries` times with exponential backoff. Non-retryable errors (`401`, `400`, `404`) raise immediately.
335
+
336
+ For the full exception hierarchy and internal architecture, see [docs/internal/exceptions-and-errors-guide.md](docs/internal/exceptions-and-errors-guide.md).
337
+
338
+ ## Guides
339
+
340
+ - [Streaming Guide](docs/streaming-guide.md) — event lifecycle, callbacks vs iteration, event type reference
341
+ - [Proxy & Browser Profiles](docs/proxy-and-browser-profiles.md) — stealth mode, proxy countries
342
+ - [Pagination Guide](docs/pagination-guide.md) — filtering, sorting, cursor-based pagination
343
+ - [Exceptions & Error Handling (internal)](docs/internal/exceptions-and-errors-guide.md) — layer-by-layer architecture
344
+ - [Testing Guide](tests/testing_guide.md) — running and writing tests
@@ -1,7 +1,8 @@
1
1
  [project]
2
2
  name = "tinyfish"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  description = "Official Python SDK for the TinyFish API"
5
+ readme = "README.md"
5
6
  requires-python = ">=3.11"
6
7
  dependencies = [
7
8
  "httpx>=0.27.0",
@@ -322,7 +322,7 @@ wheels = [
322
322
 
323
323
  [[package]]
324
324
  name = "tinyfish"
325
- version = "0.2.2"
325
+ version = "0.2.3"
326
326
  source = { editable = "." }
327
327
  dependencies = [
328
328
  { name = "httpx" },
tinyfish-0.2.2/PKG-INFO DELETED
@@ -1,8 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: tinyfish
3
- Version: 0.2.2
4
- Summary: Official Python SDK for the TinyFish API
5
- Requires-Python: >=3.11
6
- Requires-Dist: httpx>=0.27.0
7
- Requires-Dist: pydantic>=2.0.0
8
- Requires-Dist: tenacity>=8.0.0
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