Skip to content

Documentation

Export transformations in Python

Collection language and transformation language are independent. PHP or JavaScript may collect records while Python prepares them for CSV/JSON/XML, files, HTTP endpoints, Webhooks, or a supported destination. Transformation runs after field mapping and does not modify the site's source records.

Input and output

def run(ctx):
    items = ctx.params().get('items', [])
    for item in items:
        result = dict(item)
        quantity = result.get('quantity')
        result['in_stock'] = quantity is not None and float(quantity) > 0
        ctx.emit(result)

Mapped records arrive in ctx.params()['items']; use .get('items', []) for an empty input fallback. Emit each output dictionary with ctx.emit(). Returning a list from run does not produce export records. Transformations always use run(ctx), matching the other languages.

Do not create an application data field named __key. Export identity is managed by the export pipeline. Emit only the mapped fields required by the receiver.

Modes

Records mode computes, cleans, and renames fields while preserving record count and order. Dropping a record or emitting two instead of one is rejected by the platform.

Dataset mode is available for files, HTTP endpoints, and Webhooks; an attached database delivery prevents saving this mode. Dataset mode supports filtering, sorting, grouping, and summaries. Full input is bounded by 10,000 records and 16 MiB; one transformation call has a 30-second limit. User code cannot raise these limits. Narrow the selection or redesign the workflow for larger datasets.

def run(ctx):
    totals = {}
    for item in ctx.param('items', []):
        category = str(item.get('category') or 'other')
        quantity = float(item.get('quantity') or 0)
        totals[category] = totals.get(category, 0) + quantity
    for category in sorted(totals):
        ctx.emit({'category': category, 'quantity': totals[category]})

This aggregation example is for Dataset mode only. Its output fields must match the receiver's expected schema.

Endpoint pages and complete files

HTTP endpoint transformation applies to the current page. A page total is not a total for the entire catalog. File generation and Webhook preparation use a permitted complete selection. For a global summary, use a dedicated scenario or a full-selection delivery within the limits.

Sorting one page does not globally sort all pages. Cursors and token scopes remain controlled by the export system. Shared delivery schedules and run-triggered deliveries work independently of language.

Permitted actions and testing

Transformations compute locally without external services. HTTP, browser, mail, documents, S3, credentials, and AI calls are unavailable. Use normal calculations, the permitted standard library, params/param, emit, and allowed local diagnostics. A prohibited call fails the transformation rather than producing a partial successful delivery.

Preview a small sample and check empty input, a missing field, zero quantities, invalid types, and record order. Do not swallow exceptions. After the preview succeeds, verify the actual delivery channel. Endpoint token rules are described in HTTP exports.

Serialized payload size

The logical 16 MiB dataset limit does not remove the 12 MiB serialized-message limit, including parameters and metadata. Both input and emitted output must fit. The usable dataset may be smaller; narrow the selection or shorten large fields when the payload cannot be sent. A limit error does not indicate a successful truncated export.