Skip to content

Commit 13cd90d

Browse files
shixishclaude
andcommitted
docs: 3.3.0 changelog, S1 leftovers, mark response TypedDicts landed; type AskChunk in the SSE parser
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 97d53e4 commit 13cd90d

4 files changed

Lines changed: 97 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,55 @@
11
# Changelog
22

3+
## 3.3.0 (unreleased)
4+
5+
Response types, a pyright gate, and two small methods that complete existing
6+
workflows. Additive minor: no wire changes. The package version in
7+
`pyproject.toml` is bumped at release time.
8+
9+
### Added
10+
11+
- Response `TypedDict`s (stdlib, `total=False`, no Pydantic, Python 3.9-compatible),
12+
exported from `diffbot`: `DqlResponse`/`DqlEntity`, `WebSearchResponse`/
13+
`WebSearchResult`, `EntitiesResponse`, `ExtractResponse` and per-API
14+
`ArticleExtractResponse`, `ProductExtractResponse`, ... with their object types,
15+
`CrawlJob`, `CrawlDataRecord`, `AccountResponse`, `AskChunk`.
16+
- `account(days=None)` and `verify_token()` (sync and async): `GET /v4/account`.
17+
`verify_token()` calls it with `days=1`; only an auth failure (401/403) returns
18+
`False`, every other error propagates. The account response carries `token` and
19+
`childTokens`: don't log it whole.
20+
- `crawl_download(name, *, format="json", type=None, num=None)` (sync and async):
21+
`GET /v3/crawl/data`. `format="csv"` returns `str`, otherwise a list of records.
22+
The crawl watcher now uses it. For tools that can't block, the recommended
23+
pattern is `crawl(..., watch=False)` -> `crawl_get_job` -> `crawl_download`.
24+
- `extract()` keyword-only options after `fmt`: `timeout` (server-side fetch timeout
25+
in ms, default still 30000), `mode` (overrides the `fmt="markdown"` -> `llm`
26+
mapping), `fields` (sequence, comma-joined; per-API `Literal` names), `fallback`,
27+
`discussion`, `paging`, `max_pages`, `natural_language`, `summary_num_sentences`,
28+
`max_tags`, `tag_confidence`, `category_confidence`, `use_proxy`, and `extra`
29+
for anything else (`proxy`/`proxyAuth`; keys that collide with a named option or
30+
`token`/`url` raise `ValidationError`). When you set `timeout`, the per-call
31+
transport timeout is raised to at least `timeout + 10s` (never lowered).
32+
- Dev: `pyright` (basic on `src/`, strict on `types.py`) plus `tests/typing`
33+
`assert_type` checks, run in `tests.yml`.
34+
35+
### Fixed
36+
37+
- `dql(format="csv")` and `dql(format="jsonl")` without `raw=True` crashed in
38+
`response.json()`. `csv` now returns `str`, `xls`/`xlsx` return `bytes`, and
39+
`jsonl` returns an iterator of entities (`AsyncIterator` from the async client).
40+
`raw=True` is unchanged (undecoded `bytes`).
41+
42+
### Changed (type-level only)
43+
44+
- Return annotations changed from `Dict[str, Any]` to the TypedDicts above
45+
(`dql`, `extract`, `web_search`, `entities`, `crawl_list_jobs`, `crawl_get_job`),
46+
and `dql`/`extract`/`crawl_download` gained `@overload`s. Runtime values are
47+
unchanged. A type checker may now flag keys the types don't declare; wrap the
48+
value in `typing.cast(Dict[str, Any], resp)` as the escape hatch. `dql_parallel`
49+
returns `List[Any]` (each element's type follows its own call).
50+
- `crawl_get_job` still returns `{}` for a missing job (the TypeScript SDK returns
51+
`undefined`); unchanged on purpose.
52+
353
## 3.2.0 (unreleased)
454

555
Shared transport foundation, a sync/async de-duplication refactor, and DQL sent

‎PHASE0_LEFTOVERS.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ Unchanged by the move to POST. Covered by the existing raw-mode tests.
3232
Adding `dql_fetch_ontology_text()` and `dql_refresh_ontology_async()` to close the
3333
Python/TypeScript asymmetry is scheduled for **S2** (Python 3.4.0).
3434

35-
## 5. Response TypedDicts: scheduled for S1
35+
## 5. Response TypedDicts: landed in S1
3636

37-
Request-side `TypedDict`/`Literal` aliases landed in `src/diffbot/types.py`.
37+
Request-side `TypedDict`/`Literal` aliases landed in `src/diffbot/types.py` with Phase 0.
3838
Response shapes (`DqlResponse`, `WebSearchResponse`, `ExtractResponse`, `CrawlJob`,
39-
`AccountResponse`, `AskChunk`, ...) are scheduled for **S1** (Python 3.3.0),
40-
together with a pyright CI gate so they are checked from day one.
39+
`AccountResponse`, `AskChunk`, ...) land in S1 (Python 3.3.0, branch `feat/sdk-s1`)
40+
together with the pyright CI gate, so they are checked from day one.

