Docs/SDKs

Python SDK

Run the Rust dataset pipeline from Python and receive a compact report.

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

Install the Python SDK

These guides describe the development source. Crawlingo 1.0.0-alpha.2 is an alpha release; compare your installed version with the documented API and use the matching source when needed.

Use the PyPI alpha for the published API or build from source for unreleased changes.

python -m pip install crawlingo==1.0.0a2
shell1 lines · copy-ready

Generate a dataset

DatasetJob(config, session=None) accepts the shared JSON configuration as a dictionary. run() blocks until completion and releases the GIL while the native job runs.

import json
from crawlingo import DatasetJob

with open("job.json", encoding="utf-8") as source:
    config = json.load(source)

report = DatasetJob(config).run()
print(report["records_written"])
print(report["pages_failed"], report["records_rejected"])
python9 lines · copy-ready

Use an async application

Cancellation requests stop the native job. Wait for the previous run to release its directory before resuming with a new instance.

import asyncio
import json
from crawlingo import DatasetJob

async def main():
    with open("job.json", encoding="utf-8") as source:
        job = DatasetJob(json.load(source))
    report = await job.run_async()
    print(report)

asyncio.run(main())
python11 lines · copy-ready

Extract one page

The Python Dataset.field wrapper currently accepts name, selector, selector_type, transform and default. Use JobField configuration for extract_type in bulk jobs.

from crawlingo import Dataset

result = Dataset("https://example.com/").field("title", "h1").build()
print(result.to_dict())
result.to_json("page.json")
python5 lines · copy-ready