Objective
Guide you through how to make asynchronous API requests using the Python helper library.
Procedure
By default, the Twilio Client will make synchronous requests to the Twilio API. To allow for asynchronous, non-blocking requests, we've included an optional asynchronous HTTP client. When used with the Client and the accompanying *_async methods, requests made to the Twilio API will be performed asynchronously.
import asyncio
from twilio.http.async_http_client import AsyncTwilioHttpClient
from twilio.rest import Client
async def main():
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
http_client = AsyncTwilioHttpClient()
client = Client(account_sid, auth_token, http_client=http_client)
message = await client.messages.create_async(to="+12316851234", from_="+15555555555",
body="Hello there!")
asyncio.run(main())Additional Information
The documentation for the Twilio API can be found here.
The Python library documentation can be found here.