---
title: trigger (DataStreamWriter)
description: "DataStreamWriter.trigger method in PySpark: Sets the trigger for the streaming query. If not set, the query runs as fast as possible, equivalent to processingTime='0 seconds'. Only one trigger parameter can be set at a time."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/datastreamwriter/trigger
---

# trigger (DataStreamWriter)

Sets the trigger for the streaming query. If not set, the query runs as fast as possible, equivalent to `processingTime='0 seconds'`. Only one trigger parameter can be set at a time.

See [Configure Structured Streaming trigger intervals](https://docs.databricks.com/aws/en/structured-streaming/triggers.md).

## Compute and pipeline execution

In Lakeflow pipelines, the pipeline manages stream execution. Use [pipeline execution settings](https://docs.databricks.com/aws/en/ldp/concepts/pipeline-mode.md) to control when pipeline data is processed.

When you use `DataStreamWriter` directly on serverless compute for notebooks and jobs, use `availableNow=True`. The default trigger, `processingTime`, `continuous`, and `realTime` are not supported on that compute. These restrictions do not apply to serverless pipeline execution modes. See [Streaming limitations](https://docs.databricks.com/aws/en/compute/serverless/limitations.md#streaming).

## Syntax

```
trigger(*, processingTime=None, once=None, continuous=None, availableNow=None, realTime=None)
```

## Parameters

| Parameter        | Type           | Description                                                                                                                                                                                                                                                                                                     |
| ---------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `processingTime` | str, optional  | A processing time interval string (for example, `'5 seconds'`, `'1 minute'`). Runs a microbatch query periodically based on the processing time.                                                                                                                                                                |
| `once`           | bool, optional | If `True`, processes only one batch of data then terminates the query. Deprecated in Databricks Runtime 11.3 LTS and above. Use `availableNow=True` instead.                                                                                                                                                    |
| `continuous`     | str, optional  | Not supported on Databricks. This parameter enables Apache Spark's experimental Continuous Processing mode, which differs from continuous pipeline mode. Use real-time mode for low-latency Structured Streaming queries.                                                                                       |
| `availableNow`   | bool, optional | If `True`, processes all available data in multiple batches then terminates the query.                                                                                                                                                                                                                          |
| `realTime`       | str, optional  | A batch duration string (for example, `'5 minutes'`). Processes records as they arrive within a long-running batch. The value controls batch duration, not record-processing latency. See [Real-time mode in Structured Streaming](https://docs.databricks.com/aws/en/structured-streaming/real-time/index.md). |

## Returns

`DataStreamWriter`

## Examples

```python
df = spark.readStream.format("rate").load()
```

Trigger execution every 5 seconds:

```python
df.writeStream.trigger(processingTime='5 seconds')
# <...streaming.readwriter.DataStreamWriter object ...>
```

Process all available data in multiple batches:

```python
df.writeStream.trigger(availableNow=True)
# <...streaming.readwriter.DataStreamWriter object ...>
```

Configure real-time mode with five-minute batches. Records are processed as they arrive during each batch. Use a [supported source, sink, and compute type](https://docs.databricks.com/aws/en/structured-streaming/real-time/reference.md):

```python
kafka_df = (spark.readStream
    .format("kafka")
    .option("kafka.bootstrap.servers", "<bootstrap-servers>")
    .option("subscribe", "<input-topic>")
    .load())
kafka_df.writeStream.trigger(realTime="5 minutes")
# <...streaming.readwriter.DataStreamWriter object ...>
```
