Smithy AWS Event Stream

0.2.1 · active · verified Fri Apr 17

Smithy AWS Event Stream provides components for interacting with Amazon Event Streams. It handles the serialization and deserialization of event stream messages according to the AWS Event Stream specification. This library is part of the broader `smithy-python` project, currently at version 0.2.1, with a release cadence tied to the evolution of the `smithy-python` ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to construct a basic `EventStreamMessage` using the library's data models. This message can then be serialized and sent over an event stream, typically within the context of an AWS client generated by `smithy-python`.

from smithy_aws_event_stream.model import EventStreamMessage, EventStreamHeader, EventStreamHeaderValue

# 1. Create headers for the event stream message
headers = [
    EventStreamHeader(name=":message-type", value=EventStreamHeaderValue.string("event")),
    EventStreamHeader(name=":event-type", value=EventStreamHeaderValue.string("MyApplicationEvent")),
    EventStreamHeader(name="correlation-id", value=EventStreamHeaderValue.uuid("a1b2c3d4-e5f6-7890-1234-567890abcdef")),
    EventStreamHeader(name="is-urgent", value=EventStreamHeaderValue.boolean(True)),
    EventStreamHeader(name="sequence-number", value=EventStreamHeaderValue.int64(1))
]

# 2. Define the payload (can be empty or any bytes)
payload = b'{"data": "This is my event payload!"}'

# 3. Create an EventStreamMessage instance
message = EventStreamMessage(headers=headers, payload=payload)

print("Created Event Stream Message:")
print(f"  Payload: {message.payload.decode('utf-8')}")
print("  Headers:")
for header in message.headers:
    # Using to_python() to get the native Python value from EventStreamHeaderValue
    print(f"    - {header.name}: {header.value.to_python()}")

# In a real-world scenario, this message would typically be serialized
# by an EventStreamSerde instance (part of an AWS client generated by smithy-python)
# and sent over an asynchronous stream to an AWS service.

view raw JSON →