Edit in GitHubLog an issue

Asynchronous Requests

Description#

One benefit of server-side integration is that you can leverage the huge bandwidth and computing resources available on the server-side by using parallelism. Target Python SDK supports asynchronous requests, which can reduce the effective target time to zero.

Supported Methods#

Copied to your clipboard
1get_offers(options)
2send_notifications(options)
3get_attributes(mbox_names, options)

Example#

A sample application that uses the asyncio module's async/await in Python 3.9+ could look like this:

Copied to your clipboard
1async def execute_mboxes(self, mboxes):
2 context = Context(channel=ChannelType.WEB)
3 execute = ExecuteRequest(mboxes=mboxes)
4 delivery_request = DeliveryRequest(context=context, execute=execute)
5
6 get_offers_options = {
7 "request": delivery_request
8 }
9 return await asyncio.to_thread(target_client.get_offers, get_offers_options)
10
11async def get_target_delivery_response(mboxes):
12 target_delivery_response = await execute_mboxes(mboxes)
13 response = Response(target_delivery_response.get("response").to_str(), status=200, mimetype='application/json')
14 return response
15
16mboxes = [MboxRequest(name="a1-serverside-ab", index=1)]
17return asyncio.run(get_target_delivery_response(mboxes)

This example assumes you you are using Python 3.9+. If using an older version of Python you can still send asynchronous requests by passing in options.callback to get_offers. Check out the sample Flask app for more details about asynchronous execution using either callbacks or async/await, here.

Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.