Skip to content

Commit b022907

Browse files
shixishclaude
andcommitted
docs: note two deliberately deferred Phase 0 items; add an Unreleased changelog entry
PHASE0_LEFTOVERS.md: no standalone endpoint-registry data structure (same call as the TypeScript SDK on this branch — Phase 0 adds zero new endpoints, so a registry has no second consumer yet), response headers surfaced on the error path only (success-path headers deferred to Phase 6's dql_report, which doesn't exist yet to shape it against), confirmation that Python's dql(raw=True) never had the TypeScript SDK's binary-corruption bug, the ontology async/text asymmetry being Phase 1 scope rather than Phase 0, and the scope of the TypedDict/Literal additions (existing request parameters, not response shapes — this repo has no type-checking CI gate to shape response overlays against). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 9902bc3 commit b022907

2 files changed

Lines changed: 154 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Changelog
2+
3+
## Unreleased
4+
5+
Phase 0 of the Diffbot SDKs' full HTTP API coverage plan: shared transport
6+
foundation and a sync/async de-duplication refactor. No new API endpoints
7+
land in this phase, and the package version is unchanged (per the plan's
8+
scope, version bumps are deferred).
9+
10+
### Added
11+
12+
- Per-host base URL options: `api_base`, `kg_base`, `llm_base`, `nlp_base` on
13+
both `Diffbot` and `DiffbotAsync`. The older per-endpoint options
14+
(`analyze_url`, `crawler_url`, `llm_url`, `web_search_url`, `nlp_url`,
15+
`dql_url`, `ontology_url`) still work and win over the matching base when
16+
both are set.
17+
- Repeated query parameters: handler param builders now declare
18+
`Sequence`-valued params explicitly (httpx already encoded them as repeated
19+
keys; this makes it a documented, tested capability).
20+
- `client.request(method, url, ...)` on both clients: `DELETE` + arbitrary
21+
method/body/`Content-Type`, form-encoded (`data=`) and raw (`content=`)
22+
bodies, a per-call `timeout` override separate from the client default, and
23+
a `follow_redirects` override.
24+
- A default-on retry policy (`RetryPolicy` dataclass, `retry` client option)
25+
for `429`/`5xx`/connection errors, with backoff, jitter, and `Retry-After`
26+
support, capped at 3 attempts by default. Disable with `retry=False`, or
27+
opt a single call out with `retryable=False` (used internally by
28+
`crawl_delete_job`/`crawl_delete_job_async`, a GET-shaped mutation that must
29+
never be retried blindly).
30+
- `NotFoundError` (404) and `JobError`, both subclassing `APIError` so
31+
existing `except APIError` call sites are unaffected.
32+
- `APIError.headers` (and subclasses), populated from the error response.
33+
- Additive `TypedDict`/`Literal` type aliases in `diffbot.types`:
34+
`ChatMessage`, `ResponseFormat`, `ExportFormat`, `SnippetLength` — used in
35+
`ask()`/`ask_json()`/`dql()`/`web_search()` signatures. No Pydantic, no
36+
runtime behavior change.
37+
38+
### Fixed
39+
40+
- `ask()`/`ask_json()` (sync and async): a non-2xx response (e.g. 401, 429)
41+
while streaming now raises `AuthError`/`RateLimitError` as documented,
42+
instead of `httpx.ResponseNotRead`. The error body is now read before
43+
raising.
44+
- `crawl()`'s job-failure path now raises `JobError` (carrying the job name)
45+
instead of a synthesized `APIError(500, ...)`.
46+
47+
### Internal
48+
49+
- Sync/async de-duplication: `Diffbot`/`DiffbotAsync._raise_for_status` and
50+
the repeated `client._http.get(...)` + raise pattern in every handler
51+
module are replaced by shared helpers in a new `_transport.py`, used by
52+
both clients through `client.request()`.

