### Install Async Support Source: https://github.com/resend/resend-python/blob/main/README.md Install the necessary extra dependencies to enable asynchronous operations. ```bash pip install resend[async] ``` -------------------------------- ### Install Async Support for Resend SDK Source: https://github.com/resend/resend-python/blob/main/_autodocs/configuration.md Install the necessary packages to enable asynchronous HTTP client support in the Resend Python SDK. ```bash pip install resend[async] # or pip install resend httpx ``` -------------------------------- ### Complete Configuration Example Source: https://github.com/resend/resend-python/blob/main/_autodocs/configuration.md A comprehensive example demonstrating how to configure the Resend Python SDK with API key, API URL, and custom timeouts for both sync and async HTTP clients. ```python import resend import os # 1. Set API key from environment or explicit assignment resend.api_key = os.environ.get("RESEND_API_KEY", "re_yourkey") # 2. Configure API URL (optional, defaults to production) resend.api_url = os.environ.get( "RESEND_API_URL", "https://api.resend.com" ) # 3. Configure sync HTTP client with custom timeout resend.default_http_client = resend.RequestsClient(timeout=60) # 4. Configure async HTTP client with custom timeout try: resend.default_async_http_client = resend.HTTPXClient(timeout=60) except ImportError: # httpx not installed resend.default_async_http_client = None ``` -------------------------------- ### Install Resend SDK Source: https://github.com/resend/resend-python/blob/main/README.md Command to install the Resend Python SDK via pip. ```bash pip install resend ``` -------------------------------- ### Install Resend SDK with Async Support Source: https://github.com/resend/resend-python/blob/main/_autodocs/README.md Install the Resend Python SDK, including optional asynchronous HTTP client support. This command ensures all necessary dependencies are met. ```bash pip install resend[async] ``` -------------------------------- ### Example Event Schema Source: https://github.com/resend/resend-python/blob/main/_autodocs/types.md An example of how to define an event schema for tracking user-specific data. This schema includes user ID, purchase amount, VIP status, and purchase date. ```python schema: resend.EventSchema = { "user_id": "string", "purchase_amount": "number", "is_vip": "boolean", "purchase_date": "date" } ``` -------------------------------- ### Example of Using EmailTemplate Source: https://github.com/resend/resend-python/blob/main/_autodocs/emails.md Illustrates how to construct the `params` dictionary to send an email using a predefined template with custom variables. ```python params: resend.Emails.SendParams = { "from": "onboarding@resend.dev", "to": "customer@example.com", "template": { "id": "template_abc123", "variables": { "username": "John", "order_id": 12345 } } } ``` -------------------------------- ### Create and Send a Broadcast Immediately Source: https://github.com/resend/resend-python/blob/main/_autodocs/broadcasts.md This example demonstrates creating and sending a broadcast in one step. Set the 'send' parameter to True to initiate immediate sending. ```python import resend resend.api_key = "re_yourkey" # Create and send immediately response = resend.Broadcasts.create({ "from": "hello@example.com", "segment_id": "segment_abc123", "subject": "Urgent Update", "html": "

Important News

