Docs/API reference

DatasetJob

Stream a URL file into validated JSONL or CSV shards. Construct a job, run it, inspect its report, and resume committed progress.

Download .md
Developers4 min read8 sections
Source reference · Match your SDK version. Availability and known issues
In this guide

Use this API to build a dataset

Start by defining the unit of observation, source identity and required fields. The research walkthrough runs this API through the CLI against a public directory, then collects a fixed sample of documents.

Import

from crawlingo import DatasetJob, Session
python1 lines · copy-ready

Constructor

Validates the extraction configuration and creates a job handle. Fetching starts when run is called. Python and Node.js create a default session when one is omitted; Rust requires an Arc<Session>. These are signatures, followed by a complete usage example below.

DatasetJob(config: dict, session: Optional[Session] = None)
python1 lines · copy-ready
ParameterRequiredContract
configYesJobConfig: URL file, output directory, at least one field, and optional execution limits.
sessionRust: yes; Python / Node: optionalRequest headers, timeout, per-host pacing and transport configuration. Configure it before starting the job.

run()

Runs a new job or resumes the same input and configuration. Records stay in the Rust pipeline and are written to disk; the method returns counters rather than a list of every record. The output directory permits one writer at a time.

def run(self) -> dict: ...
async def run_async(self) -> dict: ...
python2 lines · copy-ready
BindingExecutionReturn value
Python run()Blocking; native work releases the GIL.Dictionary with JobReport keys.
Python run_async()Runs the blocking job on an executor.Awaitable yielding the same report dictionary.
Node.js run()Asynchronous native job.Promise<JobReport>.
Rust run().awaitAsync handle; filesystem work uses a blocking worker.Result<JobReport, CrawlingoError>.

Complete usage example

Build the matching SDK, then run one example in a writable working directory. This example writes its one-line URL input and extracts the heading from example.com. Repeating it with the same configuration resumes the existing output. Use a new directory if you change the input or schema.

from pathlib import Path
from crawlingo import DatasetJob

Path("urls.txt").write_text("https://example.com/\n", encoding="utf-8")
job = DatasetJob({
    "urls_file": "urls.txt",
    "output_dir": "datasets/example",
    "fields": [{"name": "title", "selector": "h1", "required": True}],
    "format": "jsonl",
})
report = job.run()
print(report)
if not report["complete"] or report["pages_failed"] or report["records_rejected"]:
    raise RuntimeError("Review the report and error shards before using this dataset")
python14 lines · copy-ready

Output record

After a successful fetch of the current example page, a data shard contains a record with this shape. Values are strings; _source_url and _row are provenance fields. Read report.shards to find the committed shard boundary. This is an illustrative result, not a live request from the documentation.

{"title":"Example Domain","_source_url":"https://example.com/","_row":"0"}
json1 lines · copy-ready

cancel()

Requests cancellation and returns immediately: None in Python, void in Node.js and () in Rust. It does not wait for the worker to release the directory. The uncommitted batch is discarded and can be replayed by a new instance. Keep the same URL file, configuration and output directory when resuming.

When a Python run_async task is cancelled, the wrapper requests native cancellation and re-raises CancelledError. The executor worker may still be shutting down. Wait for directory ownership to be released before launching a replacement. A cancelled handle stays cancelled; construct a new one to resume.

const stop = () => job.cancel();
process.once('SIGINT', stop);
process.once('SIGTERM', stop);
try {
  const report = await job.run();
  console.log({ cancelled: report.cancelled, shards: report.shards });
} finally {
  process.removeListener('SIGINT', stop);
  process.removeListener('SIGTERM', stop);
}
javascript10 lines · copy-ready

Errors and failure handling

Constructor and run failures throw in Python / Node.js and return Err in Rust. They include invalid configuration, inaccessible files, locked state and input changes. Node maps structured native failures into CrawlingoError subclasses and exposes code; Python conversion differs. Avoid treating message text as a stable machine API. See the language-specific reference for error details.

ConditionWhere to lookNext action
Invalid config or unsupported formatConstructor exception / ErrCheck required fields, accepted values and positive resource limits.
Input file missing or output not writablerun exception / rejected promise / ErrResolve paths against the worker’s current directory and check access.
Another writer owns output_dirrun failure while opening stateWait for the previous worker; use one owner per directory.
Input or config changed on resumerun failureStart a new job directory for the changed dataset.
HTTP failure, robots denial, missing row containerpages_failed and error shardsReview failed sources. A completed job will not retry them automatically.
Required field missing or invalid valuerecords_rejected and error shardsInspect the affected row and correct the extraction rules.