@@ -246,6 +246,9 @@ class BatchRequest(TypedDict, total=False):
246246 the rate of requests with the same flow control key.
247247 """
248248
249+ label : str
250+ """Assign a label to the request to filter logs with it later."""
251+
249252
250253class BatchJsonRequest (TypedDict , total = False ):
251254 url : str
@@ -368,6 +371,9 @@ class BatchJsonRequest(TypedDict, total=False):
368371 the rate of requests with the same flow control key.
369372 """
370373
374+ label : str
375+ """Assign a label to the request to filter logs with it later."""
376+
371377
372378@dataclasses .dataclass
373379class Message :
@@ -437,6 +443,9 @@ class Message:
437443 flow_control : Optional [FlowControlProperties ]
438444 """Flow control properties."""
439445
446+ label : Optional [str ]
447+ """Label assigned to the request for filtering logs."""
448+
440449
441450def get_destination (
442451 * ,
@@ -488,6 +497,7 @@ def prepare_headers(
488497 content_based_deduplication : Optional [bool ],
489498 timeout : Optional [Union [str , int ]],
490499 flow_control : Optional [FlowControl ],
500+ label : Optional [str ],
491501) -> Dict [str , str ]:
492502 h = {}
493503
@@ -570,6 +580,9 @@ def prepare_headers(
570580 h ["Upstash-Flow-Control-Key" ] = flow_control ["key" ]
571581 h ["Upstash-Flow-Control-Value" ] = ", " .join (control_values )
572582
583+ if label is not None :
584+ h ["Upstash-Label" ] = label
585+
573586 return h
574587
575588
@@ -645,6 +658,7 @@ def prepare_batch_message_body(messages: List[BatchRequest]) -> str:
645658 content_based_deduplication = msg .get ("content_based_deduplication" ),
646659 timeout = msg .get ("timeout" ),
647660 flow_control = msg .get ("flow_control" ),
661+ label = msg .get ("label" ),
648662 )
649663
650664 batch_messages .append (
@@ -751,6 +765,9 @@ def convert_to_batch_messages(
751765 if "flow_control" in msg :
752766 batch_msg ["flow_control" ] = msg ["flow_control" ]
753767
768+ if "label" in msg :
769+ batch_msg ["label" ] = msg ["label" ]
770+
754771 batch_messages .append (batch_msg )
755772
756773 return batch_messages
@@ -791,6 +808,7 @@ def parse_message_response(response: Dict[str, Any]) -> Message:
791808 caller_ip = response .get ("callerIP" ),
792809 flow_control = flow_control ,
793810 retry_delay_expression = response .get ("retryDelayExpression" ),
811+ label = response .get ("label" ),
794812 )
795813
796814
@@ -820,6 +838,7 @@ def publish(
820838 content_based_deduplication : Optional [bool ] = None ,
821839 timeout : Optional [Union [str , int ]] = None ,
822840 flow_control : Optional [FlowControl ] = None ,
841+ label : Optional [str ] = None ,
823842 ) -> Union [PublishResponse , List [PublishUrlGroupResponse ]]:
824843 """
825844 Publishes a message to QStash.
@@ -890,6 +909,7 @@ def publish(
890909 should be delivered with a shorter timeout.
891910 :param flow_control: Settings for controlling the number of active requests,
892911 as well as the rate of requests with the same flow control key.
912+ :param label: Assign a label to the request to filter logs with it later.
893913 """
894914 headers = headers or {}
895915 destination = get_destination (
@@ -915,6 +935,7 @@ def publish(
915935 content_based_deduplication = content_based_deduplication ,
916936 timeout = timeout ,
917937 flow_control = flow_control ,
938+ label = label ,
918939 )
919940
920941 response = self ._http .request (
@@ -947,6 +968,7 @@ def publish_json(
947968 content_based_deduplication : Optional [bool ] = None ,
948969 timeout : Optional [Union [str , int ]] = None ,
949970 flow_control : Optional [FlowControl ] = None ,
971+ label : Optional [str ] = None ,
950972 ) -> Union [PublishResponse , List [PublishUrlGroupResponse ]]:
951973 """
952974 Publish a message to QStash, automatically serializing the
@@ -1018,6 +1040,7 @@ def publish_json(
10181040 should be delivered with a shorter timeout.
10191041 :param flow_control: Settings for controlling the number of active requests,
10201042 as well as the rate of requests with the same flow control key.
1043+ :param label: Assign a label to the request to filter logs with it later.
10211044 """
10221045 return self .publish (
10231046 url = url ,
@@ -1039,6 +1062,7 @@ def publish_json(
10391062 content_based_deduplication = content_based_deduplication ,
10401063 timeout = timeout ,
10411064 flow_control = flow_control ,
1065+ label = label ,
10421066 )
10431067
10441068 def enqueue (
@@ -1061,6 +1085,7 @@ def enqueue(
10611085 deduplication_id : Optional [str ] = None ,
10621086 content_based_deduplication : Optional [bool ] = None ,
10631087 timeout : Optional [Union [str , int ]] = None ,
1088+ label : Optional [str ] = None ,
10641089 ) -> Union [EnqueueResponse , List [EnqueueUrlGroupResponse ]]:
10651090 """
10661091 Enqueues a message, after creating the queue if it does
@@ -1124,6 +1149,7 @@ def enqueue(
11241149 When a timeout is specified, it will be used instead of the maximum timeout
11251150 value permitted by the QStash plan. It is useful in scenarios, where a message
11261151 should be delivered with a shorter timeout.
1152+ :param label: Assign a label to the request to filter logs with it later.
11271153 """
11281154 headers = headers or {}
11291155 destination = get_destination (
@@ -1149,6 +1175,7 @@ def enqueue(
11491175 content_based_deduplication = content_based_deduplication ,
11501176 timeout = timeout ,
11511177 flow_control = None ,
1178+ label = label ,
11521179 )
11531180
11541181 response = self ._http .request (
@@ -1179,6 +1206,7 @@ def enqueue_json(
11791206 deduplication_id : Optional [str ] = None ,
11801207 content_based_deduplication : Optional [bool ] = None ,
11811208 timeout : Optional [Union [str , int ]] = None ,
1209+ label : Optional [str ] = None ,
11821210 ) -> Union [EnqueueResponse , List [EnqueueUrlGroupResponse ]]:
11831211 """
11841212 Enqueues a message, after creating the queue if it does
@@ -1243,6 +1271,7 @@ def enqueue_json(
12431271 When a timeout is specified, it will be used instead of the maximum timeout
12441272 value permitted by the QStash plan. It is useful in scenarios, where a message
12451273 should be delivered with a shorter timeout.
1274+ :param label: Assign a label to the request to filter logs with it later.
12461275 """
12471276 return self .enqueue (
12481277 queue = queue ,
@@ -1262,6 +1291,7 @@ def enqueue_json(
12621291 deduplication_id = deduplication_id ,
12631292 content_based_deduplication = content_based_deduplication ,
12641293 timeout = timeout ,
1294+ label = label ,
12651295 )
12661296
12671297 def batch (
0 commit comments