Skip to content

Commit 65190aa

Browse files
committed
python: Add convenient construction of rawPayload messages
1 parent 724e8dc commit 65190aa

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

python/svix/api.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,36 @@ def expunge_content(self, app_id: str, msg_id: str) -> None:
11621162
)
11631163

11641164

1165+
def message_in_raw(
1166+
event_type: str, payload: str, content_type: t.Optional[str]
1167+
) -> MessageIn:
1168+
"""
1169+
Creates a `MessageIn` with the payload already being serialized.
1170+
1171+
The payload is not normalized on the server (usually whitespace outside
1172+
of string literals, unnecessarily escaped characters in string and such
1173+
are fixed up by the server), and is not even required to be JSON.
1174+
1175+
Args:
1176+
payload (str): Serialized message payload
1177+
content_type (str?): Content type of the payload to send as a header.
1178+
Defaults to `application/json`.
1179+
1180+
See the class documentation for details about the other parameters.
1181+
"""
1182+
transformations_params: t.Dict[str, t.Any] = {
1183+
"rawPayload": payload,
1184+
}
1185+
if content_type is not None:
1186+
transformations_params["headers"] = {"content-type": content_type}
1187+
1188+
return MessageIn(
1189+
event_type=event_type,
1190+
payload={},
1191+
transformations_params=transformations_params,
1192+
)
1193+
1194+
11651195
class MessageAttemptAsync(ApiBase):
11661196
async def list_by_msg(
11671197
self,

0 commit comments

Comments
 (0)