# Chalk Python SDK Reference: Streams
source: https://docs.chalk.ai/api-docs#section-streams

## `@stream(source, mode, parse, keys, timestamp, updates_materialized_aggregations, environment, machine_type, owner)`
source: https://docs.chalk.ai/api-docs#stream

Decorator to create a stream resolver.

**Parameters**

- `source`: `StreamSource`
  The streaming source, e.g. `KafkaSource(...)` or `KinesisSource(...)` or `PubSubSource(...)`.
- `mode`: `'continuous' | 'tumbling' | None` = `None`
  This parameter is defined when the streaming resolver returns a windowed feature. Tumbling windows are fixed-size, contiguous and non-overlapping time intervals. You can think of tumbling windows as adjacently arranged bins of equal width. Tumbling windows are most often used alongside `max_staleness` to allow the features to be sent to the online store and offline store after each window period.

  Continuous windows, unlike tumbling window, are overlapping and exact. When you request the value of a continuous window feature, Chalk looks at all the messages received in the window and computes the value on-demand.
- `parse`: `Callable[[T], V] | None` = `None`
  A callable that will interpret an input prior to the invocation of the resolver. Parse functions can serve many functions, including pre-parsing bytes, skipping unrelated messages, or supporting rekeying.

  See more at [Custom Parse Functions](https://docs.chalk.ai/docs/streams#custom-parse-functions)
- `keys`: `dict[str, Any] | None` = `None`
  A mapping from input [`BaseModel`](https://docs.pydantic.dev/usage/models/) attribute to Chalk feature attribute to support continuous streaming re-keying. This parameter is required for continuous resolvers. Features that are included here do not have to be explicitly returned in the stream resolver: the feature will automatically be set to the key value used for aggregation.
- `timestamp`: `str | None` = `None`
  An optional string specifying an input attribute as the timestamp used for windowed aggregations.
- `updates_materialized_aggregations`: `bool` = `True`
  If set to [`False`](https://docs.python.org/3/library/constants.html#False), the stream resolver will not update materialized aggregations, but is still eligible for ETL.

**Other parameters**

- `environment`: `Environments | None` = `None`
  Environments are used to trigger behavior in different deployments such as staging, production, and local development.

  Environment can take one of three types:

  - [`None`](https://docs.python.org/3/library/constants.html#None) (default) - candidate to run in every environment
  - [`str`](https://docs.python.org/3/library/stdtypes.html#str) - run only in this environment
  - `list[str]` - run in any of the specified environment and no others

  Read more at [Environments](https://docs.chalk.ai/docs/resolver-environments)
- `machine_type`: `MachineType | None` = `None`
  You can optionally specify that resolvers need to run on a machine other than the default. Must be configured in your deployment.
- `owner`: `str | None` = `None`
  Individual or team responsible for this resolver. The [Chalk Dashboard](https://chalk.ai/projects) will display this field, and alerts can be routed to owners.

**Returns**

`Callable[[Callable[P, TResolverReturn]], ResolverProtocol[P, TResolverReturn]]`

A callable function! You can unit-test stream resolvers as you would unit-test any other code.

## `KafkaSource`
source: https://docs.chalk.ai/api-docs#KafkaSource

Class (bases: `StreamSource`, `SinkIntegrationProtocol`, `BaseModel`)

**Attributes**

- `bootstrap_server`: `str | None`
  The URL of one of your Kafka brokers from which to fetch initial metadata about your Kafka cluster
- `topic`: `str | None`
  The name of the topic to subscribe to.
- `ssl_keystore_location`: `str | None`
  An S3 or GCS URI that points to the keystore file that should be used for brokers. You must configure the appropriate AWS or GCP integration in order for Chalk to be able to access these files.
- `ssl_ca_file`: `str | None`
  An S3 or GCS URI that points to the certificate authority file that should be used to verify broker certificates. You must configure the appropriate AWS or GCP integration in order for Chalk to be able to access these files.
- `client_id_prefix`: `str`
- `group_id_prefix`: `str`
- `security_protocol`: `'PLAINTEXT' | 'SSL' | 'SASL_PLAINTEXT' | 'SASL_SSL'`
  Protocol used to communicate with brokers. Valid values are `"PLAINTEXT"`, `"SSL"`, `"SASL_PLAINTEXT"`, and `"SASL_SSL"`. Defaults to `"PLAINTEXT"`.
- `sasl_mechanism`: `'PLAIN' | 'GSSAPI' | 'SCRAM-SHA-256' | 'SCRAM-SHA-512' | 'OAUTHBEARER'`
  Authentication mechanism when `security_protocol` is configured for SASL_PLAINTEXT or SASL_SSL. Valid values are `"PLAIN"`, `"GSSAPI"`, `"SCRAM-SHA-256"`, `"SCRAM-SHA-512"`, `"OAUTHBEARER"`. Defaults to `"PLAIN"`.
- `sasl_username`: `str | None`
  Username for SASL PLAIN, SCRAM-SHA-256, or SCRAM-SHA-512 authentication.
- `sasl_password`: `str | None`
  Password for SASL PLAIN, SCRAM-SHA-256, or SCRAM-SHA-512 authentication.
- `name`: `str | None`
  The name of the integration, as configured in your [Chalk Dashboard](https://chalk.ai/projects).
- `late_arrival_deadline`: `Duration`
  Messages older than this deadline will not be processed.
- `dead_letter_queue_topic`: `str | None`
  Kafka topic to send messages when message processing fails
- `additional_kafka_args`: `dict[str, Any] | None`
  Additional arguments to use when constructing the Kafka consumer. See https://kafka.apache.org/documentation/#consumerconfigs for more details.
- `msk_iam_auth`: `bool`
  Enable AWS MSK IAM authentication. When enabled, `security_protocol` will be set to `"SASL_SSL"` and `sasl_mechanism` will be set to `"OAUTHBEARER"`. You must also set `aws_region` when enabling MSK IAM auth.
- `aws_region`: `str | None`
  AWS region for MSK IAM authentication (e.g., "us-east-1"). Required when `msk_iam_auth` is True.
- `aws_role_arn`: `str | None`
  Optional IAM role ARN to assume for MSK IAM authentication. If not provided, the default credentials chain will be used.
- `streaming_type`: `str`
- `dlq_name`: `str | None`

### `KafkaSource.config_to_json()`
source: https://docs.chalk.ai/api-docs#KafkaSource.config_to_json

### `KafkaSource.supports_message_headers()`
source: https://docs.chalk.ai/api-docs#KafkaSource.supports_message_headers

## `KinesisSource`
source: https://docs.chalk.ai/api-docs#KinesisSource

Class (bases: `StreamSource`, `BaseModel`)

**Attributes**

- `stream_name`: `str | None`
  The name of your stream. Either this or the stream_arn must be specified
- `stream_arn`: `str | None`
  The ARN of your stream. Either this or the stream_name must be specified
- `region_name`: `str | None`
  AWS region string, e.g. "us-east-2"
- `name`: `str | None`
  The name of the integration, as configured in your [Chalk Dashboard](https://chalk.ai/projects).
- `late_arrival_deadline`: `Duration`
  Messages older than this deadline will not be processed.
- `dead_letter_queue_stream_name`: `str | None`
  Kinesis stream name to send messages when message processing fails
- `aws_access_key_id`: `str | None`
  AWS access key id credential
- `aws_secret_access_key`: `str | None`
  AWS secret access key credential
- `aws_session_token`: `str | None`
  AWS access key id credential
- `endpoint_url`: `str | None`
  optional endpoint to hit Kinesis server
- `consumer_role_arn`: `str | None`
  Optional role ARN for the consumer to assume. If this is provided, enable the "ListShards", "DescribeStream", "ListShards", "GetShardIterator", and "GetRecords" permissions for the role.
- `enhanced_fanout_consumer_name`: `str | None`
  Optional consumer name for Enhanced Fan-Out consumption.

  Requires IAM permissions: kinesis:DescribeStreamSummary, kinesis:ListShards on stream ARN, and kinesis:DescribeStreamConsumer, kinesis:SubscribeToShard on consumer ARN pattern arn:aws:kinesis:region:account:stream/stream-name/consumer/{enhanced_fanout_consumer_name}:* If [`None`](https://docs.python.org/3/library/constants.html#None), uses traditional shared-throughput consumption.
- `dlq_format`: `'json_envelope' | 'raw' | None`
  Format for DLQ messages. `"json_envelope"` wraps failed messages in a JSON envelope containing error metadata (error message, phase, timestamps, resolver info). `"raw"` sends the original message bytes with no metadata. Defaults to `"raw"` when not specified.
- `streaming_type`: `str`
- `dlq_name`: `str | None`
- `stream_or_topic_name`: `str`

### `KinesisSource.config_to_json()`
source: https://docs.chalk.ai/api-docs#KinesisSource.config_to_json

### `KinesisSource.supports_message_headers()`
source: https://docs.chalk.ai/api-docs#KinesisSource.supports_message_headers

## `PubSubSource`
source: https://docs.chalk.ai/api-docs#PubSubSource

Class (bases: `StreamSource`, `BaseModel`)

**Attributes**

- `project_id`: `str | None`
  The project id of your PubSub source
- `subscription_id`: `str | None`
  The subscription id of your PubSub topic from which you want to consume messages. To enable permission for consuming this screen, ensure that the service account has the permissions 'pubsub.subscriptions.consume' and 'pubsub.subscriptions.get'.
- `name`: `str | None`
  The name of the integration, as configured in your [Chalk Dashboard](https://chalk.ai/projects).
- `late_arrival_deadline`: `Duration`
  Messages older than this deadline will not be processed.
- `dead_letter_queue_topic_id`: `str | None`
  PubSub topic id to send messages when message processing fails. Add the permission 'pubsub.topics.publish' if this is set.
- `service_account_credentials_base64`: `str | None`
  Base64-encoded GCP service account credentials JSON for authenticating with PubSub. When set, these credentials are used instead of the default application credentials.
- `streaming_type`: `str`
- `dlq_name`: `str | None`
- `stream_or_topic_name`: `str`

### `PubSubSource.config_to_json()`
source: https://docs.chalk.ai/api-docs#PubSubSource.config_to_json

### `PubSubSource.supports_message_headers()`
source: https://docs.chalk.ai/api-docs#PubSubSource.supports_message_headers

## `StreamSource`
source: https://docs.chalk.ai/api-docs#StreamSource

Class

Base class for all stream sources generated from [`@stream`](https://docs.chalk.ai/api-docs#stream).

**Attributes**

- `registry`: `ClassVar[list[StreamSource]]`
- `name`: `str | None`
- `streaming_type`: `str`
  e.g. 'kafka' or 'kinesis' or 'pubsub'
- `dlq_name`: `str | None`
  Identifier for the dead-letter queue (DLQ) for the stream. If not specified, failed messages will be dropped. Stream name for Kinesis, topic name for Kafka, subscription id for PubSub.
- `stream_or_topic_name`: `str`
  Identifier for the stream to consume. Stream name for Kinesis, topic name for Kafka, subscription id for PubSub

### `StreamSource.config_to_json()`
source: https://docs.chalk.ai/api-docs#StreamSource.config_to_json

### `StreamSource.config_to_dict()`
source: https://docs.chalk.ai/api-docs#StreamSource.config_to_dict

### `StreamSource.supports_message_headers()`
source: https://docs.chalk.ai/api-docs#StreamSource.supports_message_headers

## `make_stream_resolver(name, source, message_type, output_features, parse, environment, machine_type, owner, doc, sink, additional_output_features, skip_online, skip_offline, update_aggregates, excluded_aggregations, include_message_envelope, message_header_filters, resource_group, deduplication, customer_metrics_tags)`
source: https://docs.chalk.ai/api-docs#make_stream_resolver

Constructs a streaming resolver that, instead of a Python function, defines its output features as column projections on an input message.

**Parameters**

- `name`: `str`
  The name of the streaming resolver.
- `source`: `StreamSource`
  The streaming source, e.g. `KafkaSource(...)` or `KinesisSource(...)` or `PubSubSource(...)`.
- `message_type`: `Type[BaseModel | google.protobuf.message.Message | AnyDataclass | str | bytes]`
  The type of message to process.
- `output_features`: `Mapping[FeatureWrapper, Underscore]`
  Mapping of output features to their corresponding expressions.
- `parse`: `Underscore | None` = `None`
  Converts bytes -> message_type. If it returns [`None`](https://docs.python.org/3/library/constants.html#None), message is skipped.
- `environment`: `Environments | None` = `None`
  Environments are used to trigger behavior in different deployments such as staging, production, and local development.
- `machine_type`: `MachineType | None` = `None`
  You can optionally specify that resolvers need to run on a machine other than the default. Must be configured in your deployment.
- `owner`: `str | None` = `None`
  Individual or team responsible for this resolver. The [Chalk Dashboard](https://chalk.ai/projects) will display this field, and alerts can be routed to owners.
- `doc`: `str | None` = `None`
  Documentation string for the resolver.
- `sink`: `Sink | None` = `None`
  An optional message producer configuration that specifies where to send messages. Read more at https://docs.chalk.ai/api-docs#Sink
- `additional_output_features`: `Iterable[FeatureWrapper | str] | None` = `None`
  An optional iterable of additional features to compute and persist to the online store without publishing to an auxiliary stream. Mutually exclusive with `sink`. Use this when you want to enrich features without setting up stream publishing infrastructure.
- `skip_online`: `bool` = `False`
  If [`True`](https://docs.python.org/3/library/constants.html#True), skip online persistence (no writes to Redis/DynamoDB/etc). Results will still be processed but not stored in online stores. Note: Only applies to native streaming. Default: False
- `skip_offline`: `bool` = `False`
  If [`True`](https://docs.python.org/3/library/constants.html#True), skip offline persistence (no result bus publishing for offline storage). Results will still be processed but not stored in offline stores (S3/BigQuery/etc). Note: Only applies to native streaming. Default: False
- `update_aggregates`: `bool` = `True`
  Whether this stream resolver should update materialized aggregations. Default: True
- `excluded_aggregations`: `Iterable[FeatureWrapper | str] | None` = `None`
  Materialized-aggregate feature references whose state this resolver must NOT update, even when `update_aggregates=True`. Unversioned FeatureWrappers resolve to the default version's FQN at call time; pin with `@ N` to anchor on a specific version regardless of later `default_version` flips.
- `include_message_envelope`: `bool` = `False`
  If [`True`](https://docs.python.org/3/library/constants.html#True), the message envelope will be included in the output features. Default: False
- `message_header_filters`: `list[tuple[str, bytes]] | None` = `None`
  A list of tuples of (header_name, header_value) to filter the message by. Default: None
- `resource_group`: `str | None` = `None`
  If specified, this resolver will only run on streaming servers whose resource group matches. If None, the resolver runs on all servers.
- `deduplication`: `Deduplication | None` = `None`
- `customer_metrics_tags`: `list[str] | None` = `None`

**Returns**

`StreamResolver`

A configured stream resolver.

## `Sink`
source: https://docs.chalk.ai/api-docs#Sink

Class

Computes additional output features and sends them to a stream source.

**Attributes**

- `send_to`: `StreamSource`
  The stream source to send results to.
- `output_features`: `Iterable[FeatureWrapper | str]`
  The requested output features. These can include both features returned by the stream resolvers and other features retrievable via online query given the stream resolver outputs as inputs. The message sent to the stream will have these output features as columns.
- `format`: `'json' | 'ipc_stream'`
  Format of messages sent.
- `feature_expressions`: `Mapping[FeatureWrapper | str, Underscore] | None`
- `message_key`: `'pass_through' | None`
  Controls the key on outbound sink messages. Defaults to [`None`](https://docs.python.org/3/library/constants.html#None), which produces messages without a key. Set to `"pass_through"` to copy the incoming source message key onto the outbound message.