", "send": True }) print(f"Sent: {response['id']}") ``` -------------------------------- ### Create a Welcome Series automation Source: https://github.com/resend/resend-python/blob/main/_autodocs/automations.md Example of creating a 'Welcome Series' automation workflow. This workflow is triggered on 'signup' and includes multiple email sending steps with delays. ```python resend.Automations.create({ "name": "Welcome Series", "steps": [ {"id": "trigger", "type": "trigger", "trigger_on": "signup"}, {"id": "welcome", "type": "send_email", "source_mail": "hello@example.com"}, {"id": "wait", "type": "delay", "action": "wait_days:1"}, {"id": "guide", "type": "send_email", "source_mail": "guide@example.com"}, {"id": "wait2", "type": "delay", "action": "wait_days:2"}, {"id": "offer", "type": "send_email", "source_mail": "offer@example.com"}, ], "connections": [ {"from": "trigger", "to": "welcome"}, {"from": "welcome", "to": "wait"}, {"from": "wait", "to": "guide"}, {"from": "guide", "to": "wait2"}, {"from": "wait2", "to": "offer"}, ], "status": "enabled" }) ``` -------------------------------- ### Create a Post-Purchase follow-up automation Source: https://github.com/resend/resend-python/blob/main/_autodocs/automations.md Example of creating a 'Post-Purchase' automation workflow. This workflow is triggered on 'purchase' and includes email steps for confirmation and follow-up with a delay. ```python resend.Automations.create({ "name": "Post-Purchase", "steps": [ {"id": "trigger", "type": "trigger", "trigger_on": "purchase"}, {"id": "confirmation", "type": "send_email", "source_mail": "order@example.com"}, {"id": "wait", "type": "delay", "action": "wait_days:3"}, {"id": "followup", "type": "send_email", "source_mail": "feedback@example.com"}, ], "connections": [ {"from": "trigger", "to": "confirmation"}, {"from": "confirmation", "to": "wait"}, {"from": "wait", "to": "followup"}, ], "status": "enabled" }) ``` -------------------------------- ### Multi-segment Management Example Source: https://github.com/resend/resend-python/blob/main/_autodocs/contact-segments.md Illustrates creating multiple segments and then adding a single contact to both. This is useful for categorizing contacts into various groups simultaneously. ```python import resend # Create segments premium = resend.Segments.create({ "name": "Premium Customers", "audience_id": "audience_main" }) active = resend.Segments.create({ "name": "Active Users", "audience_id": "audience_main" }) # Add contact to multiple segments contact = resend.Contacts.get("contact_xyz") resend.Contacts.Segments.add( contact_id=contact["id"], segment_id=premium["id"] ) resend.Contacts.Segments.add( contact_id=contact["id"], segment_id=active["id"] ) # Check segment membership segments = resend.Contacts.Segments.list(contact["id"]) for segment in segments["data"]: print(f"Member of: {segment['name']}") ``` -------------------------------- ### Segment-based Broadcasts Example Source: https://github.com/resend/resend-python/blob/main/_autodocs/contact-segments.md Shows how to retrieve a contact and then list their segment memberships, which can be used for targeted communication like broadcasts. ```python import resend # Get VIP contacts contact = resend.Contacts.get("contact_premium_user") segments = resend.Contacts.Segments.list(contact["id"]) ``` -------------------------------- ### Global Configuration Setup Source: https://github.com/resend/resend-python/blob/main/_autodocs/configuration.md Set global configuration options for the Resend Python SDK, including API key, API URL, and default HTTP clients. ```python import resend resend.api_key = "re_yourkey" resend.api_url = "https://api.resend.com" resend.default_http_client = resend.RequestsClient() resend.default_async_http_client = resend.HTTPXClient() ``` -------------------------------- ### get() Source: https://github.com/resend/resend-python/blob/main/_autodocs/domains.md Retrieves details for a specific domain using its unique ID. Returns all domain configuration settings. ```APIDOC ## get() ### Description Retrieve a single domain by ID. ### Method GET (inferred from get operation) ### Endpoint /domains/{domain_id} (inferred from context and parameter) ### Parameters #### Path Parameters - **domain_id** (str) - Required - The domain ID ### Response #### Success Response (200) - **id** (str) - Domain ID - **name** (str) - Domain name - **created_at** (str) - ISO 8601 creation timestamp - **status** (str) - Verification status - **region** (str) - AWS region - **records** (Union[List[Record], None]) - DNS records to configure - **open_tracking** (Optional[bool]) - Open tracking enabled - **click_tracking** (Optional[bool]) - Click tracking enabled - **tracking_subdomain** (Optional[str]) - Tracking subdomain #### Response Example ```json { "id": "domain_abc123", "name": "example.com", "created_at": "2023-10-27T10:00:00Z", "status": "verified", "region": "us-east-1", "records": null, "open_tracking": true, "click_tracking": true, "tracking_subdomain": "links" } ``` ``` -------------------------------- ### Get Resend SDK Version Source: https://github.com/resend/resend-python/blob/main/_autodocs/configuration.md Retrieve the currently installed version of the Resend Python SDK. This can be done using the __version__ attribute or the get_version() function. ```python import resend version = resend.__version__ print(version) # e.g., "0.9.0" # Or using get_version() version = resend.get_version() ``` -------------------------------- ### Verify Webhook Signature (Flask Example) Source: https://github.com/resend/resend-python/blob/main/_autodocs/webhooks.md Verifies the authenticity of an incoming webhook request using the Resend-Signature header and a signing secret. This example is for a Flask application. ```python import resend from flask import Flask, request app = Flask(__name__) @app.route("/webhooks/resend", methods=["POST"]) def handle_webhook(): try: event = resend.Webhooks.verify( body=request.get_data(), signature=request.headers.get("Resend-Signature", ""), options={ "signing_secret": "whsec_abc123..." } ) print(f"Event type: {event['type']}") print(f"Email ID: {event['data']['email_id']}") return {"status": "ok"}, 200 except ValueError as e: print(f"Invalid signature: {e}") return {"error": "Invalid signature"}, 401 ``` -------------------------------- ### Resend Python SDK Setup Source: https://github.com/resend/resend-python/blob/main/_autodocs/README.md Initialize the Resend Python SDK by setting your API key and optionally configuring the API endpoint. The API key can be set directly or loaded from environment variables. ```python import resend # Set API key (from environment or explicitly) resend.api_key = "re_yourkey" # Configure API endpoint (optional) resend.api_url = "https://api.resend.com" ``` -------------------------------- ### Send Email with Resend SDK Source: https://github.com/resend/resend-python/blob/main/_autodocs/configuration.md Basic example of sending an email using the Resend Python SDK. Ensure your API key is set. ```python import resend email = resend.Emails.send({ "from": "hello@example.com", "to": "user@example.com", "subject": "Hello", "html": "

Hello

" }) ``` -------------------------------- ### Email Parameters with Tags Source: https://github.com/resend/resend-python/blob/main/_autodocs/types.md Example demonstrating how to include tags in email parameters for tracking. Tags are provided as a list of dictionaries, each with a 'name' and an optional 'value'. ```python params = { "from": "hello@example.com", "to": "user@example.com", "subject": "Welcome", "html": "