‎PHASE0_LEFTOVERS.md‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Phase 0 leftovers (Python)
2+
3+
Everything in the Phase 0 scope (`py-prompt.md`, opus-plan.md §6 "Phase 0 — Foundation",
4+
§3.2–3.4, §3.7) landed. A few items are deliberately smaller than the plan's framing, or
5+
were already true on the Python side without a code change — documented here rather than
6+
silently shipped (or silently skipped) without explanation, mirroring the TypeScript
7+
SDK's own `PHASE0_LEFTOVERS.md` on this branch.
8+
9+
## 1. No literal "endpoint registry" data structure
10+
11+
opus-plan §3.2/§6 0.1 frames the per-host base URLs as part of "an endpoint registry +
12+
per-host base URLs." What landed is the per-host base URL resolution
13+
(`api_base`/`kg_base`/`llm_base`/`nlp_base`, old `*_url` options winning aliases) directly
14+
in `client.py` — there's no separate data structure mapping `(operation) -> {path,
15+
auth_style, retryable}`.
16+
17+
This mirrors the TypeScript SDK's same call on this branch: Phase 0 adds zero new
18+
endpoints, so the only thing a registry would currently serve is base-URL resolution
19+
(done) and a `retryable` flag (done ad hoc, as an explicit `retryable=False` at the one
20+
call site that needs it — `crawl_delete_job`/`crawl_delete_job_async`). Building a
21+
generic per-operation table with no second or third consumer risked guessing the wrong
22+
shape for Phase 1+ (Account, Enhance, Bulk, Custom API, ...), which is where a real
23+
registry starts paying for itself. Revisit when Phase 1 lands.
24+
25+
## 2. Response headers: error path only, not success path
26+
27+
opus-plan §6 0.6 asks for "response headers surfaced to callers," calling out an
28+
`include_headers` option or a `*_raw` variant returning `(body, headers)`.
29+
30+
What landed: every error response's headers are attached to `APIError` (and its
31+
subclasses `AuthError`, `NotFoundError`, `RateLimitError`, `JobError`) via a new
32+
`headers` field, populated in `_transport.raise_for_status()`. Tested in
33+
`tests/test_transport.py`'s `raise_for_status` tests.
34+
35+
What didn't land: a generic opt-in mechanism for a *successful* response's headers. The
36+
plan's own stated motivation is `X-Diffbot-CoverageReportId` on a DQL coverage report
37+
(opus-plan §3.4, §6 0.6's "prerequisite for DQL coverage reports") — that's a Phase 6
38+
operation (`dql_report`) that doesn't exist yet. Building the success-path mechanism now,
39+
with no real caller to shape it against, risked the same guessing problem as the
40+
registry above. Build it alongside `dql_report`/`dql_report_by_id` in Phase 6. Matches
41+
the TypeScript SDK's identical call on this branch.
42+
43+
## 3. `dql(raw=True)` binary correctness: no bug existed on the Python side
44+
45+
opus-plan §3.3/§6 0.5 frames this as "binary + text response reads" plus a concrete bug:
46+
the TypeScript SDK's `dql()` read the body as text and re-encoded it with
47+
`TextEncoder`, corrupting `xls`/`xlsx` exports. The audit explicitly notes Python's byte
48+
path was already correct (`kg.py` returning `response.content` directly). No code change
49+
was needed here beyond routing the call through the shared `client.request()` helper,
50+
which preserves the same `response.content` / `response.json()` split. Covered by the
51+
existing `test_dql.py` raw-mode tests (unchanged) plus the new per-host-base tests.
52+
53+
## 4. Ontology asymmetries are Phase 1, not Phase 0
54+
55+
opus-plan §5.2's core-surface-mapping row for the ontology endpoint lists adding
56+
`dql_fetch_ontology_text()` and `dql_refresh_ontology_async()` to close the existing
57+
Python/TypeScript asymmetry (`dql_refresh_ontology` has no async twin; TypeScript has no
58+
raw-text fetch). That row is scoped under "Phase 1 — Account + token verification," not
59+
Phase 0, and the `py-prompt.md` Phase 0 scope list does not mention it. Left alone.
60+
61+
## 5. TypedDict/Literal annotations: existing-surface request parameters only
62+
63+
`py-prompt.md` asks for "matching TypedDict(total=False)/Literal annotations, additive,
64+
no Pydantic" as the Python counterpart to the TypeScript SDK's much larger Phase 0 type
65+
safety push (vendored OpenAPI, generated response schemas, per-handler overloads). The
66+
typesafety-revision page's override on this point is specifically about TypeScript's
67+
approach; opus-plan's own phasing (§6, Phase 7 "typed responses... land as a dedicated
68+
minor, not bundled with each endpoint" — the risk being a `TypedDict` claiming a field
69+
that a future server response omits) argues for keeping Python's response shapes as
70+
plain `dict`/`bytes` for now, which is what shipped.
71+
72+
What landed: `src/diffbot/types.py` adds `ChatMessage`, `ResponseFormatType`,
73+
`ResponseFormat`, `ExportFormat`, `SnippetLength`, and `CrawlJobStatusCode` (the last
74+
documents the numeric status codes `crawl.py` already branches on; not yet wired into a
75+
public signature since no handler takes a status code as an input). These are wired into
76+
the existing `ask()`/`ask_json()`/`dql()`/`web_search()` request-parameter signatures in
77+
both `client.py` and the handler modules — purely additive, no runtime behavior change
78+
(verified by the full test suite staying green before and after).
79+
80+
What didn't land: `TypedDict` overlays for *response* shapes (`DqlResponse`,
81+
`WebSearchResponse`, `NlpResponse`, `ExtractResponse`, a `CrawlJob`/`JobStatus` pair,
82+
`Ontology`'s wire format). This repo has no mypy/type-checking gate in CI today (checked
83+
`.github/workflows/tests.yml`), so there is no second consumer to shape these against
84+
yet, and retrofitting them risks exactly the staleness opus-plan §3.5/§6 Phase 7 warns
85+
about. Revisit if/when Enhance (Phase 2) introduces the first genuinely new typed
86+
response and a type-checking CI gate is added.
87+
88+
## Everything else
89+
90+
The sync/async de-duplication refactor (shared `_transport.py` request/response
91+
helpers), per-host bases, repeated query parameters, DELETE + arbitrary method/body/
92+
Content-Type, form-encoded and raw bodies, per-call timeout, the default-on retry policy
93+
with per-call `retryable=False` opt-out, `NotFoundError`/`JobError` (both subclassing
94+
`APIError`), and the streaming `ask()` `ResponseNotRead` fix (sync and async, with tests
95+
using a real byte-stream mock transport so the fix is actually exercised) all landed —
96+
see the commit log for the breakdown and `tests/test_transport.py`, `tests/test_client.py`,
97+
`tests/test_ask.py`, `tests/test_crawl.py`, `tests/test_dql.py` for coverage.
98+
99+
The TypeScript SDK's two fixes (dql raw-mode binary corruption, crawl CSV quote-aware
100+
parsing) and its full type-safety push (vendored OpenAPI, generated types, per-handler
101+
overloads, typescript-eslint strict-type-checked) are not part of this checkout; they
102+
were implemented first on the matching TypeScript branch per the assignment.

0 commit comments

Comments
 (0)