Docs/API reference

Dataset · Python

Extract named fields from one page, with optional validation and small-result exports.

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

Purpose and lifecycle

field adds a named selector; build fetches once and returns DatasetResult. This API keeps results in memory.

buildStructured/extractStructured zip selector results by their positions. Missing values can change row alignment. Prefer DatasetJob with row_selector for reliable repeated records.

The Python wrapper exposes transform callbacks for ordinary build/build_async. The Node field options expose extractType. Do not infer parity from the underlying Rust field type.

Definition and availability

Source snapshot: 1.0.0-alpha.3. Package export. Declared in source; this is not a runtime test result.

Signatures and source locations are generated from the SDK wrappers. Clean snapshots link to the recorded commit. Modified snapshots link to main, which may differ; file hashes identify the local inputs.

class Dataset
python1 lines · copy-ready

Usage example

Use a matching source build. Where a snippet uses page, obtain it with the Page example first. Example URLs illustrate API shape; they are not promised datasets.

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

Members

MemberKindReturn / value typeSource status
__init__methodNot annotated; see behavior notesPresent in source
fieldmethod'Dataset'Present in source
with_schemamethod'Dataset'Present in source
auto_matchmethod'Dataset'Present in source
timeoutmethod'Dataset'Present in source
headersmethod'Dataset'Present in source
buildmethod'DatasetResult'Present in source
build_asyncmethod'DatasetResult'Present in source
extract_structuredmethodlist[dict[str, str]]Present in source
build_structuredmethodlist[dict[str, str]]Present in source
save_jsonstatic methodNot annotated; see behavior notesPresent in source
save_csvstatic methodNot annotated; see behavior notesPresent in source

__init__()

Configure extraction for one URL with the supplied or default session. Add fields, then call build to fetch and produce a result.

Returns / value: Not annotated; see behavior notes.

def __init__(self, url: str, session: Optional[Session]=None)
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
urlstrRequiredHTTP(S) source URL; verify the target is appropriate for your application.
sessionOptional[Session]Default: NoneShared request state. Omit only where the signature provides a default.

field()

Append a field definition. name is its output key; selector_type/selectorType chooses the selector family; default/defaultVal supplies a fallback when empty. Node extractType supports text, price, datetime, url and attr:name.

Returns / value: 'Dataset'.

def field(self, name: str, selector: str, selector_type: str='css', transform: Optional[Callable[[str], str]]=None, default: Optional[str]=None) -> 'Dataset'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
namestrRequiredField, header or attribute name for this operation.
selectorstrRequiredSelector evaluated against the fetched DOM.
selector_typestrDefault: 'css'Selector engine for this field; supported values differ between builders.
transformOptional[Callable[[str], str]]Default: NonePython callback applied to the extracted string; application exceptions propagate.
defaultOptional[str]Default: NoneFallback field value when extraction is empty.

with_schema()

Attach DatasetSchema to validate/coerce the collected field map before returning it.

Returns / value: 'Dataset'.

def with_schema(self, schema: DatasetSchema) -> 'Dataset'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
schemaDatasetSchemaRequiredDatasetSchema containing validation constraints.

auto_match()

Set heuristic recovery on the attached session for ordinary Dataset extraction.

Returns / value: 'Dataset'.

def auto_match(self, enabled: bool) -> 'Dataset'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
enabledboolRequiredEnable or disable this behavior.

timeout()

Set timeout on the attached session in seconds.

Returns / value: 'Dataset'.

def timeout(self, seconds: int) -> 'Dataset'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
secondsintRequiredTime in seconds; see the method-specific range and timing semantics.

headers()

Replace headers on the attached session.

Returns / value: 'Dataset'.

def headers(self, headers: dict) -> 'Dataset'
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
headersdictRequiredHeader names and values; avoid sharing credentials across unrelated sites.

build()

Fetch, parse and extract one field map. Node returns Promise<DatasetResult>; Python blocks and returns DatasetResult.

Returns / value: 'DatasetResult'.

def build(self) -> 'DatasetResult'
python1 lines · copy-ready

build_async()

Run the Python native build through an executor and await its result. This is an in-memory result, not a streaming DatasetJob.

Returns / value: 'DatasetResult'.

async def build_async(self) -> 'DatasetResult'
python1 lines · copy-ready

extract_structured()

Extract positional rows from an already parsed Page without making another fetch.

Returns / value: list[dict[str, str]].

def extract_structured(self, page: 'Page') -> list[dict[str, str]]
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
page'Page'RequiredPage object to extract from; distinct from a page-number pagination parameter.

build_structured()

Fetch the configured URL and return positional multi-row records in memory.

Returns / value: list[dict[str, str]].

def build_structured(self) -> list[dict[str, str]]
python1 lines · copy-ready

save_json()

Write the supplied records as a JSON array. The destination file is created or replaced.

Returns / value: Not annotated; see behavior notes.

def save_json(records: list[dict[str, str]], path: str)
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
recordslist[dict[str, str]]RequiredIn-memory row maps to export.
pathstrRequiredFilesystem path relative to the process working directory unless absolute.

save_csv()

Write a CSV header and the supplied records. The destination file is created or replaced. Use a consistent record schema.

Returns / value: Not annotated; see behavior notes.

def save_csv(records: list[dict[str, str]], path: str)
python1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
recordslist[dict[str, str]]RequiredIn-memory row maps to export.
pathstrRequiredFilesystem path relative to the process working directory unless absolute.

Errors and operational limits

Non-success HTTP statuses abort a Dataset build. Required schema violations, regex syntax errors, fingerprint storage failures and export errors can fail the operation. Node uses the typed error bridge; Python uses its wrapper-specific conversion.

Source availability, package publication and runtime validation are separate facts. These pages describe the source snapshot, not a claim that all platforms or every API path have passed production acceptance.