Welcome

", "tags": [ {"name": "campaign", "value": "welcome_series"}, {"name": "type", "value": "onboarding"} ] } ``` -------------------------------- ### Send Email Using Template Source: https://github.com/resend/resend-python/blob/main/_autodocs/templates.md Send an email using a predefined template, substituting variables. This example shows basic variable substitution. ```python email_response = resend.Emails.send({ "from": "hello@example.com", "to": "user@example.com", "template": { "id": "template_abc123", "variables": { "name": "John", "order_id": 12345 } } }) ``` -------------------------------- ### Asynchronous Event Creation and Sending Source: https://github.com/resend/resend-python/blob/main/_autodocs/events.md This example demonstrates how to asynchronously create an event with a schema and send an event using async methods. Ensure you have the asyncio library imported and Resend API key configured. ```python import asyncio import resend resend.api_key = "re_yourkey" async def main(): # Create event async response = await resend.Events.create_async({ "name": "order_shipped", "schema": { "order_id": "string", "tracking_number": "string", "estimated_delivery": "date" } }) print(f"Created: {response['id']}") # Send event async await resend.Events.send_async({ "event": "order_shipped", "email": "customer@example.com", "payload": { "order_id": "ord_123", "tracking_number": "track_456", "estimated_delivery": "2024-01-15" } }) asyncio.run(main()) ``` -------------------------------- ### Access Default Async HTTP Client Source: https://github.com/resend/resend-python/blob/main/_autodocs/configuration.md The default asynchronous HTTP client is `resend.HTTPXClient` if `httpx` is installed. ```python import resend print(resend.default_async_http_client) # instance ``` -------------------------------- ### get() Source: https://github.com/resend/resend-python/blob/main/_autodocs/events.md Retrieve a single event by its ID or name. ```APIDOC ## GET /events/{event_id} ### Description Retrieve a single event by its ID or name. ### Method GET ### Endpoint /events/{event_id} ### Parameters #### Path Parameters - **event_id** (str) - Required - Event ID (UUID) or event name ### Response #### Success Response (200) - **id** (str) - Event ID - **name** (str) - Event name - **schema** (object) - Event schema (or null) - **created_at** (str) - ISO 8601 creation timestamp #### Response Example ```json { "id": "event_abc123", "name": "purchase_completed", "schema": { "user_id": "string", "amount": "number", "currency": "string" }, "created_at": "2023-10-26T10:00:00Z" } ``` ``` -------------------------------- ### get() Source: https://github.com/resend/resend-python/blob/main/_autodocs/automations.md Retrieve a single automation by its ID. This method allows you to fetch all details of a specific automation workflow, including its steps and connections. ```APIDOC ## get() ### Description Retrieve a single automation by ID. ### Method GET (Implicit) ### Endpoint /automations/{automation_id} ### Parameters #### Path Parameters - **automation_id** (str) - Yes - The automation ID ### Return Type `Automation` - All automation fields including steps and connections ### Example ```python automation = resend.Automations.get("automation_abc123") print(f"Name: {automation['name']}") print(f"Status: {automation['status']}") print(f"Steps: {len(automation['steps'])}") ``` ``` -------------------------------- ### Send a Single Email Source: https://github.com/resend/resend-python/blob/main/_autodocs/README.md Basic example of sending a single email using the Resend SDK. Ensure your API key is set before sending. ```python import resend resend.api_key = "re_yourkey" email = resend.Emails.send({ "from": "hello@example.com", "to": "user@example.com", "subject": "Hello", "html": "

Hello!

" }) print(f"Sent: {email['id']}") ``` -------------------------------- ### Handling MissingApiKeyError Source: https://github.com/resend/resend-python/blob/main/_autodocs/errors.md This example shows how to specifically catch a MissingApiKeyError, which occurs when the API key is not provided. It includes a note on the suggested action for resolving this issue. ```python import resend # Not setting API key resend.api_key = None try: email = resend.Emails.send({ "to": "user@example.com", "subject": "Hello", "html": "

Hello

" }) except resend.MissingApiKeyError as e: print("Missing API key!") # Suggested action: Set resend.api_key or RESEND_API_KEY env var ``` -------------------------------- ### Template Variable Syntax Example Source: https://github.com/resend/resend-python/blob/main/_autodocs/templates.md Illustrates how to use double curly braces in HTML or text content to reference template variables. Undefined variables are replaced with empty strings. ```html

Hello {{name}},

Your order #{{order_id}} is confirmed.

Total: {{amount}}

