diffbot 3.0.0__py3-none-any.whl → 3.1.0__py3-none-any.whl

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.
diffbot/__init__.py CHANGED
@@ -13,7 +13,7 @@ def _installed_version(dist: str):
13
13
 
14
14
 
15
15
  # The distribution was renamed from diffbot-python to diffbot. The final
16
- # diffbot-python release ships this same code (see legacy/diffbot-python), so
16
+ # diffbot-python release ships this same code (tag legacy-diffbot-python-v0.3.0), so
17
17
  # fall back to its version when that's what is installed.
18
18
  _legacy_version = _installed_version("diffbot-python")
19
19
  # "0.0.0" when not installed (e.g. running from a source tree).
diffbot/cli/__init__.py CHANGED
@@ -359,16 +359,17 @@ def _strip_markdown(text: str) -> str:
359
359
  @click.option("-n", "--num-results", type=int, default=None, help="Number of results to return")
360
360
  @click.option("-m", "--max-tokens", type=int, default=None, help="Limit total response tokens (for agentic use cases)")
361
361
  @click.option("-f", "--format", "fmt", type=click.Choice(["list", "json", "text"]), default="list", help="Output format (text is plain/agent-friendly)")
362
- def web_search(query: str, num_results, max_tokens, fmt: str):
362
+ @click.option("-s", "--snippet-length", type=click.Choice(["short", "medium", "long", "full"], case_sensitive=False), default=None, help="How much of each page's matching content to return (default: long). short keeps a result to ~1-1.5 KB; full returns the whole stored page, for url: lookups")
363
+ def web_search(query: str, num_results, max_tokens, fmt: str, snippet_length):
363
364
  """Search the web using the Diffbot LLM web search API."""
364
365
  db = get_client()
365
366
  try:
366
367
  if is_interactive:
367
368
  with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}"), transient=True) as progress:
368
369
  progress.add_task(description="Searching...", total=None)
369
- data = db.web_search(query, num_results=num_results, max_tokens=max_tokens)
370
+ data = db.web_search(query, num_results=num_results, max_tokens=max_tokens, snippet_length=snippet_length)
370
371
  else:
371
- data = db.web_search(query, num_results=num_results, max_tokens=max_tokens)
372
+ data = db.web_search(query, num_results=num_results, max_tokens=max_tokens, snippet_length=snippet_length)
372
373
 
373
374
  if fmt == "json":
374
375
  sys.stdout.write(json.dumps(data, indent=2))
diffbot/client.py CHANGED
@@ -197,9 +197,22 @@ class Diffbot:
197
197
  """Download the ontology and return it as a queryable Ontology (no caching)."""
198
198
  return _dql_fetch_ontology(self)
199
199
 
200
- def web_search(self, text: str, *, num_results: Optional[int] = None, max_tokens: Optional[int] = None) -> Dict[str, Any]:
201
- """Search the web via the Diffbot LLM web search API."""
202
- return _web_search(self, text, num_results=num_results, max_tokens=max_tokens)
200
+ def web_search(
201
+ self,
202
+ text: str,
203
+ *,
204
+ num_results: Optional[int] = None,
205
+ max_tokens: Optional[int] = None,
206
+ snippet_length: Optional[str] = None,
207
+ ) -> Dict[str, Any]:
208
+ """Search the web via the Diffbot LLM web search API.
209
+
210
+ snippet_length: "short", "medium", "long" or "full" — how much of each
211
+ page's matching content to return. Omit for the API default (long).
212
+ "full" returns the whole stored page (reranking is disabled for it);
213
+ use it with a url:<URL> query.
214
+ """
215
+ return _web_search(self, text, num_results=num_results, max_tokens=max_tokens, snippet_length=snippet_length)
203
216
 
204
217
  def entities(self, text: str, *, lang: str = "auto") -> Dict[str, Any]:
205
218
  """Identify and resolve entities and sentiment in text using the Diffbot NLP API.
@@ -349,9 +362,22 @@ class DiffbotAsync:
349
362
  """Download the ontology and return it as a queryable Ontology (no caching)."""
350
363
  return await _dql_fetch_ontology_async(self)
351
364
 
352
- async def web_search(self, text: str, *, num_results: Optional[int] = None, max_tokens: Optional[int] = None) -> Dict[str, Any]:
353
- """Search the web via the Diffbot LLM web search API."""
354
- return await _web_search_async(self, text, num_results=num_results, max_tokens=max_tokens)
365
+ async def web_search(
366
+ self,
367
+ text: str,
368
+ *,
369
+ num_results: Optional[int] = None,
370
+ max_tokens: Optional[int] = None,
371
+ snippet_length: Optional[str] = None,
372
+ ) -> Dict[str, Any]:
373
+ """Search the web via the Diffbot LLM web search API.
374
+
375
+ snippet_length: "short", "medium", "long" or "full" — how much of each
376
+ page's matching content to return. Omit for the API default (long).
377
+ "full" returns the whole stored page (reranking is disabled for it);
378
+ use it with a url:<URL> query.
379
+ """
380
+ return await _web_search_async(self, text, num_results=num_results, max_tokens=max_tokens, snippet_length=snippet_length)
355
381
 
356
382
  async def entities(self, text: str, *, lang: str = "auto") -> Dict[str, Any]:
357
383
  """Identify and resolve entities and sentiment in text using the Diffbot NLP API.
