Python Library
▶ github.com/diffbot/diffbot-python
The official Diffbot Python client is available as a CLI or client library for all your human and agentic needs.
Agentic usage
Go directly to diffbot-skills. Do not pass Go. Do not collect $200.
Installation
Install the standalone CLI binary for agentic use:
bash
curl -fsSL https://raw.githubusercontent.com/diffbot/diffbot-python/main/install.sh | shIf you prefer, the full Python library can also be installed with pip:
bash
python3 -m pip install diffbot-pythonAuthentication
Set a DIFFBOT_API_TOKEN env variable or in ~/.diffbot/credentials. Import with resolve_token.
python
from diffbot import Diffbot, resolve_token
db = Diffbot(token=resolve_token()) # from env var or ~/.diffbot/credentials
data = db.extract("https://www.example.com")Usage
Extract structured content:
python
from diffbot import Diffbot
db = Diffbot(token="<DIFFBOT_TOKEN>")
data = db.extract("https://www.example.com")Crawl a site for structured content:
python
from diffbot import Diffbot
db = Diffbot(token="<DIFFBOT_TOKEN>")
for event in db.crawl("https://www.example.com", hops=1):
print(event)Query the Knowledge Graph with DQL (Don't know DQL? There's a skill for that):
python
from diffbot import Diffbot
db = Diffbot(token="<DIFFBOT_TOKEN>")
results = db.dql('type:Organization name:"Diffbot"')Search the web
python
from diffbot import Diffbot
db = Diffbot(token="<DIFFBOT_TOKEN>")
results = db.web_search("diffbot knowledge graph")
for r in results["search_results"]:
print(r["score"], r["title"], r["pageUrl"])
print(r["content"])Resolve entities using NLP
python
from diffbot import Diffbot
db = Diffbot(token="<DIFFBOT_TOKEN>")
result = db.entities("Apple CEO Tim Cook announced record quarterly earnings.")
for entity in result["entities"]:
print(entity["name"], entity.get("type"), entity.get("id"))
print("sentiment:", result.get("sentiment"))