SDKs
On this page
There are two official SDKs, for Python and TypeScript. Both cover the Crawl API, POST /v1/serp and GET /v1/usage.
The SDKs don't wrap the compatible SERP, Pages, AI answers, Business and Ads endpoints yet. Call those over HTTP, as in every example in these docs, or with an existing DataForSEO v3 client pointed at our base URL. See Migrate from DataForSEO.
What they cover
| Python | TypeScript | Endpoint |
|---|---|---|
crawl(url, output_format=, include_receipt=, project_id=) | crawl(url, { outputFormat, includeReceipt, projectId }) | POST /v1/crawls |
crawl_batch(urls, webhook_url=, output_format=, include_receipt=, project_id=) | crawlBatch(urls, { webhookUrl, ... }) | POST /v1/crawls/batch |
get_crawl(ref, include_receipt=) | getCrawl(ref, { includeReceipt }) | GET /v1/crawls/{ref} |
wait_for_batch(job_id, timeout=600, poll_interval=2, max_poll_interval=15) | waitForBatch(jobId, { timeoutMs, pollIntervalMs, maxPollIntervalMs }) | Polls GET /v1/crawls/{ref} |
get_receipt(ref) | getReceipt(ref) | GET /v1/crawls/{ref}/receipt |
serp(keyword, search_engine=, country=, language=, device=) | serp(keyword, { searchEngine, country, language, device }) | POST /v1/serp |
usage() | usage() | GET /v1/usage |
ref is a batch job_id (job_...) or a task id (cr_...). Responses are the API's own JSON, with its snake_case field names.
The crawl methods don't take auto_upgrade, max_level or max_cost yet, so they use the API defaults. To set a ceiling, call POST /v1/crawls directly.
Python
pip install dataforgaio
pip install "dataforgaio[langchain]" # adds DataForGAIOLoader
pip install "dataforgaio[llamaindex]" # adds DataForGAIOReaderfrom dataforgaio import DataForGAIO
client = DataForGAIO() # reads DATAFORGAIO_API_KEY; or DataForGAIO(api_key="dg_...")
result = client.crawl("https://example.com", output_format="markdown")
task = result["tasks"][0]
print(task["status"], task["content"]["title"], task["receipt"]["billed_usd"])
job = client.crawl_batch(["https://example.com/a", "https://example.com/b"])
done = client.wait_for_batch(job["job_id"], timeout=600)- Sync
DataForGAIOand asyncAsyncDataForGAIOclients. Python 3.9 or later; the only runtime dependency ishttpx. DataForGAIOLoader(LangChain) andDataForGAIOReader(LlamaIndex) put every receipt field in each document's metadata and skip pages whosecontent_checkisn'tsubstantive(passinclude_non_substantive=Trueto keep them).- Default base URL
https://api.dataforgaio.com/v1, overridable withbase_url=orDATAFORGAIO_BASE_URL.
TypeScript
npm install @dataforgaio/sdkimport { DataForGAIO } from '@dataforgaio/sdk';
const client = new DataForGAIO(); // reads DATAFORGAIO_API_KEY
const result = await client.crawl('https://example.com', { outputFormat: 'markdown' });
const task = result.tasks[0]!;
console.log(task.status, task.content?.title, task.receipt?.billed_usd);- No runtime dependencies; uses the built-in
fetch. ESM and CommonJS builds for Node 18 or later, Deno, Bun and edge runtimes. - Client options:
apiKey,baseUrl,timeoutMs(default 120 s),maxRetries,headers,fetch. Every method accepts anAbortSignalassignal.
Errors and retries (both SDKs)
| Error | HTTP | API code |
|---|---|---|
AuthError | 401, 403 | unauthorized, forbidden |
InsufficientBalance | 402 | balance_required |
InvalidRequest | 400, 422 | invalid_request, invalid_target |
NotFound | 404 | not_found |
RateLimited | 429 | rate_limited (with retry_after in seconds) |
APIError | anything else | e.g. not_configured |
Both retry up to max_retries / maxRetries times (default 2): 429 on any method, honoring Retry-After up to 60 s; 5xx and network errors on GET, with exponential backoff and full jitter; and connection failures on POST where the request never reached us. A POST isn't retried after a 5xx or a read timeout, since the crawl or search may already have run. See Retrying safely.
Calling the compatible endpoints
Until the SDKs cover them, a few lines of HTTP do the job:
import os
import requests
def dfg(path, tasks):
res = requests.post(
f"https://api.dataforgaio.com/v1/{path}",
auth=("api", os.environ["DATAFORGAIO_API_KEY"]),
json=tasks,
timeout=180,
)
res.raise_for_status()
return res.json()
body = dfg("serp/google/organic/live/advanced",
[{"keyword": "web data api", "location_code": 2840, "language_code": "en", "max_cost": 0.002}])async function dfg(path: string, tasks: object[]) {
const auth = Buffer.from(`api:${process.env.DATAFORGAIO_API_KEY}`).toString('base64');
const res = await fetch(`https://api.dataforgaio.com/v1/${path}`, {
method: 'POST',
headers: { Authorization: `Basic ${auth}`, 'Content-Type': 'application/json' },
body: JSON.stringify(tasks),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
}
const body = await dfg('serp/google/organic/live/advanced', [
{ keyword: 'web data api', location_code: 2840, language_code: 'en', max_cost: 0.002 },
]);Task-level errors arrive inside an HTTP 200, so check each tasks[].status_code as well.