diffbot/web_search.py CHANGED
@@ -14,6 +14,7 @@ def web_search(
14
14
  *,
15
15
  num_results: Optional[int] = None,
16
16
  max_tokens: Optional[int] = None,
17
+ snippet_length: Optional[str] = None,
17
18
  ) -> Dict[str, Any]:
18
19
  headers = {"Authorization": f"Bearer {client.token}"}
19
20
  params: Dict[str, Any] = {"text": text}
@@ -21,6 +22,11 @@ def web_search(
21
22
  params["size"] = num_results
22
23
  if max_tokens is not None:
23
24
  params["maxTokens"] = max_tokens
25
+ if snippet_length is not None:
26
+ params["snippetLength"] = snippet_length.upper()
27
+ if params["snippetLength"] == "FULL":
28
+ # the reranker always chunks; only the unranked path returns the stored page
29
+ params["rerank"] = "none"
24
30
  response = client._http.get(client.web_search_url, headers=headers, params=params)
25
31
  client._raise_for_status(response)
26
32
  return response.json()
@@ -32,6 +38,7 @@ async def web_search_async(
32
38
  *,
33
39
  num_results: Optional[int] = None,
34
40
  max_tokens: Optional[int] = None,
41
+ snippet_length: Optional[str] = None,
35
42
  ) -> Dict[str, Any]:
36
43
  headers = {"Authorization": f"Bearer {client.token}"}
37
44
  params: Dict[str, Any] = {"text": text}
@@ -39,6 +46,11 @@ async def web_search_async(
39
46
  params["size"] = num_results
40
47
  if max_tokens is not None:
41
48
  params["maxTokens"] = max_tokens
49
+ if snippet_length is not None:
50
+ params["snippetLength"] = snippet_length.upper()
51
+ if params["snippetLength"] == "FULL":
52
+ # the reranker always chunks; only the unranked path returns the stored page
53
+ params["rerank"] = "none"
42
54
  response = await client._http.get(client.web_search_url, headers=headers, params=params)
43
55
  client._raise_for_status(response)
44
56
  return response.json()
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: diffbot
3
- Version: 3.0.0
3
+ Version: 3.1.0
4
4
  Summary: Python client library for Diffbot APIs
5
5
  Project-URL: Homepage, https://github.com/diffbot/diffbot-python
6
6
  Project-URL: Documentation, https://github.com/diffbot/diffbot-python#readme
@@ -224,6 +224,13 @@ results = db.web_search("diffbot knowledge graph")
224
224
  for r in results["search_results"]:
225
225
  print(r["score"], r["title"], r["pageUrl"])
226
226
  print(r["content"])
227
+
228
+ # snippet_length controls how much of each page comes back in "content":
229
+ # "short" (~1-1.5 KB per result), "medium", "long" (default), or "full"
230
+ results = db.web_search("diffbot knowledge graph", num_results=5, snippet_length="short")
231
+
232
+ # "full" with a url: query returns the whole stored page
233
+ page = db.web_search("url:https://en.wikipedia.org/wiki/Knowledge_graph", snippet_length="full")
227
234
  ```
228
235
 
229
236
  ### Entities (NLP)
@@ -385,6 +392,8 @@ db crawl-list-jobs
385
392
  db crawl-delete-job crawl-1234567890
386
393
  db web-search "diffbot knowledge graph"
387
394
  db web-search "diffbot knowledge graph" -n 5 -f json
395
+ db web-search "diffbot knowledge graph" -n 5 -s short
396
+ db web-search "url:https://en.wikipedia.org/wiki/Knowledge_graph" -s full -f json
388
397
  db entities "Apple CEO Tim Cook announced record quarterly earnings."
389
398
  db entities "Apple CEO Tim Cook announced record quarterly earnings." -f dql
390
399
  ```
@@ -408,3 +417,7 @@ environment variable or `~/.diffbot/credentials`:
408
417
  ```bash
409
418
  DIFFBOT_API_TOKEN=your_token python -m pytest -m live
410
419
  ```
420
+
421
+ ## Acknowledgements
422
+
423
+ Thanks to [@attilaolah](https://github.com/attilaolah), who published the original `diffbot` package in 2012 and looked after the name for 14 years.
@@ -1,22 +1,22 @@
1
- diffbot/__init__.py,sha256=LAZr0P760URw34JXMIcN-2fTMIELq_-IUd1gj8KgVfI,1875
1
+ diffbot/__init__.py,sha256=PmwZ25wHDva_CwchhnW8ds3N35v_1K-1yIfr2c5gDPs,1882
2
2
  diffbot/_auth.py,sha256=dzNMWqIjtG3YtRBb_EKpPRiBxvZgogxvoE0ABLvzfOk,1251
3
3
  diffbot/ask.py,sha256=taLISU0BUHzi9SwESZmgDST8PUHoLGJnI02aHngljQM,7411
4
- diffbot/client.py,sha256=k3orUmOv1RG_xHInyEt0bS0CIYyTOBW56ZDEMgvX8nc,13379
4
+ diffbot/client.py,sha256=XtqjDfGK78iZwXVmHx6F-XC5TrGL7NjOLEbZNUR0Ivk,14193
5
5
  diffbot/crawl.py,sha256=iYMFmf7HKrbefJrGg14VnlfiBFLOE_Z1pfO4Rn_cDXc,8893
6
6
  diffbot/errors.py,sha256=5-AceX5MyNVUhe9pvR_4rnQQmBhvLfwWmrRl7dRZUSg,1576
7
7
  diffbot/extract.py,sha256=R9SVxaOi4FjHOQIX5ho_75OwaJ7VdX-mdAoV_UY-lrM,1452
8
8
  diffbot/kg.py,sha256=WPvy3B_ywdoM0uEmAgN7-3uOvf4aC4l2mjS2v_tWPN4,3925
9
9
  diffbot/nlp.py,sha256=lZJW4MkjhVklIEM2OBfhc8LvresXTy7RsuImPteYsOA,1153
10
10
  diffbot/ontology.py,sha256=GWD5m2rz7ECWY6RrO1TeN3kk3DYTgmEHz6gFKASMvAU,6283
11
- diffbot/web_search.py,sha256=RSaEK0pdAdLgtilc500Mf2MNmJ1DmiYYmIlBQBWvOpE,1356
12
- diffbot/cli/__init__.py,sha256=uCngMioFdxTSeUrBxPrxepVqqwllAjXVr8W-zThcYaE,17435
11
+ diffbot/web_search.py,sha256=0LzHzngjcC-TWhBiiSODNTmgiLv15R7v7YZ_A0aE8UI,1970
12
+ diffbot/cli/__init__.py,sha256=wqvil8RiFJ21UWb8xYxwZdqGIWrBWNSqTCd79SJ4Gb4,17809
13
13
  diffbot/cli/__main__.py,sha256=5BjNuyet8AY-POwoF5rGt722rHQ7tJ0Vf0UFUfzzi-I,58
14
14
  diffbot/cli/_common.py,sha256=_s8WRukzSX3krjJW6HJmT7_3hEjNyv1i_y45tm81b2A,654
15
15
  diffbot/cli/dql.py,sha256=iIMaGysMWTScnbAHAdWei2iVUJpMV5lA1pk1E9uQg4s,11439
16
16
  diffbot/cli/entities.py,sha256=tsHKexF0b6NnsoUEZJUS2rJidTIE8lt6xrcSenPbwtY,5630
17
17
  diffbot/cli/ontology.py,sha256=cLuRQ0KTsOJnFCXdG_zIX9J1ODK8ThPznWVDDEpO1pg,2055
18
- diffbot-3.0.0.dist-info/METADATA,sha256=-_Ih-DSJGKOuk-FWx-eLELglRvJbb6bj8IN4V12jsBs,13049
19
- diffbot-3.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
20
- diffbot-3.0.0.dist-info/entry_points.txt,sha256=FCxJhrbl7VNEsTK7zl7qYvXID7gQ1_wxhiw5_Vllb_M,40
21
- diffbot-3.0.0.dist-info/licenses/LICENSE,sha256=UZlamI1XGeiG0Mit8dsHssNhOuMGKfmNOp5qpf1533w,1063
22
- diffbot-3.0.0.dist-info/RECORD,,
18
+ diffbot-3.1.0.dist-info/METADATA,sha256=AdpsX46XFeoDRME8-pUjswHSbhW8IWzgGlJDOh2Audo,13747
19
+ diffbot-3.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
20
+ diffbot-3.1.0.dist-info/entry_points.txt,sha256=FCxJhrbl7VNEsTK7zl7qYvXID7gQ1_wxhiw5_Vllb_M,40
21
+ diffbot-3.1.0.dist-info/licenses/LICENSE,sha256=UZlamI1XGeiG0Mit8dsHssNhOuMGKfmNOp5qpf1533w,1063
22
+ diffbot-3.1.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any