``` -------------------------------- ### Async List and Get Logs Source: https://github.com/resend/resend-python/blob/main/_autodocs/logs.md Provides asynchronous equivalents for listing and retrieving log entries, suitable for non-blocking operations in async applications. Requires an active asyncio event loop. ```python import asyncio import resend resend.api_key = "re_yourkey" async def main(): # List logs async logs = await resend.Logs.list_async({"limit": 10}) print(f"Total logs: {len(logs['data'])}") # Get specific log async if logs["data"]: log = await resend.Logs.get_async(logs["data"][0]["id"]) print(f"Status: {log['response_status']}") asyncio.run(main()) ``` -------------------------------- ### Asynchronous Contact Management Source: https://github.com/resend/resend-python/blob/main/_autodocs/contacts.md Demonstrates asynchronous operations for creating, listing, updating, getting, and removing contacts using the Resend Python SDK. Ensure you have set your API key. ```python import asyncio import resend resend.api_key = "re_yourkey" async def main(): # Create async response = await resend.Contacts.create_async({ "email": "user@example.com", "first_name": "User" }) print(f"Created: {response['id']}") # List async contacts = await resend.Contacts.list_async({"limit": 10}) print(f"Total contacts: {len(contacts['data'])}") # Update async await resend.Contacts.update_async({ "id": response["id"], "last_name": "Test" }) # Get async contact = await resend.Contacts.get_async(response["id"]) print(f"Email: {contact['email']}") # Remove async await resend.Contacts.remove_async(response["id"]) asyncio.run(main()) ``` -------------------------------- ### Real Estate Custom Properties Source: https://github.com/resend/resend-python/blob/main/_autodocs/contact-properties.md Provides examples of creating custom properties for real estate use cases, such as agent ID, budget, preferred locations, last showing date, and buyer seriousness. ```python # Store property-specific information resend.ContactProperties.create({"name": "agent_id", "type": "string"}) resend.ContactProperties.create({"name": "budget", "type": "number"}) resend.ContactProperties.create({"name": "preferred_locations", "type": "string"}) resend.ContactProperties.create({"name": "last_showing_date", "type": "date"}) resend.ContactProperties.create({"name": "is_serious_buyer", "type": "boolean"}) ``` -------------------------------- ### Webhook Event Payload Example Source: https://github.com/resend/resend-python/blob/main/_autodocs/webhooks.md An example of the JSON payload for an 'email.sent' webhook event. This structure includes event type, timestamp, and specific data related to the sent email. ```json { "type": "email.sent", "created_at": "2024-01-01T00:00:00.000Z", "data": { "email_id": "email_abc123", "from": "hello@example.com", "to": ["user@example.com"], "created_at": "2024-01-01T00:00:00.000Z" } } ``` -------------------------------- ### Get Contact Source: https://github.com/resend/resend-python/blob/main/_autodocs/contacts.md Retrieves a specific contact by its ID. ```APIDOC ## Get Contact ### Description Retrieves a specific contact by its ID. ### Method GET ### Endpoint /contacts/{id} ### Parameters #### Path Parameters - **id** (str) - Required - The ID of the contact to retrieve. ### Response #### Success Response (200) - **id** (str) - Contact ID - **email** (str) - Email address - **first_name** (Optional[str]) - First name - **last_name** (Optional[str]) - Last name - **created_at** (str) - ISO 8601 creation timestamp - **unsubscribed** (bool) - Whether contact is unsubscribed #### Response Example ```json { "id": "con_xxxxxxxxxxxxxxxx", "email": "user@example.com", "first_name": "User", "last_name": null, "created_at": "2023-10-27T10:00:00Z", "unsubscribed": false } ``` ``` -------------------------------- ### get() Source: https://github.com/resend/resend-python/blob/main/_autodocs/broadcasts.md Retrieve the details of a single broadcast by its unique ID. ```APIDOC ## GET /v1/broadcasts/{broadcast_id} ### Description Retrieve a single broadcast by ID. ### Method GET ### Endpoint /v1/broadcasts/{broadcast_id} ### Parameters #### Path Parameters - **broadcast_id** (str) - Required - The broadcast ID ### Response #### Success Response (200) - All broadcast fields ### Response Example ```json { "id": "broadcast_abc123", "name": "Summer Promo", "status": "draft", "subject": "Summer Sale", "from": "hello@example.com", "created_at": "2024-01-01T12:00:00Z", "updated_at": "2024-01-01T12:00:00Z" } ``` ``` -------------------------------- ### get() Source: https://github.com/resend/resend-python/blob/main/_autodocs/contact-properties.md Retrieves a specific contact property definition by its unique ID. ```APIDOC ## get() ### Description Retrieve a single property by ID. ### Method `GET` (Assumed based on get operation) ### Endpoint `/v1/contact-properties/{property_id}` (Assumed based on typical REST patterns) ### Parameters #### Path Parameters - **property_id** (str) - Required - The property ID ### Response #### Success Response (200) - **id** (str) - The property ID - **name** (str) - Property name - **type** (str) - Data type - **created_at** (str) - Timestamp of creation #### Response Example ```json { "id": "prop_abc123", "name": "phone_number", "type": "string", "created_at": "2023-01-01T12:00:00Z" } ``` ``` -------------------------------- ### Create User Lifecycle Event Schemas Source: https://github.com/resend/resend-python/blob/main/_autodocs/events.md Defines schemas for 'user_signup' and 'user_trial_ending' events. These help standardize user-related event data. ```python resend.Events.create({ "name": "user_signup", "schema": { "user_id": "string", "plan_tier": "string", "signup_date": "date" } }) resend.Events.create({ "name": "user_trial_ending", "schema": { "user_id": "string", "days_remaining": "number" } }) ``` -------------------------------- ### Get Webhook Source: https://github.com/resend/resend-python/blob/main/_autodocs/webhooks.md Retrieves the details of a specific webhook endpoint using its ID. ```APIDOC ## GET /webhooks/{webhook_id} ### Description Retrieve a single webhook by its ID. ### Method GET ### Endpoint /webhooks/{webhook_id} ### Parameters #### Path Parameters - **webhook_id** (str) - Required - The ID of the webhook to retrieve. ### Response #### Success Response (200) - **id** (str): The webhook ID. - **object** (str): Always "webhook". - **endpoint** (str): The webhook endpoint URL. - **events** (List[str]): The subscribed event types. - **status** (str): The status of the webhook ('enabled' or 'disabled'). - **signing_secret** (str): The webhook signing secret. - **created_at** (str): Timestamp of when the webhook was created. #### Response Example ```json { "object": "webhook", "id": "whk_abc123", "endpoint": "https://example.com/webhooks/resend", "events": ["email.sent", "email.delivered"], "status": "enabled", "signing_secret": "your_signing_secret_here", "created_at": "2023-10-27T10:00:00Z" } ``` ``` -------------------------------- ### Create Marketing Topics Source: https://github.com/resend/resend-python/blob/main/_autodocs/topics.md Creates three distinct 'opt-in' topics suitable for marketing communications, each with a specific focus and description. ```python # Create opt-in topics for different email types resend.Topics.create({ "name": "Marketing Newsletter", "default_subscription": "opt_in", "description": "Promotional offers and new product launches" }) resend.Topics.create({ "name": "Product Updates", "default_subscription": "opt_in", "description": "New features and improvements" }) resend.Topics.create({ "name": "Event Invitations", "default_subscription": "opt_in", "description": "Invitations to webinars and events" }) ``` -------------------------------- ### Get a Single Audience Source: https://github.com/resend/resend-python/blob/main/_autodocs/audiences.md Retrieve details for a specific audience using its ID. ```python audience = resend.Audiences.get("audience_abc123") print(f"Audience: {audience['name']}") print(f"Created: {audience['created_at']}") ``` -------------------------------- ### get() Source: https://github.com/resend/resend-python/blob/main/_autodocs/audiences.md Retrieve a single audience by its unique ID. This method returns the details of a specific audience. ```APIDOC ## GET /audiences/{audience_id} ### Description Retrieve a single audience by its ID. ### Method GET ### Endpoint /audiences/{audience_id} ### Parameters #### Path Parameters - **audience_id** (str) - Required - The ID of the audience to retrieve ### Response #### Success Response (200 OK) - **id** (str) - Audience ID - **name** (str) - Audience name - **created_at** (str) - ISO 8601 creation timestamp #### Response Example ```json { "id": "aud_12345", "name": "Premium Customers", "created_at": "2023-10-26T10:00:00Z" } ``` ``` -------------------------------- ### Async Methods for Contact Properties Source: https://github.com/resend/resend-python/blob/main/_autodocs/contact-properties.md Shows how to asynchronously create and list contact properties using `create_async()` and `list_async()`. Ensure Resend API key is set. ```python import asyncio import resend resend.api_key = "re_yourkey" async def main(): # Create property async response = await resend.ContactProperties.create_async({ "name": "preferred_language", "type": "string" }) print(f"Created: {response['id']}") # List properties async props = await resend.ContactProperties.list_async({"limit": 10}) print(f"Total properties: {len(props['data'])}") asyncio.run(main()) ``` -------------------------------- ### create() Source: https://github.com/resend/resend-python/blob/main/_autodocs/api-keys.md Adds a new API key for authentication. It requires a name and can optionally include permission levels and a domain ID for restricted access. ```APIDOC ## POST /v1/keys ### Description Creates a new API key for authentication. You can specify the key's name, permission level, and optionally restrict it to a specific domain. ### Method POST ### Endpoint /v1/keys ### Parameters #### Request Body - **name** (str) - Required - Name for the API key - **permission** (str) - Optional - Permission level: "full_access" (all operations) or "sending_access" (send emails only). Defaults to "full_access". - **domain_id** (str) - Optional - Restrict sending to a specific domain (only with sending_access permission) ### Response #### Success Response (200) - **id** (str) - The ID of the created API key - **token** (str) - The API key token (only visible on creation) ### Response Example ```json { "id": "key_abc123", "token": "re_xxxxxxxxxxxxxxxxxxxxxxxx" } ``` ### Throws - **ValidationError**: Missing required fields - **InvalidApiKeyError**: Invalid permission or domain_id ``` -------------------------------- ### Paginate Through Logs Source: https://github.com/resend/resend-python/blob/main/_autodocs/logs.md Demonstrates how to retrieve logs page by page using cursor-based pagination. Essential for handling large log volumes efficiently. ```python import resend # Get first page response = resend.Logs.list({"limit": 20}) print(f"Page 1: {len(response['data'])} logs") # Get next page if available if response["has_more"]: next_response = resend.Logs.list({ "limit": 20, "after": response["data"][-1]["id"] }) print(f"Page 2: {len(next_response['data'])} logs") ``` -------------------------------- ### get() Source: https://github.com/resend/resend-python/blob/main/_autodocs/templates.md Retrieves a single email template by its unique ID, returning all its details including HTML content and variables. ```APIDOC ## get() ### Description Retrieve a single template by ID. ### Method GET (inferred from SDK method) ### Endpoint /templates/{template_id} (inferred from SDK context and parameters) ### Parameters #### Path Parameters - **template_id** (str) - Required - The template ID ### Response #### Success Response (200) - All template fields including HTML, subject, variables, etc. ### Request Example ```python template = resend.Templates.get("template_abc123") print(f"Subject: {template['subject']}") print(f"Variables: {template.get('variables', [])}") ``` ``` -------------------------------- ### Configure Custom Async Client Source: https://github.com/resend/resend-python/blob/main/README.md Override the default HTTP client to customize settings like timeouts. ```python import resend resend.api_key = "re_yourkey" resend.default_async_http_client = resend.HTTPXClient(timeout=60) ``` -------------------------------- ### Create Transactional and Marketing Topics Source: https://github.com/resend/resend-python/blob/main/_autodocs/topics.md Creates both an 'opt-out' transactional topic for essential business operations and an 'opt-in' marketing topic for promotional content. ```python # Transactional (opt-out) - important for business operations transactional = resend.Topics.create({ "name": "Transactional", "default_subscription": "opt_out", "description": "Order confirmations, receipts, password resets" }) # Marketing (opt-in) - promotional content marketing = resend.Topics.create({ "name": "Marketing", "default_subscription": "opt_in", "description": "Promotions, offers, and marketing content" }) ``` -------------------------------- ### get() Source: https://github.com/resend/resend-python/blob/main/_autodocs/emails.md Retrieves a single email by its unique identifier. This method allows fetching details of a previously sent or scheduled email. ```APIDOC ## get() ### Description Retrieve a single email by ID. ### Method GET (inferred from SDK method) ### Endpoint /emails/{email_id} (inferred from SDK context) ### Parameters #### Path Parameters - **email_id** (str) - Required - The ID of the email to retrieve ### Response #### Success Response (200) - **id** (str) - The Email ID - **from** (str) - The sender email address - **to** (Union[List[str], str]) - Recipients - **created_at** (str) - When the email was created - **subject** (str) - Email subject - **html** (str) - HTML content - **text** (str) - Plain text content - **bcc** (Union[List[str], str]) - Blind carbon copy addresses - **cc** (Union[List[str], str]) - Carbon copy addresses - **reply_to** (Union[List[str], str]) - Reply-to addresses - **last_event** (str) - The last event of the email ### Response Example ```json { "id": "email_123456", "from": "sender@example.com", "to": ["recipient@example.com"], "created_at": "2024-01-01T12:00:00Z", "subject": "Test Email", "html": "