‎S1_LEFTOVERS.md‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# S1 leftovers (Python)
2+
3+
S1 (plan §5, §6, §8) landed on `feat/sdk-s1`. Notes on what is deliberately smaller than
4+
the plan's wording, and what is unverified.
5+
6+
## Deliberately narrower
7+
8+
- **Overloads live on the client methods** (`Diffbot`/`DiffbotAsync` `dql`, `extract`,
9+
`crawl_download`), the public surface. The module-level shared implementations in
10+
`kg.py`/`extract.py`/`crawl.py` return `Any` to avoid duplicating ~50 overloads.
11+
- **Per-API extract options use `**options: Unpack[...]` in the overloads** (a
12+
`TYPE_CHECKING`-only import of `typing_extensions.Unpack`; no runtime dependency).
13+
At runtime the implementation takes `**options` and rejects unknown names with
14+
`TypeError`. Every option is accepted for every API at runtime; only the type
15+
level restricts them per API.
16+
- **Transport timeout is raised only when the caller sets `timeout`.** With the default
17+
30000 ms and the default 30 s client timeout the two are still equal, as before.
18+
- `dql_parallel` returns `List[Any]` (heterogeneous per-call formats).
19+
- `EntitiesResponse` mirrors TS `Pick<..., "entities" | "sentiment">`; `errors` is not declared.
20+
- `CrawlDataRecord` is a best-effort shape (the crawl data JSON is example-only in the
21+
docs); keep it open to change. The TypeScript counterpart did not exist yet when this
22+
was written, so field-for-field parity with its `CrawlDataRecord` is unchecked.
23+
24+
## Unverified here
25+
26+
- Live tests (`pytest -m live`) were not run against the real API (no token resolved in
27+
the build environment); `test_live_verify_token_rejects_a_bad_token` was.
28+
The live crawl test (start/poll/download/delete) is therefore unexercised.
29+
- Open question from plan §11: DQL POST parity (jsonl/csv/xlsx with `exportspec`,
30+
JSON strings vs numbers in `extra`) should be confirmed with the Diffbot contact
31+
before release.
32+
33+
## Not in S1 (see plan §2/§8)
34+
35+
S2 items (DQL named params, crawl-create options, `nlp()`, web-search multi-value
36+
`text` + `snippet_length` validation, ontology text/async parity) and everything marked
37+
Out.

‎src/diffbot/ask.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import TYPE_CHECKING, Any, AsyncIterator, Dict, Iterator, List, Optional
66

77
from .errors import ValidationError
8-
from .types import ChatMessage, ResponseFormat
8+
from .types import AskChunk, ChatMessage, ResponseFormat
99

1010
if TYPE_CHECKING:
1111
from .client import Diffbot, DiffbotAsync
@@ -76,12 +76,14 @@ def _build_payload(
7676

7777
def _parse_chunk(line: str):
7878
try:
79-
chunk = json.loads(line.replace("data: ", ""))
79+
chunk: AskChunk = json.loads(line.replace("data: ", ""))
8080
except json.JSONDecodeError:
8181
return None
8282
choices = chunk.get("choices")
83-
if choices and choices[0].get("delta", {}).get("content"):
84-
return choices[0]["delta"]["content"]
83+
if choices:
84+
content = choices[0].get("delta", {}).get("content")
85+
if content:
86+
return content
8587
return None
8688

8789

0 commit comments

Comments
 (0)