Skip to content

Response

faststream.Response #

Response(
    body: Any,
    *,
    headers: dict[str, Any] | None = None,
    correlation_id: str | None = None,
)

Initialize a handler.

Source code in faststream/response/response.py
def __init__(
    self,
    body: Any,
    *,
    headers: dict[str, Any] | None = None,
    correlation_id: str | None = None,
) -> None:
    """Initialize a handler."""
    self.body = body
    self.headers = headers or {}
    self.correlation_id = correlation_id

body instance-attribute #

body = body

headers instance-attribute #

headers = headers or {}

correlation_id instance-attribute #

correlation_id = correlation_id

as_publish_command #

as_publish_command() -> PublishCommand

Method to transform handlers' Response result to DTO for publishers.

Source code in faststream/response/response.py
def as_publish_command(self) -> "PublishCommand":
    """Method to transform handlers' Response result to DTO for publishers."""
    return PublishCommand(
        body=self.body,
        headers=self.headers,
        correlation_id=self.correlation_id,
        _publish_type=PublishType.PUBLISH,
    )

get_publish_key #

get_publish_key() -> Any | None

Get the key for publishing this message.

Override this method in subclasses to provide broker-specific keys. Default implementation returns None (no key).

RETURNS DESCRIPTION
Any | None

The key for publishing, or None if this Response type doesn't use keys.

Source code in faststream/response/response.py
def get_publish_key(self) -> Any | None:
    """Get the key for publishing this message.

    Override this method in subclasses to provide broker-specific keys.
    Default implementation returns None (no key).

    Returns:
        The key for publishing, or None if this Response type doesn't use keys.
    """
    return None