This is a test email.

", "text": "This is a test email.", "bcc": [], "cc": [], "reply_to": [], "last_event": "sent" } ``` ``` -------------------------------- ### create() Source: https://github.com/resend/resend-python/blob/main/_autodocs/automations.md Create a new automation workflow with specified name, steps, and connections. An optional status can be provided to enable or disable the automation upon creation. ```APIDOC ## POST /automations ### Description Creates a new automation workflow. ### Method POST ### Endpoint /automations ### Parameters #### Request Body - **name** (str) - Required - Automation workflow name - **steps** (List[AutomationStep]) - Required - Workflow steps (must include at least one trigger) - **connections** (List[AutomationConnection]) - Required - Connections between steps - **status** (AutomationStatus) - Optional - Initial status: "enabled" or "disabled" (default) ### Response #### Success Response (200) - **object** (str) - Always "automation" - **id** (str) - The automation ID ``` -------------------------------- ### Create and Update Contact with Custom Properties Source: https://github.com/resend/resend-python/blob/main/_autodocs/contact-properties.md Demonstrates how to add custom fields like phone number, lifetime value, last purchase date, and VIP status when creating or updating a contact. ```python # Create contact with custom properties contact = resend.Contacts.create({ "email": "john@example.com", "first_name": "John", "last_name": "Doe", # Custom properties stored as additional fields "phone_number": "555-1234", "lifetime_value": 5000, "last_purchase_date": "2024-01-15", "is_vip": True }) # Update contact with custom properties resend.Contacts.update({ "id": contact["id"], "phone_number": "555-5678", "lifetime_value": 7500, "is_vip": False }) ``` -------------------------------- ### Configure Staging Environment Source: https://github.com/resend/resend-python/blob/main/_autodocs/configuration.md Set API key and URL for the staging environment. This allows testing against a staging API endpoint. ```python import resend # Use staging credentials resend.api_key = "re_staging_xxxxx" resend.api_url = "https://staging-api.resend.com" # if available ``` -------------------------------- ### Create Broadcast to Segment Source: https://github.com/resend/resend-python/blob/main/_autodocs/segments.md Example of creating a broadcast that targets a specific segment. The `segment_id` parameter is crucial for directing the broadcast to the intended audience. ```python response = resend.Broadcasts.create({ "from": "hello@example.com", "segment_id": "segment_abc123", # Send to this segment "subject": "Premium Offer", "html": "

