Skip to content

Documentation

Python SDK: KeyValue: crawl state

ctx.state() stores a small crawl cursor, such as the next page number. Reads and writes are synchronous; it is not a product database.

Examples are fragments inside def run(ctx):. All SDK methods are synchronous; do not add await.

Methods

get

ctx.state().get(key, default=None) -> Any

Argument Type Required Purpose
key str | None Yes Record, state, object, or workflow-input key, depending on the method.
default Any No, see the signature default Fallback when no value is available.

Result: Any.

Read a saved state value. If the key does not exist yet, the method returns default.

result = ctx.state().get('page', 1)

set

ctx.state().set(key, value) -> None

Argument Type Required Purpose
key str | None Yes Record, state, object, or workflow-input key, depending on the method.
value Any Yes Method-specific value; see its result description.

Result: None. The method does not return a data value.

Save a state value to resume traversal later.

ctx.state().set('page', 2)

incr

ctx.state().incr(key, by=1) -> int

Argument Type Required Purpose
key str | None Yes Record, state, object, or workflow-input key, depending on the method.
by int No, see the signature default Integer increment.

Result: int.

Increase an integer state counter.

result = ctx.state().incr('processed', 1)

Errors and execution context

All calls are synchronous. Invalid arguments or malformed source data can raise ValueError/TypeError; a platform refusal or unavailable service raises RuntimeError. Missing elements/values return None or an empty collection only where explicitly documented. Do not convert every exception into an empty successful result. External-service methods are unavailable in export transformations; see transformation limits and environment.