Dataset · Python
Extract named fields from one page, with optional validation and small-result exports.
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 DatasetUsage 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")Members
| Member | Kind | Return / value type | Source status |
|---|---|---|---|
| __init__ | method | Not annotated; see behavior notes | Present in source |
| field | method | 'Dataset' | Present in source |
| with_schema | method | 'Dataset' | Present in source |
| auto_match | method | 'Dataset' | Present in source |
| timeout | method | 'Dataset' | Present in source |
| headers | method | 'Dataset' | Present in source |
| build | method | 'DatasetResult' | Present in source |
| build_async | method | 'DatasetResult' | Present in source |
| extract_structured | method | list[dict[str, str]] | Present in source |
| build_structured | method | list[dict[str, str]] | Present in source |
| save_json | static method | Not annotated; see behavior notes | Present in source |
| save_csv | static method | Not annotated; see behavior notes | Present 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)| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| url | str | Required | HTTP(S) source URL; verify the target is appropriate for your application. |
| session | Optional[Session] | Default: None | Shared 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'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| name | str | Required | Field, header or attribute name for this operation. |
| selector | str | Required | Selector evaluated against the fetched DOM. |
| selector_type | str | Default: 'css' | Selector engine for this field; supported values differ between builders. |
| transform | Optional[Callable[[str], str]] | Default: None | Python callback applied to the extracted string; application exceptions propagate. |
| default | Optional[str] | Default: None | Fallback 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'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| schema | DatasetSchema | Required | DatasetSchema 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'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| enabled | bool | Required | Enable or disable this behavior. |
timeout()
Set timeout on the attached session in seconds.
Returns / value: 'Dataset'.
def timeout(self, seconds: int) -> 'Dataset'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| seconds | int | Required | Time 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'| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| headers | dict | Required | Header 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'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'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]]| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| page | 'Page' | Required | Page 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]]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)| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| records | list[dict[str, str]] | Required | In-memory row maps to export. |
| path | str | Required | Filesystem 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)| Parameter | Type | Required / default | Meaning |
|---|---|---|---|
| records | list[dict[str, str]] | Required | In-memory row maps to export. |
| path | str | Required | Filesystem 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.