Special Offer for Premium Users

", "send": True }) ``` -------------------------------- ### Set API Key via Environment Variable Source: https://github.com/resend/resend-python/blob/main/_autodocs/configuration.md Recommended method for setting the API key. The SDK automatically loads it if the RESEND_API_KEY environment variable is set. ```bash export RESEND_API_KEY="re_yourkey" ``` ```python import resend # api_key is automatically loaded from environment print(resend.api_key) # "re_yourkey" ``` -------------------------------- ### create() Source: https://github.com/resend/resend-python/blob/main/_autodocs/templates.md Creates a new email template with specified parameters, including name, HTML content, and optional configurations like alias, sender, subject, and variables. ```APIDOC ## create() ### Description Create a new email template. ### Method POST (inferred from SDK method) ### Endpoint /templates (inferred from SDK context) ### Parameters #### Request Body - **params** (CreateParams) - Required - Template creation parameters - **name** (str) - Required - Template name - **html** (str) - Required - HTML content of the template - **alias** (str) - Optional - Unique alias for the template - **from** (str) - Optional - Default sender email - **subject** (str) - Optional - Default subject line - **reply_to** (Union[List[str], str]) - Optional - Default reply-to email(s) - **text** (str) - Optional - Plain text version - **variables** (List[Variable]) - Optional - Template variables (max 20 per template) ### Response #### Success Response (200) - **id** (str) - The template ID - **object** (str) - Always "template" ### Request Example ```python import resend resend.api_key = "re_yourkey" response = resend.Templates.create({ "name": "Welcome Email", "alias": "welcome", "from": "hello@example.com", "subject": "Welcome {{name}}!", "html": "

