You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add ontology navigation to the SDK core for DQL authoring
Promote ontology introspection out of the CLI layer into a storage-agnostic
diffbot.Ontology class so library consumers (e.g. langchain) can build valid
DQL on the fly, without depending on the disk-backed CLI cache.
- New diffbot/ontology.py: Ontology with types/composites/enums/taxonomies,
fields_for, filter_fields, taxonomy_values, enum_values, find_named,
format_field, plus from_json/from_path. Pure; imposes no caching policy.
- Client: dql_fetch_ontology() (sync + async) downloads and returns an
Ontology; add async DiffbotAsync.dql_parallel() to mirror the sync one.
- cli/ontology.py now delegates to Ontology, keeping its ~/.diffbot disk cache
and existing module API unchanged.
- tests/test_ontology.py covers the core, the HTTP fetch, and async parallel.
Also includes a pre-existing, in-progress credential-resolution refactor that
was already present in the working tree (diffbot/_auth.py and its consumers in
cli/_common.py, cli/dql.py, conftest, tests, README); __init__.py carries both
sets of changes, so they commit together.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
With either in place, resolve the token and pass it to the client:
45
+
46
+
```python
47
+
from diffbot import Diffbot, resolve_token
48
+
49
+
db = Diffbot(token=resolve_token()) # from env var or ~/.diffbot/credentials
50
+
data = db.extract("https://www.example.com")
51
+
```
52
+
27
53
### Extract structured content
28
54
```python
29
55
from diffbot import Diffbot
@@ -166,7 +192,15 @@ asyncio.run(main())
166
192
167
193
## CLI
168
194
169
-
This library also includes a CLI.
195
+
This library also includes a CLI exposed as the `db` command.
196
+
197
+
To make `db` available from anywhere, install it as an isolated tool with [uv](https://docs.astral.sh/uv/):
198
+
199
+
```bash
200
+
uv tool install .
201
+
```
202
+
203
+
This drops a `db` executable into `~/.local/bin` (ensure it is on your `PATH`). Use `--force` to reinstall or upgrade after changes, or `--editable` to have source edits take effect immediately. Alternatively, a plain `pip install .` (or `pip install -e .`) also installs the `db` entry point into the active environment.
170
204
171
205
```bash
172
206
export DIFFBOT_API_TOKEN=your-token-here
@@ -189,7 +223,9 @@ Run the mock test suite:
189
223
python -m pytest
190
224
```
191
225
192
-
Run live integration tests against the real API (requires a valid token):
226
+
Run live integration tests against the real API (requires a valid token).
227
+
The token is resolved the same way as everywhere else — the `DIFFBOT_API_TOKEN`
228
+
environment variable or `~/.diffbot/credentials`:
193
229
```bash
194
-
DIFFBOT_TOKEN=your_token python -m pytest -m live
230
+
DIFFBOT_API_TOKEN=your_token python -m pytest -m live
0 commit comments