import stytch
client = stytch.Client(
project_id="project-live-c60c0abe-c25a-4472-a9ed-320c6667d317",
secret="secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=",
# Optionally specify a custom base URL for all API calls
# custom_base_url="https://api.custom-domain.com/",
)
Every endpoint supports an async version which you can use by appending _async to the method name. You can use the
same Client object for sync and async methods. The above example of sending and authenticating an magic link can
be rewritten as:
import stytch
client = stytch.B2BClient(
project_id="project-live-c60c0abe-c25a-4472-a9ed-320c6667d317",
secret="secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=",
# Optionally specify a custom base URL for all API calls
# custom_base_url="https://api.custom-domain.com/",
)
Structured errors from the Stytch API will raise StytchError exceptions. You can view the details of the error through
the .details property of the StytchError exception.
from stytch.core.response_base import StytchError
try:
auth_resp = await client.magic_links.authenticate_async(token="token")
except StytchError as error:
# Handle Stytch errors here
if error.details.error_type == "invalid_token":
print("Whoops! Try again?")
except Exception as error:
# Handle other errors here
pass