Welcome {{name}}

Thanks for joining!

", "variables": [ { "name": "name", "description": "User's name", "type": "string", "required": True } ] }) print(f"Template created: {response['id']}") ``` ``` -------------------------------- ### Get a Single Webhook Source: https://github.com/resend/resend-python/blob/main/_autodocs/webhooks.md Retrieve the details of a specific webhook using its unique ID. This includes the endpoint, status, events, and signing secret. ```python webhook = resend.Webhooks.get("webhook_abc123") print(f"Endpoint: {webhook['endpoint']}") print(f"Status: {webhook['status']}") print(f"Events: {webhook['events']}") ``` -------------------------------- ### Asynchronous Audience Operations Source: https://github.com/resend/resend-python/blob/main/_autodocs/audiences.md Perform audience operations asynchronously using async/await syntax. Includes create, list, get, and remove operations. ```python import asyncio import resend resend.api_key = "re_yourkey" async def main(): # Create async response = await resend.Audiences.create_async({ "name": "Newsletter Subscribers" }) print(f"Created: {response['id']}") # List async audiences = await resend.Audiences.list_async({"limit": 10}) print(f"Total audiences: {len(audiences['data'])}") # Get async audience = await resend.Audiences.get_async(response["id"]) print(f"Name: {audience['name']}") # Remove async await resend.Audiences.remove_async(response["id"]) asyncio.run(main()) ``` -------------------------------- ### Async Methods Source: https://github.com/resend/resend-python/blob/main/_autodocs/api-keys.md Provides asynchronous equivalents for creating, listing, and removing API keys, allowing for non-blocking operations. ```APIDOC ## Async API Keys Operations All methods available in the synchronous API Keys API have asynchronous counterparts, suffixed with `_async`. ### create_async() - Asynchronously creates a new API key. ### list_async() - Asynchronously retrieves a paginated list of API keys. ### remove_async() - Asynchronously deletes an API key by its ID. **Example:** ```python import asyncio import resend resend.api_key = "re_yourkey" async def main(): # Create async response = await resend.ApiKeys.create_async({ "name": "Async Key", "permission": "full_access" }) print(f"Created: {response['id']}") # List async keys = await resend.ApiKeys.list_async({"limit": 10}) print(f"Total keys: {len(keys['data'])}") # Remove async await resend.ApiKeys.remove_async(response["id"]) print("Key deleted") asyncio.run(main()) ``` ``` -------------------------------- ### Async Methods Source: https://github.com/resend/resend-python/blob/main/_autodocs/logs.md Asynchronous equivalents for listing and retrieving log entries are available as `list_async()` and `get_async()`. ```APIDOC ## Async Methods ### Description Asynchronous equivalents for listing and retrieving log entries are available as `list_async()` and `get_async()`. ### Method - `list_async(params: Optional[ListParams] = None)` - `get_async(log_id: str)` ### Parameters - **params** (`Optional[ListParams]`) - Optional - Pagination parameters for `list_async()` - **limit** (`Optional[int]`) - Number of logs (1-100, default 10) - **after** (`Optional[str]`) - Cursor for pagination - **before** (`Optional[str]`) - Cursor for pagination - **log_id** (`str`) - Required - The log ID for `get_async()` ### Request Example ```python import asyncio import resend resend.api_key = "re_yourkey" async def main(): # List logs async logs = await resend.Logs.list_async({"limit": 10}) print(f"Total logs: {len(logs['data'])}") # Get specific log async if logs["data"]: log = await resend.Logs.get_async(logs["data"][0]["id"]) print(f"Status: {log['response_status']}") asyncio.run(main()) ``` ### Response - `list_async()` returns a `ListResponse` object similar to `list()`. - `get_async()` returns a `Log` object similar to `get()`. ``` -------------------------------- ### create() Source: https://github.com/resend/resend-python/blob/main/_autodocs/audiences.md Create a new audience. This method takes audience creation parameters and returns the details of the newly created audience. ```APIDOC ## POST /audiences ### Description Create a new audience group for organizing contacts. ### Method POST ### Endpoint /audiences ### Parameters #### Request Body - **name** (str) - Required - The audience name ### Request Example ```json { "name": "Premium Customers" } ``` ### Response #### Success Response (200 OK) - **object** (str) - Always "audience" - **id** (str) - The created audience ID - **name** (str) - The audience name #### Response Example ```json { "object": "audience", "id": "aud_12345", "name": "Premium Customers" } ``` ``` -------------------------------- ### Get Single Log Entry by ID Source: https://github.com/resend/resend-python/blob/main/_autodocs/logs.md Retrieves a specific log entry using its unique ID. This is useful for detailed inspection of a single request/response. ```python log = resend.Logs.get("log_abc123") print(f"Endpoint: {log['endpoint']}") print(f"Status: {log['response_status']}") print(f"Request body: {log['request_body']}") print(f"Response body: {log['response_body']}") ``` -------------------------------- ### Send Email with Remote Attachment Source: https://github.com/resend/resend-python/blob/main/_autodocs/types.md Example of sending an email with a remote file attachment. The attachment is specified using its HTTPS URL and an optional display filename. ```python attachment = { "path": "https://cdn.example.com/invoice.pdf", "filename": "invoice.pdf" } email = resend.Emails.send({ "from": "hello@example.com", "to": "user@example.com", "subject": "Your invoice", "html": "

Invoice attached

", "attachments": [attachment] }) ``` -------------------------------- ### create() Source: https://github.com/resend/resend-python/blob/main/_autodocs/domains.md Creates a new email domain. Requires domain name and optionally accepts region. Returns domain details and DNS records for verification. ```APIDOC ## create() ### Description Create a new email domain. ### Method POST (inferred from create operation) ### Endpoint /domains (inferred from context) ### Parameters #### Request Body - **name** (str) - Required - The domain name (e.g., "example.com") - **region** (str) - Optional - AWS region: "us-east-1" (default), "eu-west-1", "sa-east-1", "ap-northeast-1" ### Request Example ```python { "name": "example.com", "region": "us-east-1" } ``` ### Response #### Success Response (200) - **id** (str) - Domain ID - **name** (str) - Domain name - **created_at** (str) - ISO 8601 creation timestamp - **status** (str) - Verification status - **region** (str) - AWS region - **records** (Union[List[Record], None]) - DNS records to configure - **open_tracking** (Optional[bool]) - Open tracking enabled - **click_tracking** (Optional[bool]) - Click tracking enabled - **tracking_subdomain** (Optional[str]) - Tracking subdomain #### Response Example ```json { "id": "domain_id_123", "name": "example.com", "created_at": "2023-10-27T10:00:00Z", "status": "verified", "region": "us-east-1", "records": [ { "type": "TXT", "name": "_dmarc.example.com", "value": "v=DMARC1; p=none" } ], "open_tracking": true, "click_tracking": true, "tracking_subdomain": "mail" } ``` ``` -------------------------------- ### create() Source: https://github.com/resend/resend-python/blob/main/_autodocs/broadcasts.md Create a new broadcast, either as a draft or to be sent immediately. You can specify the sender, recipient segment, subject, and content. ```APIDOC ## POST /v1/broadcasts ### Description Create a new broadcast (draft or send immediately). ### Method POST ### Endpoint /v1/broadcasts ### Parameters #### Request Body - **from** (str) - Required - Sender email address - **segment_id** (str) - Optional - Segment ID to send to (use either segment_id or audience_id) - **audience_id** (str) - Optional - (Deprecated) Audience ID - use segment_id instead - **subject** (str) - Required - Email subject line - **reply_to** (Union[List[str], str]) - Optional - Reply-to address(es) - **html** (str) - Optional - HTML content - **text** (str) - Optional - Plain text content - **name** (str) - Optional - Internal name for the broadcast - **send** (bool) - Optional - If true, send immediately; if false/omitted, create as draft - **scheduled_at** (str) - Optional - Schedule time (ISO 8601 or natural language) - only valid when send=true ### Response #### Success Response (200) - **object** (str) - "broadcast" - **id** (str) - The broadcast ID ### Request Example ```json { "from": "hello@example.com", "segment_id": "segment_abc123", "subject": "Summer Sale", "html": "

50% Off Everything!

", "name": "Summer Promo" } ``` ### Response Example ```json { "object": "broadcast", "id": "broadcast_abc123" } ``` ```