resend
Advanced tools
| from typing import Any, Dict, List, Optional, Union, cast | ||
| from typing_extensions import NotRequired, TypedDict | ||
| from resend import request | ||
| from resend.pagination_helper import PaginationHelper | ||
| from ._contact_property import ContactProperty | ||
| class ContactProperties: | ||
| class CreateResponse(TypedDict): | ||
| """ | ||
| CreateResponse is the type that wraps the response of the contact property that was created. | ||
| Attributes: | ||
| id (str): The ID of the created contact property | ||
| object (str): The object type, always "contact_property" | ||
| """ | ||
| id: str | ||
| """ | ||
| The ID of the created contact property. | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type, always "contact_property". | ||
| """ | ||
| class UpdateResponse(TypedDict): | ||
| """ | ||
| UpdateResponse is the type that wraps the response of the contact property that was updated. | ||
| Attributes: | ||
| id (str): The ID of the updated contact property | ||
| object (str): The object type, always "contact_property" | ||
| """ | ||
| id: str | ||
| """ | ||
| The ID of the updated contact property. | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type, always "contact_property". | ||
| """ | ||
| class RemoveResponse(TypedDict): | ||
| """ | ||
| RemoveResponse is the type that wraps the response of the contact property that was removed. | ||
| Attributes: | ||
| id (str): The ID of the removed contact property | ||
| object (str): The object type, always "contact_property" | ||
| deleted (bool): Whether the contact property was deleted | ||
| """ | ||
| id: str | ||
| """ | ||
| The ID of the removed contact property. | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type, always "contact_property". | ||
| """ | ||
| deleted: bool | ||
| """ | ||
| Whether the contact property was deleted. | ||
| """ | ||
| class ListParams(TypedDict): | ||
| """ | ||
| ListParams is the class that wraps the parameters for the list method. | ||
| Attributes: | ||
| limit (NotRequired[int]): Number of contact properties to retrieve. Maximum is 100, minimum is 1. | ||
| after (NotRequired[str]): The ID after which we'll retrieve more contact properties (for pagination). | ||
| before (NotRequired[str]): The ID before which we'll retrieve more contact properties (for pagination). | ||
| """ | ||
| limit: NotRequired[int] | ||
| """ | ||
| Number of contact properties to retrieve. Maximum is 100, minimum is 1. | ||
| """ | ||
| after: NotRequired[str] | ||
| """ | ||
| The ID after which we'll retrieve more contact properties (for pagination). | ||
| This ID will not be included in the returned list. | ||
| Cannot be used with the before parameter. | ||
| """ | ||
| before: NotRequired[str] | ||
| """ | ||
| The ID before which we'll retrieve more contact properties (for pagination). | ||
| This ID will not be included in the returned list. | ||
| Cannot be used with the after parameter. | ||
| """ | ||
| class ListResponse(TypedDict): | ||
| """ | ||
| ListResponse type that wraps a list of contact property objects with pagination metadata. | ||
| Attributes: | ||
| object (str): The object type, always "list" | ||
| data (List[ContactProperty]): A list of contact property objects | ||
| has_more (bool): Whether there are more results available | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type, always "list". | ||
| """ | ||
| data: List[ContactProperty] | ||
| """ | ||
| A list of contact property objects. | ||
| """ | ||
| has_more: bool | ||
| """ | ||
| Whether there are more results available for pagination. | ||
| """ | ||
| class CreateParams(TypedDict): | ||
| """ | ||
| CreateParams is the class that wraps the parameters for creating a contact property. | ||
| Attributes: | ||
| key (str): The key name of the property | ||
| type (str): The data type of the property (e.g., "string", "number", "boolean") | ||
| fallback_value (NotRequired[Any]): The default value used when a contact doesn't have this property set | ||
| """ | ||
| key: str | ||
| """ | ||
| The key name of the property. | ||
| """ | ||
| type: str | ||
| """ | ||
| The data type of the property (e.g., "string", "number", "boolean"). | ||
| """ | ||
| fallback_value: NotRequired[Union[str, int, float, None]] | ||
| """ | ||
| The default value used when a contact doesn't have this property set. | ||
| Must match the type specified in the type field (string or number). | ||
| """ | ||
| class UpdateParams(TypedDict): | ||
| """ | ||
| UpdateParams is the class that wraps the parameters for updating a contact property. | ||
| Attributes: | ||
| id (str): The contact property ID | ||
| fallback_value (Union[str, int, float, None]): The default value used when a contact doesn't have this property set | ||
| """ | ||
| id: str | ||
| """ | ||
| The contact property ID. | ||
| """ | ||
| fallback_value: Union[str, int, float, None] | ||
| """ | ||
| The default value used when a contact doesn't have this property set. | ||
| Must match the type of the property (string or number). | ||
| """ | ||
| @classmethod | ||
| def create(cls, params: CreateParams) -> CreateResponse: | ||
| """ | ||
| Create a new contact property. | ||
| see more: https://resend.com/docs/api-reference/contact-properties/create-contact-property | ||
| Args: | ||
| params (CreateParams): The contact property creation parameters | ||
| Returns: | ||
| CreateResponse: The created contact property response | ||
| """ | ||
| path = "/contact-properties" | ||
| resp = request.Request[ContactProperties.CreateResponse]( | ||
| path=path, params=cast(Dict[Any, Any], params), verb="post" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def list(cls, params: Optional[ListParams] = None) -> ListResponse: | ||
| """ | ||
| List all contact properties. | ||
| see more: https://resend.com/docs/api-reference/contact-properties/list-contact-properties | ||
| Args: | ||
| params (Optional[ListParams]): Optional pagination parameters | ||
| - limit: Number of contact properties to retrieve (max 100, min 1). | ||
| If not provided, all contact properties will be returned without pagination. | ||
| - after: ID after which to retrieve more contact properties | ||
| - before: ID before which to retrieve more contact properties | ||
| Returns: | ||
| ListResponse: A list of contact property objects | ||
| """ | ||
| base_path = "/contact-properties" | ||
| query_params = cast(Dict[Any, Any], params) if params else None | ||
| path = PaginationHelper.build_paginated_path(base_path, query_params) | ||
| resp = request.Request[ContactProperties.ListResponse]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def get(cls, id: str) -> ContactProperty: | ||
| """ | ||
| Get a contact property by ID. | ||
| see more: https://resend.com/docs/api-reference/contact-properties/get-contact-property | ||
| Args: | ||
| id (str): The contact property ID | ||
| Returns: | ||
| ContactProperty: The contact property object | ||
| """ | ||
| path = f"/contact-properties/{id}" | ||
| resp = request.Request[ContactProperty]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def update(cls, params: UpdateParams) -> UpdateResponse: | ||
| """ | ||
| Update an existing contact property. | ||
| see more: https://resend.com/docs/api-reference/contact-properties/update-contact-property | ||
| Args: | ||
| params (UpdateParams): The contact property update parameters | ||
| Returns: | ||
| UpdateResponse: The updated contact property response | ||
| """ | ||
| path = f"/contact-properties/{params['id']}" | ||
| # Build the payload without id (it's only used in the URL path) | ||
| payload: Dict[str, Any] = {"fallback_value": params["fallback_value"]} | ||
| resp = request.Request[ContactProperties.UpdateResponse]( | ||
| path=path, params=payload, verb="patch" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def remove(cls, id: str) -> RemoveResponse: | ||
| """ | ||
| Remove a contact property by ID. | ||
| see more: https://resend.com/docs/api-reference/contact-properties/delete-contact-property | ||
| Args: | ||
| id (str): The contact property ID | ||
| Returns: | ||
| RemoveResponse: The removed contact property response object | ||
| """ | ||
| path = f"/contact-properties/{id}" | ||
| resp = request.Request[ContactProperties.RemoveResponse]( | ||
| path=path, params={}, verb="delete" | ||
| ).perform_with_content() | ||
| return resp |
| from typing import Union | ||
| from typing_extensions import TypedDict | ||
| class ContactProperty(TypedDict): | ||
| """ | ||
| ContactProperty represents a custom property definition for contacts. | ||
| Attributes: | ||
| id (str): The unique identifier for the contact property | ||
| key (str): The key name of the property | ||
| object (str): The object type, always "contact_property" | ||
| created_at (str): The ISO 8601 timestamp when the property was created | ||
| type (str): The data type of the property (e.g., "string", "number") | ||
| fallback_value (Union[str, int, float, None]): The default value used when a contact doesn't have this property set | ||
| """ | ||
| id: str | ||
| """ | ||
| The unique identifier for the contact property. | ||
| """ | ||
| key: str | ||
| """ | ||
| The key name of the property. | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type, always "contact_property". | ||
| """ | ||
| created_at: str | ||
| """ | ||
| The ISO 8601 timestamp when the property was created. | ||
| """ | ||
| type: str | ||
| """ | ||
| The data type of the property (e.g., "string", "number"). | ||
| """ | ||
| fallback_value: Union[str, int, float, None] | ||
| """ | ||
| The default value used when a contact doesn't have this property set. | ||
| Must match the type of the property (string or number). | ||
| """ |
| from typing_extensions import TypedDict | ||
| class ContactTopic(TypedDict): | ||
| """ | ||
| ContactTopic represents a topic subscription for a contact. | ||
| Attributes: | ||
| id (str): The unique identifier for the topic | ||
| name (str): The name of the topic | ||
| description (str): The description of the topic | ||
| subscription (str): The subscription status. Must be either "opt_in" or "opt_out" | ||
| """ | ||
| id: str | ||
| """ | ||
| The unique identifier for the topic. | ||
| """ | ||
| name: str | ||
| """ | ||
| The name of the topic. | ||
| """ | ||
| description: str | ||
| """ | ||
| The description of the topic. | ||
| """ | ||
| subscription: str | ||
| """ | ||
| The subscription status. Must be either "opt_in" or "opt_out". | ||
| """ | ||
| class TopicSubscriptionUpdate(TypedDict): | ||
| """ | ||
| TopicSubscriptionUpdate represents an update to a topic subscription. | ||
| Attributes: | ||
| id (str): The topic ID | ||
| subscription (str): The subscription action. Must be either "opt_in" or "opt_out" | ||
| """ | ||
| id: str | ||
| """ | ||
| The topic ID. | ||
| """ | ||
| subscription: str | ||
| """ | ||
| The subscription action. Must be either "opt_in" or "opt_out". | ||
| """ |
| from typing import Any, Dict, List, Optional, Union, cast | ||
| from typing_extensions import NotRequired, TypedDict | ||
| from resend import request | ||
| from resend.pagination_helper import PaginationHelper | ||
| from ._contact_topic import ContactTopic, TopicSubscriptionUpdate | ||
| class _ListParams(TypedDict): | ||
| limit: NotRequired[int] | ||
| """ | ||
| Number of topics to retrieve. Maximum is 100, minimum is 1. | ||
| """ | ||
| after: NotRequired[str] | ||
| """ | ||
| The ID after which we'll retrieve more topics (for pagination). | ||
| """ | ||
| before: NotRequired[str] | ||
| """ | ||
| The ID before which we'll retrieve more topics (for pagination). | ||
| """ | ||
| class _ListResponse(TypedDict): | ||
| object: str | ||
| """ | ||
| The object type: "list" | ||
| """ | ||
| data: List[ContactTopic] | ||
| """ | ||
| The list of contact topic objects. | ||
| """ | ||
| has_more: bool | ||
| """ | ||
| Whether there are more topics available for pagination. | ||
| """ | ||
| class _UpdateParams(TypedDict): | ||
| id: NotRequired[str] | ||
| """ | ||
| The contact ID. | ||
| """ | ||
| email: NotRequired[str] | ||
| """ | ||
| The contact email. | ||
| """ | ||
| topics: List[TopicSubscriptionUpdate] | ||
| """ | ||
| List of topic subscription updates. | ||
| """ | ||
| class _UpdateResponse(TypedDict): | ||
| id: str | ||
| """ | ||
| The contact ID. | ||
| """ | ||
| class Topics: | ||
| """ | ||
| Topics class that provides methods for managing contact topic subscriptions. | ||
| """ | ||
| class ListParams(_ListParams): | ||
| """ | ||
| ListParams is the class that wraps the parameters for the list method. | ||
| Attributes: | ||
| limit (NotRequired[int]): Number of topics to retrieve. Maximum is 100, minimum is 1. | ||
| after (NotRequired[str]): Return topics after this cursor for pagination. | ||
| before (NotRequired[str]): Return topics before this cursor for pagination. | ||
| """ | ||
| class ListResponse(_ListResponse): | ||
| """ | ||
| ListResponse is the type that wraps the response for listing contact topics. | ||
| Attributes: | ||
| object (str): The object type: "list" | ||
| data (List[ContactTopic]): The list of contact topic objects. | ||
| has_more (bool): Whether there are more topics available for pagination. | ||
| """ | ||
| class UpdateParams(_UpdateParams): | ||
| """ | ||
| UpdateParams is the class that wraps the parameters for updating contact topic subscriptions. | ||
| Attributes: | ||
| id (NotRequired[str]): The contact ID (either id or email must be provided) | ||
| email (NotRequired[str]): The contact email (either id or email must be provided) | ||
| topics (List[TopicSubscriptionUpdate]): List of topic subscription updates | ||
| """ | ||
| class UpdateResponse(_UpdateResponse): | ||
| """ | ||
| UpdateResponse is the type that wraps the response for updating contact topics. | ||
| Attributes: | ||
| id (str): The contact ID | ||
| """ | ||
| @classmethod | ||
| def list( | ||
| cls, | ||
| contact_id: Optional[str] = None, | ||
| email: Optional[str] = None, | ||
| params: Optional["Topics.ListParams"] = None, | ||
| ) -> "Topics.ListResponse": | ||
| """ | ||
| List all topics for a contact. | ||
| see more: https://resend.com/docs/api-reference/contacts/list-contact-topics | ||
| Args: | ||
| contact_id (Optional[str]): The contact ID (either contact_id or email must be provided) | ||
| email (Optional[str]): The contact email (either contact_id or email must be provided) | ||
| params (Optional[ListParams]): Optional pagination parameters | ||
| - limit: Number of topics to retrieve (max 100, min 1). | ||
| If not provided, all topics will be returned without pagination. | ||
| - after: ID after which to retrieve more topics | ||
| - before: ID before which to retrieve more topics | ||
| Returns: | ||
| ListResponse: A list of contact topic objects | ||
| Raises: | ||
| ValueError: If neither contact_id nor email is provided | ||
| """ | ||
| contact = email if contact_id is None else contact_id | ||
| if contact is None: | ||
| raise ValueError("contact_id or email must be provided") | ||
| base_path = f"/contacts/{contact}/topics" | ||
| query_params = cast(Dict[Any, Any], params) if params else None | ||
| path = PaginationHelper.build_paginated_path(base_path, query_params) | ||
| resp = request.Request[_ListResponse]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def update(cls, params: UpdateParams) -> UpdateResponse: | ||
| """ | ||
| Update topic subscriptions for a contact. | ||
| see more: https://resend.com/docs/api-reference/contacts/update-contact-topics | ||
| Args: | ||
| params (UpdateParams): The topic update parameters | ||
| - id: The contact ID (either id or email must be provided) | ||
| - email: The contact email (either id or email must be provided) | ||
| - topics: List of topic subscription updates | ||
| Returns: | ||
| UpdateResponse: The updated contact response | ||
| Raises: | ||
| ValueError: If neither id nor email is provided in params | ||
| """ | ||
| if params.get("id") is None and params.get("email") is None: | ||
| raise ValueError("id or email must be provided") | ||
| contact = ( | ||
| params.get("id") if params.get("id") is not None else params.get("email") | ||
| ) | ||
| path = f"/contacts/{contact}/topics" | ||
| # Send the topics array directly as the request body (not wrapped in an object) | ||
| # The Request class accepts Union[Dict, List] as params | ||
| request_body: Union[Dict[str, Any], List[Dict[str, Any]]] = cast( | ||
| List[Dict[str, Any]], params["topics"] | ||
| ) | ||
| resp = request.Request[_UpdateResponse]( | ||
| path=path, params=request_body, verb="patch" | ||
| ).perform_with_content() | ||
| return resp |
| from typing_extensions import TypedDict | ||
| class ContactSegment(TypedDict): | ||
| id: str | ||
| """ | ||
| The unique identifier of the segment. | ||
| """ | ||
| name: str | ||
| """ | ||
| The name of the segment. | ||
| """ | ||
| created_at: str | ||
| """ | ||
| The date and time the segment was created. | ||
| """ |
| from typing import Any, Dict, List, Optional, cast | ||
| from typing_extensions import NotRequired, TypedDict | ||
| from resend import request | ||
| from resend.pagination_helper import PaginationHelper | ||
| from ._contact_segment import ContactSegment | ||
| class ContactSegments: | ||
| """ | ||
| ContactSegments manages the association between contacts and segments. | ||
| This is separate from the main Contacts API which uses audience_id. | ||
| """ | ||
| class AddContactSegmentResponse(TypedDict): | ||
| """ | ||
| AddContactSegmentResponse is the type that wraps the response when adding a contact to a segment. | ||
| Attributes: | ||
| id (str): The ID of the contact segment association | ||
| """ | ||
| id: str | ||
| """ | ||
| The ID of the contact segment association. | ||
| """ | ||
| class RemoveContactSegmentResponse(TypedDict): | ||
| """ | ||
| RemoveContactSegmentResponse is the type that wraps the response when removing a contact from a segment. | ||
| Attributes: | ||
| id (str): The ID of the contact segment association | ||
| deleted (bool): Whether the association was deleted | ||
| """ | ||
| id: str | ||
| """ | ||
| The ID of the contact segment association. | ||
| """ | ||
| deleted: bool | ||
| """ | ||
| Whether the association was deleted. | ||
| """ | ||
| class ListContactSegmentsParams(TypedDict): | ||
| """ | ||
| ListContactSegmentsParams are the parameters for listing contact segments. | ||
| Attributes: | ||
| limit (NotRequired[int]): Number of segments to retrieve. Maximum is 100, minimum is 1. | ||
| after (NotRequired[str]): The ID after which we'll retrieve more segments (for pagination). | ||
| before (NotRequired[str]): The ID before which we'll retrieve more segments (for pagination). | ||
| """ | ||
| limit: NotRequired[int] | ||
| """ | ||
| Number of segments to retrieve. Maximum is 100, and minimum is 1. | ||
| """ | ||
| after: NotRequired[str] | ||
| """ | ||
| The ID after which we'll retrieve more segments (for pagination). | ||
| This ID will not be included in the returned list. | ||
| Cannot be used with the before parameter. | ||
| """ | ||
| before: NotRequired[str] | ||
| """ | ||
| The ID before which we'll retrieve more segments (for pagination). | ||
| This ID will not be included in the returned list. | ||
| Cannot be used with the after parameter. | ||
| """ | ||
| class ListContactSegmentsResponse(TypedDict): | ||
| """ | ||
| ListContactSegmentsResponse type that wraps a list of segment objects with pagination metadata. | ||
| Attributes: | ||
| object (str): The object type, always "list" | ||
| data (List[ContactSegment]): A list of segment objects | ||
| has_more (bool): Whether there are more results available | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type, always "list" | ||
| """ | ||
| data: List[ContactSegment] | ||
| """ | ||
| A list of segment objects. | ||
| """ | ||
| has_more: bool | ||
| """ | ||
| Whether there are more results available for pagination. | ||
| """ | ||
| class AddParams(TypedDict): | ||
| """ | ||
| AddParams for adding a contact to a segment. | ||
| Attributes: | ||
| segment_id (str): The segment ID | ||
| contact_id (NotRequired[str]): The contact ID | ||
| email (NotRequired[str]): The contact email (use either contact_id or email) | ||
| """ | ||
| segment_id: str | ||
| """ | ||
| The segment ID. | ||
| """ | ||
| contact_id: NotRequired[str] | ||
| """ | ||
| The contact ID. Either contact_id or email must be provided. | ||
| """ | ||
| email: NotRequired[str] | ||
| """ | ||
| The contact email. Either contact_id or email must be provided. | ||
| """ | ||
| class RemoveParams(TypedDict): | ||
| """ | ||
| RemoveParams for removing a contact from a segment. | ||
| Attributes: | ||
| segment_id (str): The segment ID | ||
| contact_id (NotRequired[str]): The contact ID | ||
| email (NotRequired[str]): The contact email (use either contact_id or email) | ||
| """ | ||
| segment_id: str | ||
| """ | ||
| The segment ID. | ||
| """ | ||
| contact_id: NotRequired[str] | ||
| """ | ||
| The contact ID. Either contact_id or email must be provided. | ||
| """ | ||
| email: NotRequired[str] | ||
| """ | ||
| The contact email. Either contact_id or email must be provided. | ||
| """ | ||
| class ListParams(TypedDict): | ||
| """ | ||
| ListParams for listing segments for a contact. | ||
| Attributes: | ||
| contact_id (NotRequired[str]): The contact ID | ||
| email (NotRequired[str]): The contact email (use either contact_id or email) | ||
| """ | ||
| contact_id: NotRequired[str] | ||
| """ | ||
| The contact ID. Either contact_id or email must be provided. | ||
| """ | ||
| email: NotRequired[str] | ||
| """ | ||
| The contact email. Either contact_id or email must be provided. | ||
| """ | ||
| @classmethod | ||
| def add(cls, params: AddParams) -> AddContactSegmentResponse: | ||
| """ | ||
| Add a contact to a segment. | ||
| Args: | ||
| params (AddParams): Parameters including segment_id and either contact_id or email | ||
| Returns: | ||
| AddContactSegmentResponse: The response containing the association ID | ||
| Raises: | ||
| ValueError: If neither contact_id nor email is provided | ||
| """ | ||
| contact_identifier = params.get("email") or params.get("contact_id") | ||
| if not contact_identifier: | ||
| raise ValueError("Either contact_id or email must be provided") | ||
| segment_id = params["segment_id"] | ||
| path = f"/contacts/{contact_identifier}/segments/{segment_id}" | ||
| resp = request.Request[ContactSegments.AddContactSegmentResponse]( | ||
| path=path, params=cast(Dict[Any, Any], params), verb="post" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def remove(cls, params: RemoveParams) -> RemoveContactSegmentResponse: | ||
| """ | ||
| Remove a contact from a segment. | ||
| Args: | ||
| params (RemoveParams): Parameters including segment_id and either contact_id or email | ||
| Returns: | ||
| RemoveContactSegmentResponse: The response containing the deleted status | ||
| Raises: | ||
| ValueError: If neither contact_id nor email is provided | ||
| """ | ||
| contact_identifier = params.get("email") or params.get("contact_id") | ||
| if not contact_identifier: | ||
| raise ValueError("Either contact_id or email must be provided") | ||
| segment_id = params["segment_id"] | ||
| path = f"/contacts/{contact_identifier}/segments/{segment_id}" | ||
| resp = request.Request[ContactSegments.RemoveContactSegmentResponse]( | ||
| path=path, params={}, verb="delete" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def list( | ||
| cls, params: ListParams, pagination: Optional[ListContactSegmentsParams] = None | ||
| ) -> ListContactSegmentsResponse: | ||
| """ | ||
| List all segments for a contact. | ||
| Args: | ||
| params (ListParams): Parameters containing either contact_id or email | ||
| pagination (Optional[ListContactSegmentsParams]): Optional pagination parameters | ||
| Returns: | ||
| ListContactSegmentsResponse: A list of segment objects | ||
| Raises: | ||
| ValueError: If neither contact_id nor email is provided | ||
| """ | ||
| contact_identifier = params.get("email") or params.get("contact_id") | ||
| if not contact_identifier: | ||
| raise ValueError("Either contact_id or email must be provided") | ||
| base_path = f"/contacts/{contact_identifier}/segments" | ||
| query_params = cast(Dict[Any, Any], pagination) if pagination else None | ||
| path = PaginationHelper.build_paginated_path(base_path, query_params) | ||
| resp = request.Request[ContactSegments.ListContactSegmentsResponse]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp |
| from typing import Any, Dict, List, Optional, cast | ||
| from typing_extensions import NotRequired, TypedDict | ||
| from resend import request | ||
| from resend.emails._received_email import (EmailAttachment, | ||
| EmailAttachmentDetails) | ||
| from resend.pagination_helper import PaginationHelper | ||
| class _ListParams(TypedDict): | ||
| limit: NotRequired[int] | ||
| """ | ||
| The maximum number of attachments to return. Maximum 100, minimum 1. | ||
| """ | ||
| after: NotRequired[str] | ||
| """ | ||
| Return attachments after this cursor for pagination. | ||
| """ | ||
| before: NotRequired[str] | ||
| """ | ||
| Return attachments before this cursor for pagination. | ||
| """ | ||
| class _ListResponse(TypedDict): | ||
| object: str | ||
| """ | ||
| The object type: "list" | ||
| """ | ||
| data: List[EmailAttachment] | ||
| """ | ||
| The list of attachment objects. | ||
| """ | ||
| has_more: bool | ||
| """ | ||
| Whether there are more attachments available for pagination. | ||
| """ | ||
| class Attachments: | ||
| """ | ||
| Attachments class that provides methods for retrieving attachments from sent emails. | ||
| """ | ||
| class ListParams(_ListParams): | ||
| """ | ||
| ListParams is the class that wraps the parameters for the list method. | ||
| Attributes: | ||
| limit (NotRequired[int]): The maximum number of attachments to return. Maximum 100, minimum 1. | ||
| after (NotRequired[str]): Return attachments after this cursor for pagination. | ||
| before (NotRequired[str]): Return attachments before this cursor for pagination. | ||
| """ | ||
| class ListResponse(_ListResponse): | ||
| """ | ||
| ListResponse is the type that wraps the response for listing attachments. | ||
| Attributes: | ||
| object (str): The object type: "list" | ||
| data (List[EmailAttachment]): The list of attachment objects. | ||
| has_more (bool): Whether there are more attachments available for pagination. | ||
| """ | ||
| @classmethod | ||
| def get(cls, email_id: str, attachment_id: str) -> EmailAttachmentDetails: | ||
| """ | ||
| Retrieve a single attachment from a sent email. | ||
| see more: https://resend.com/docs/api-reference/attachments/retrieve-sent-email-attachment | ||
| Args: | ||
| email_id (str): The ID of the sent email | ||
| attachment_id (str): The ID of the attachment to retrieve | ||
| Returns: | ||
| EmailAttachmentDetails: The attachment details including download URL | ||
| """ | ||
| path = f"/emails/{email_id}/attachments/{attachment_id}" | ||
| resp = request.Request[EmailAttachmentDetails]( | ||
| path=path, | ||
| params={}, | ||
| verb="get", | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def list(cls, email_id: str, params: Optional[ListParams] = None) -> ListResponse: | ||
| """ | ||
| Retrieve a list of attachments from a sent email. | ||
| see more: https://resend.com/docs/api-reference/attachments/list-sent-email-attachments | ||
| Args: | ||
| email_id (str): The ID of the sent email | ||
| params (Optional[ListParams]): The list parameters for pagination | ||
| Returns: | ||
| ListResponse: A paginated list of attachment objects | ||
| """ | ||
| base_path = f"/emails/{email_id}/attachments" | ||
| query_params = cast(Dict[Any, Any], params) if params else None | ||
| path = PaginationHelper.build_paginated_path(base_path, query_params) | ||
| resp = request.Request[Attachments.ListResponse]( | ||
| path=path, | ||
| params={}, | ||
| verb="get", | ||
| ).perform_with_content() | ||
| return resp |
| from typing import Dict, List, Optional | ||
| from typing_extensions import NotRequired, TypedDict | ||
| class EmailAttachment(TypedDict): | ||
| """ | ||
| EmailAttachment type that wraps an attachment object from an email. | ||
| Attributes: | ||
| id (str): The attachment ID. | ||
| filename (str): The filename of the attachment. | ||
| content_type (str): The content type of the attachment. | ||
| content_disposition (str): The content disposition of the attachment. | ||
| content_id (NotRequired[str]): The content ID for inline attachments. | ||
| size (NotRequired[int]): The size of the attachment in bytes. | ||
| """ | ||
| id: str | ||
| """ | ||
| The attachment ID. | ||
| """ | ||
| filename: str | ||
| """ | ||
| The filename of the attachment. | ||
| """ | ||
| content_type: str | ||
| """ | ||
| The content type of the attachment. | ||
| """ | ||
| content_disposition: str | ||
| """ | ||
| The content disposition of the attachment. | ||
| """ | ||
| content_id: NotRequired[str] | ||
| """ | ||
| The content ID for inline attachments. | ||
| """ | ||
| size: NotRequired[int] | ||
| """ | ||
| The size of the attachment in bytes. | ||
| """ | ||
| class EmailAttachmentDetails(TypedDict): | ||
| """ | ||
| EmailAttachmentDetails type that wraps an email attachment with download details. | ||
| Attributes: | ||
| object (str): The object type. | ||
| id (str): The attachment ID. | ||
| filename (str): The filename of the attachment. | ||
| content_type (str): The content type of the attachment. | ||
| content_disposition (str): The content disposition of the attachment. | ||
| content_id (NotRequired[str]): The content ID for inline attachments. | ||
| download_url (str): The URL to download the attachment. | ||
| expires_at (str): When the download URL expires. | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type. | ||
| """ | ||
| id: str | ||
| """ | ||
| The attachment ID. | ||
| """ | ||
| filename: str | ||
| """ | ||
| The filename of the attachment. | ||
| """ | ||
| content_type: str | ||
| """ | ||
| The content type of the attachment. | ||
| """ | ||
| content_disposition: str | ||
| """ | ||
| The content disposition of the attachment. | ||
| """ | ||
| content_id: NotRequired[str] | ||
| """ | ||
| The content ID for inline attachments. | ||
| """ | ||
| download_url: str | ||
| """ | ||
| The URL to download the attachment. | ||
| """ | ||
| expires_at: str | ||
| """ | ||
| When the download URL expires. | ||
| """ | ||
| # Uses functional typed dict syntax here in order to support "from" reserved keyword | ||
| _ReceivedEmailFromParam = TypedDict( | ||
| "_ReceivedEmailFromParam", | ||
| { | ||
| "from": str, | ||
| }, | ||
| ) | ||
| # For list responses (omits html, text, headers, object from full email) | ||
| _ListReceivedEmailFromParam = TypedDict( | ||
| "_ListReceivedEmailFromParam", | ||
| { | ||
| "from": str, | ||
| }, | ||
| ) | ||
| class _ReceivedEmailDefaultAttrs(_ReceivedEmailFromParam): | ||
| object: str | ||
| """ | ||
| The object type. | ||
| """ | ||
| id: str | ||
| """ | ||
| The received email ID. | ||
| """ | ||
| to: List[str] | ||
| """ | ||
| List of recipient email addresses. | ||
| """ | ||
| created_at: str | ||
| """ | ||
| When the email was received. | ||
| """ | ||
| subject: str | ||
| """ | ||
| The subject of the email. | ||
| """ | ||
| html: Optional[str] | ||
| """ | ||
| The HTML content of the email. | ||
| """ | ||
| text: Optional[str] | ||
| """ | ||
| The text content of the email. | ||
| """ | ||
| bcc: Optional[List[str]] | ||
| """ | ||
| Bcc recipients. | ||
| """ | ||
| cc: Optional[List[str]] | ||
| """ | ||
| Cc recipients. | ||
| """ | ||
| reply_to: Optional[List[str]] | ||
| """ | ||
| Reply-to addresses. | ||
| """ | ||
| message_id: str | ||
| """ | ||
| The message ID of the email. | ||
| """ | ||
| headers: NotRequired[Dict[str, str]] | ||
| """ | ||
| Email headers. | ||
| """ | ||
| attachments: List[EmailAttachment] | ||
| """ | ||
| List of attachments. | ||
| """ | ||
| class ReceivedEmail(_ReceivedEmailDefaultAttrs): | ||
| """ | ||
| ReceivedEmail type that wraps a received (inbound) email object. | ||
| Attributes: | ||
| object (str): The object type. | ||
| id (str): The received email ID. | ||
| to (List[str]): List of recipient email addresses. | ||
| from (str): The sender email address. | ||
| created_at (str): When the email was received. | ||
| subject (str): The subject of the email. | ||
| html (Optional[str]): The HTML content of the email. | ||
| text (Optional[str]): The text content of the email. | ||
| bcc (Optional[List[str]]): Bcc recipients. | ||
| cc (Optional[List[str]]): Cc recipients. | ||
| reply_to (Optional[List[str]]): Reply-to addresses. | ||
| message_id (str): The message ID of the email. | ||
| headers (NotRequired[Dict[str, str]]): Email headers. | ||
| attachments (List[EmailAttachment]): List of attachments. | ||
| """ | ||
| class _ListReceivedEmailDefaultAttrs(_ListReceivedEmailFromParam): | ||
| id: str | ||
| """ | ||
| The received email ID. | ||
| """ | ||
| to: List[str] | ||
| """ | ||
| List of recipient email addresses. | ||
| """ | ||
| created_at: str | ||
| """ | ||
| When the email was received. | ||
| """ | ||
| subject: str | ||
| """ | ||
| The subject of the email. | ||
| """ | ||
| bcc: Optional[List[str]] | ||
| """ | ||
| Bcc recipients. | ||
| """ | ||
| cc: Optional[List[str]] | ||
| """ | ||
| Cc recipients. | ||
| """ | ||
| reply_to: Optional[List[str]] | ||
| """ | ||
| Reply-to addresses. | ||
| """ | ||
| message_id: str | ||
| """ | ||
| The message ID of the email. | ||
| """ | ||
| attachments: List[EmailAttachment] | ||
| """ | ||
| List of attachments. | ||
| """ | ||
| class ListReceivedEmail(_ListReceivedEmailDefaultAttrs): | ||
| """ | ||
| ListReceivedEmail type for received email items in list responses. | ||
| Omits html, text, headers, and object fields from the full email. | ||
| Attributes: | ||
| id (str): The received email ID. | ||
| to (List[str]): List of recipient email addresses. | ||
| from (str): The sender email address. | ||
| created_at (str): When the email was received. | ||
| subject (str): The subject of the email. | ||
| bcc (Optional[List[str]]): Bcc recipients. | ||
| cc (Optional[List[str]]): Cc recipients. | ||
| reply_to (Optional[List[str]]): Reply-to addresses. | ||
| message_id (str): The message ID of the email. | ||
| attachments (List[EmailAttachment]): List of attachments. | ||
| """ |
| from typing import Any, Dict, List, Optional, cast | ||
| from typing_extensions import NotRequired, TypedDict | ||
| from resend import request | ||
| from resend.emails._received_email import (EmailAttachment, | ||
| EmailAttachmentDetails, | ||
| ListReceivedEmail, ReceivedEmail) | ||
| from resend.pagination_helper import PaginationHelper | ||
| class _ListParams(TypedDict): | ||
| limit: NotRequired[int] | ||
| """ | ||
| The maximum number of emails to return. Maximum 100, minimum 1. | ||
| """ | ||
| after: NotRequired[str] | ||
| """ | ||
| Return emails after this cursor for pagination. | ||
| """ | ||
| before: NotRequired[str] | ||
| """ | ||
| Return emails before this cursor for pagination. | ||
| """ | ||
| class _ListResponse(TypedDict): | ||
| object: str | ||
| """ | ||
| The object type: "list" | ||
| """ | ||
| data: List[ListReceivedEmail] | ||
| """ | ||
| The list of received email objects. | ||
| """ | ||
| has_more: bool | ||
| """ | ||
| Whether there are more emails available for pagination. | ||
| """ | ||
| class _AttachmentListParams(TypedDict): | ||
| limit: NotRequired[int] | ||
| """ | ||
| The maximum number of attachments to return. Maximum 100, minimum 1. | ||
| """ | ||
| after: NotRequired[str] | ||
| """ | ||
| Return attachments after this cursor for pagination. | ||
| """ | ||
| before: NotRequired[str] | ||
| """ | ||
| Return attachments before this cursor for pagination. | ||
| """ | ||
| class _AttachmentListResponse(TypedDict): | ||
| object: str | ||
| """ | ||
| The object type: "list" | ||
| """ | ||
| data: List[EmailAttachment] | ||
| """ | ||
| The list of attachment objects. | ||
| """ | ||
| has_more: bool | ||
| """ | ||
| Whether there are more attachments available for pagination. | ||
| """ | ||
| class Receiving: | ||
| """ | ||
| Receiving class that provides methods for retrieving received (inbound) emails. | ||
| """ | ||
| class Attachments: | ||
| """ | ||
| Attachments class that provides methods for retrieving attachments from received emails. | ||
| """ | ||
| class ListParams(_AttachmentListParams): | ||
| """ | ||
| ListParams is the class that wraps the parameters for the list method. | ||
| Attributes: | ||
| limit (NotRequired[int]): The maximum number of attachments to return. Maximum 100, minimum 1. | ||
| after (NotRequired[str]): Return attachments after this cursor for pagination. | ||
| before (NotRequired[str]): Return attachments before this cursor for pagination. | ||
| """ | ||
| class ListResponse(_AttachmentListResponse): | ||
| """ | ||
| ListResponse is the type that wraps the response for listing attachments. | ||
| Attributes: | ||
| object (str): The object type: "list" | ||
| data (List[EmailAttachment]): The list of attachment objects. | ||
| has_more (bool): Whether there are more attachments available for pagination. | ||
| """ | ||
| @classmethod | ||
| def get(cls, email_id: str, attachment_id: str) -> EmailAttachmentDetails: | ||
| """ | ||
| Retrieve a single attachment from a received email. | ||
| see more: https://resend.com/docs/api-reference/attachments/retrieve-received-email-attachment | ||
| Args: | ||
| email_id (str): The ID of the received email | ||
| attachment_id (str): The ID of the attachment to retrieve | ||
| Returns: | ||
| EmailAttachmentDetails: The attachment details including download URL | ||
| """ | ||
| path = f"/emails/receiving/{email_id}/attachments/{attachment_id}" | ||
| resp = request.Request[EmailAttachmentDetails]( | ||
| path=path, | ||
| params={}, | ||
| verb="get", | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def list( | ||
| cls, | ||
| email_id: str, | ||
| params: Optional["Receiving.Attachments.ListParams"] = None, | ||
| ) -> "Receiving.Attachments.ListResponse": | ||
| """ | ||
| Retrieve a list of attachments from a received email. | ||
| see more: https://resend.com/docs/api-reference/attachments/list-received-email-attachments | ||
| Args: | ||
| email_id (str): The ID of the received email | ||
| params (Optional[ListParams]): The list parameters for pagination | ||
| Returns: | ||
| ListResponse: A paginated list of attachment objects | ||
| """ | ||
| base_path = f"/emails/receiving/{email_id}/attachments" | ||
| query_params = cast(Dict[Any, Any], params) if params else None | ||
| path = PaginationHelper.build_paginated_path(base_path, query_params) | ||
| resp = request.Request[_AttachmentListResponse]( | ||
| path=path, | ||
| params={}, | ||
| verb="get", | ||
| ).perform_with_content() | ||
| return resp | ||
| class ListParams(_ListParams): | ||
| """ | ||
| ListParams is the class that wraps the parameters for the list method. | ||
| Attributes: | ||
| limit (NotRequired[int]): The maximum number of emails to return. Maximum 100, minimum 1. | ||
| after (NotRequired[str]): Return emails after this cursor for pagination. | ||
| before (NotRequired[str]): Return emails before this cursor for pagination. | ||
| """ | ||
| class ListResponse(_ListResponse): | ||
| """ | ||
| ListResponse is the type that wraps the response for listing received emails. | ||
| Attributes: | ||
| object (str): The object type: "list" | ||
| data (List[ListReceivedEmail]): The list of received email objects. | ||
| has_more (bool): Whether there are more emails available for pagination. | ||
| """ | ||
| @classmethod | ||
| def get(cls, email_id: str) -> ReceivedEmail: | ||
| """ | ||
| Retrieve a single received email. | ||
| see more: https://resend.com/docs/api-reference/emails/retrieve-received-email | ||
| Args: | ||
| email_id (str): The ID of the received email to retrieve | ||
| Returns: | ||
| ReceivedEmail: The received email object | ||
| """ | ||
| path = f"/emails/receiving/{email_id}" | ||
| resp = request.Request[ReceivedEmail]( | ||
| path=path, | ||
| params={}, | ||
| verb="get", | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def list(cls, params: Optional[ListParams] = None) -> ListResponse: | ||
| """ | ||
| Retrieve a list of received emails. | ||
| see more: https://resend.com/docs/api-reference/emails/list-received-emails | ||
| Args: | ||
| params (Optional[ListParams]): The list parameters for pagination | ||
| Returns: | ||
| ListResponse: A paginated list of received email objects | ||
| """ | ||
| base_path = "/emails/receiving" | ||
| query_params = cast(Dict[Any, Any], params) if params else None | ||
| path = PaginationHelper.build_paginated_path(base_path, query_params) | ||
| resp = request.Request[Receiving.ListResponse]( | ||
| path=path, | ||
| params={}, | ||
| verb="get", | ||
| ).perform_with_content() | ||
| return resp |
| from typing_extensions import TypedDict | ||
| class Segment(TypedDict): | ||
| id: str | ||
| """ | ||
| The unique identifier of the segment. | ||
| """ | ||
| name: str | ||
| """ | ||
| The name of the segment. | ||
| """ | ||
| created_at: str | ||
| """ | ||
| The date and time the segment was created. | ||
| """ |
| from typing import Any, Dict, List, Optional, cast | ||
| from typing_extensions import NotRequired, TypedDict | ||
| from resend import request | ||
| from resend.pagination_helper import PaginationHelper | ||
| from ._segment import Segment | ||
| class Segments: | ||
| class RemoveSegmentResponse(TypedDict): | ||
| """ | ||
| RemoveSegmentResponse is the type that wraps the response of the segment that was removed | ||
| Attributes: | ||
| object (str): The object type, "audience" | ||
| id (str): The ID of the removed segment | ||
| deleted (bool): Whether the segment was deleted | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type, "audience" | ||
| """ | ||
| id: str | ||
| """ | ||
| The ID of the removed segment | ||
| """ | ||
| deleted: bool | ||
| """ | ||
| Whether the segment was deleted | ||
| """ | ||
| class ListParams(TypedDict): | ||
| limit: NotRequired[int] | ||
| """ | ||
| Number of segments to retrieve. Maximum is 100, and minimum is 1. | ||
| """ | ||
| after: NotRequired[str] | ||
| """ | ||
| The ID after which we'll retrieve more segments (for pagination). | ||
| This ID will not be included in the returned list. | ||
| Cannot be used with the before parameter. | ||
| """ | ||
| before: NotRequired[str] | ||
| """ | ||
| The ID before which we'll retrieve more segments (for pagination). | ||
| This ID will not be included in the returned list. | ||
| Cannot be used with the after parameter. | ||
| """ | ||
| class ListResponse(TypedDict): | ||
| """ | ||
| ListResponse type that wraps a list of segment objects with pagination metadata | ||
| Attributes: | ||
| object (str): The object type, always "list" | ||
| data (List[Segment]): A list of segment objects | ||
| has_more (bool): Whether there are more results available | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type, always "list" | ||
| """ | ||
| data: List[Segment] | ||
| """ | ||
| A list of segment objects | ||
| """ | ||
| has_more: bool | ||
| """ | ||
| Whether there are more results available for pagination | ||
| """ | ||
| class CreateSegmentResponse(TypedDict): | ||
| """ | ||
| CreateSegmentResponse is the type that wraps the response of the segment that was created | ||
| Attributes: | ||
| object (str): The object type, "audience" | ||
| id (str): The ID of the created segment | ||
| name (str): The name of the created segment | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type, "audience" | ||
| """ | ||
| id: str | ||
| """ | ||
| The ID of the created segment | ||
| """ | ||
| name: str | ||
| """ | ||
| The name of the created segment | ||
| """ | ||
| class CreateParams(TypedDict): | ||
| name: str | ||
| """ | ||
| The name of the segment. | ||
| """ | ||
| @classmethod | ||
| def create(cls, params: CreateParams) -> CreateSegmentResponse: | ||
| """ | ||
| Create a segment. | ||
| see more: https://resend.com/docs/api-reference/segments/create-segment | ||
| Args: | ||
| params (CreateParams): The segment creation parameters | ||
| Returns: | ||
| CreateSegmentResponse: The created segment response | ||
| """ | ||
| path = "/segments" | ||
| resp = request.Request[Segments.CreateSegmentResponse]( | ||
| path=path, params=cast(Dict[Any, Any], params), verb="post" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def list(cls, params: Optional[ListParams] = None) -> ListResponse: | ||
| """ | ||
| Retrieve a list of segments. | ||
| see more: https://resend.com/docs/api-reference/segments/list-segments | ||
| Args: | ||
| params (Optional[ListParams]): Optional pagination parameters | ||
| - limit: Number of segments to retrieve (max 100, min 1). | ||
| If not provided, all segments will be returned without pagination. | ||
| - after: ID after which to retrieve more segments | ||
| - before: ID before which to retrieve more segments | ||
| Returns: | ||
| ListResponse: A list of segment objects | ||
| """ | ||
| base_path = "/segments" | ||
| query_params = cast(Dict[Any, Any], params) if params else None | ||
| path = PaginationHelper.build_paginated_path(base_path, query_params) | ||
| resp = request.Request[Segments.ListResponse]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def get(cls, id: str) -> Segment: | ||
| """ | ||
| Retrieve a single segment. | ||
| see more: https://resend.com/docs/api-reference/segments/get-segment | ||
| Args: | ||
| id (str): The segment ID | ||
| Returns: | ||
| Segment: The segment object | ||
| """ | ||
| path = f"/segments/{id}" | ||
| resp = request.Request[Segment]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def remove(cls, id: str) -> RemoveSegmentResponse: | ||
| """ | ||
| Delete a single segment. | ||
| see more: https://resend.com/docs/api-reference/segments/delete-segment | ||
| Args: | ||
| id (str): The segment ID | ||
| Returns: | ||
| RemoveSegmentResponse: The removed segment response | ||
| """ | ||
| path = f"/segments/{id}" | ||
| resp = request.Request[Segments.RemoveSegmentResponse]( | ||
| path=path, params={}, verb="delete" | ||
| ).perform_with_content() | ||
| return resp |
| """Templates module.""" |
| """Template and Variable type definitions.""" | ||
| from typing import Any, List, Literal, Union | ||
| from typing_extensions import NotRequired, TypedDict | ||
| class Variable(TypedDict): | ||
| """Template variable type. | ||
| Attributes: | ||
| key (str): The key of the variable. We recommend capitalizing the key (e.g. FIRST_NAME). | ||
| type (Literal["string", "number"]): The type of the variable. | ||
| fallback_value (Any): The fallback value of the variable. Must match the type of the variable. | ||
| If no fallback value is provided, you must provide a value for the variable when sending | ||
| an email using the template. | ||
| """ | ||
| key: str | ||
| """The key of the variable. We recommend capitalizing the key (e.g. FIRST_NAME).""" | ||
| type: Literal["string", "number"] | ||
| """The type of the variable.""" | ||
| fallback_value: NotRequired[Any] | ||
| """The fallback value of the variable. Must match the type of the variable.""" | ||
| # Use functional TypedDict syntax to support reserved keyword "from" | ||
| _FromParam = TypedDict( | ||
| "_FromParam", | ||
| { | ||
| "from": NotRequired[str], | ||
| }, | ||
| ) | ||
| class Template(_FromParam): | ||
| """Template type that wraps the template object. | ||
| Attributes: | ||
| id (str): The Template ID. | ||
| object (str): The object type (always "template"). | ||
| name (str): The name of the template. | ||
| alias (str): The alias of the template. | ||
| status (str): The status of the template ("draft" or "published"). | ||
| from (str): Sender email address. | ||
| subject (str): Email subject. | ||
| reply_to (Union[List[str], str]): Reply-to email address(es). | ||
| html (str): The HTML version of the template. | ||
| text (str): The plain text version of the template. | ||
| variables (List[Variable]): The array of variables used in the template. | ||
| created_at (str): The timestamp when the template was created. | ||
| updated_at (str): The timestamp when the template was last updated. | ||
| published_at (str): The timestamp when the template was published. | ||
| """ | ||
| id: str | ||
| """The Template ID.""" | ||
| object: str | ||
| """The object type (always "template").""" | ||
| name: str | ||
| """The name of the template.""" | ||
| alias: NotRequired[str] | ||
| """The alias of the template.""" | ||
| status: NotRequired[Literal["draft", "published"]] | ||
| """The status of the template.""" | ||
| subject: NotRequired[str] | ||
| """Email subject.""" | ||
| reply_to: NotRequired[Union[List[str], str]] | ||
| """Reply-to email address(es).""" | ||
| html: str | ||
| """The HTML version of the template.""" | ||
| text: NotRequired[str] | ||
| """The plain text version of the template.""" | ||
| variables: NotRequired[List[Variable]] | ||
| """The array of variables used in the template.""" | ||
| created_at: NotRequired[str] | ||
| """The timestamp when the template was created.""" | ||
| updated_at: NotRequired[str] | ||
| """The timestamp when the template was last updated.""" | ||
| published_at: NotRequired[str] | ||
| """The timestamp when the template was published.""" | ||
| class TemplateListItem(TypedDict): | ||
| """Template list item type returned in list responses. | ||
| This is a subset of the full Template object, containing only the fields | ||
| that are included in list responses. | ||
| Attributes: | ||
| id (str): The Template ID. | ||
| name (str): The name of the template. | ||
| status (Literal["draft", "published"]): The status of the template. | ||
| published_at (str | None): The timestamp when the template was published, or None if not published. | ||
| created_at (str): The timestamp when the template was created. | ||
| updated_at (str): The timestamp when the template was last updated. | ||
| alias (str): The alias of the template. | ||
| """ | ||
| id: str | ||
| """The Template ID.""" | ||
| name: str | ||
| """The name of the template.""" | ||
| status: Literal["draft", "published"] | ||
| """The status of the template.""" | ||
| published_at: Union[str, None] | ||
| """The timestamp when the template was published, or None if not published.""" | ||
| created_at: str | ||
| """The timestamp when the template was created.""" | ||
| updated_at: str | ||
| """The timestamp when the template was last updated.""" | ||
| alias: str | ||
| """The alias of the template.""" |
| """Templates API operations.""" | ||
| from typing import Any, Dict, List, Optional, Union, cast | ||
| from typing_extensions import NotRequired, TypedDict | ||
| from resend import request | ||
| from resend.pagination_helper import PaginationHelper | ||
| from ._template import Template, TemplateListItem, Variable | ||
| # Use functional TypedDict syntax to support reserved keyword "from" | ||
| _CreateParamsFrom = TypedDict( | ||
| "_CreateParamsFrom", | ||
| { | ||
| "from": NotRequired[str], | ||
| }, | ||
| ) | ||
| class Templates: | ||
| """Templates API resource. | ||
| The Templates API allows you to create, manage, and publish email templates | ||
| with optional variables. | ||
| """ | ||
| class CreateParams(_CreateParamsFrom): | ||
| """Parameters for creating a template. | ||
| Attributes: | ||
| name (str): The name of the template (required). | ||
| alias (str): The alias of the template. | ||
| from (str): Sender email address. To include a friendly name, use the format | ||
| "Your Name <sender@domain.com>". If provided, this value can be overridden | ||
| when sending an email using the template. | ||
| subject (str): Email subject. If provided, this value can be overridden when | ||
| sending an email using the template. | ||
| reply_to (Union[List[str], str]): Reply-to email address(es). For multiple | ||
| addresses, send as an array of strings. If provided, this value can be | ||
| overridden when sending an email using the template. | ||
| html (str): The HTML version of the template (required). | ||
| text (str): The plain text version of the message. If not provided, the HTML | ||
| will be used to generate a plain text version. You can opt out of this | ||
| behavior by setting value to an empty string. | ||
| variables (List[Variable]): The array of variables used in the template. | ||
| Each template may contain up to 20 variables. | ||
| """ | ||
| name: str | ||
| """The name of the template.""" | ||
| html: str | ||
| """The HTML version of the template.""" | ||
| alias: NotRequired[str] | ||
| """The alias of the template.""" | ||
| subject: NotRequired[str] | ||
| """Email subject.""" | ||
| reply_to: NotRequired[Union[List[str], str]] | ||
| """Reply-to email address(es).""" | ||
| text: NotRequired[str] | ||
| """The plain text version of the message.""" | ||
| variables: NotRequired[List[Variable]] | ||
| """The array of variables used in the template.""" | ||
| class CreateResponse(TypedDict): | ||
| """Response from creating a template. | ||
| Attributes: | ||
| id (str): The Template ID. | ||
| object (str): The object type (always "template"). | ||
| """ | ||
| id: str | ||
| """The Template ID.""" | ||
| object: str | ||
| """The object type (always "template").""" | ||
| class UpdateParams(_CreateParamsFrom): | ||
| """Parameters for updating a template. | ||
| Attributes: | ||
| id (str): The Template ID (required). | ||
| name (str): The name of the template. | ||
| alias (str): The alias of the template. | ||
| from (str): Sender email address. | ||
| subject (str): Email subject. | ||
| reply_to (Union[List[str], str]): Reply-to email address(es). | ||
| html (str): The HTML version of the template. | ||
| text (str): The plain text version of the message. | ||
| variables (List[Variable]): The array of variables used in the template. | ||
| """ | ||
| id: str | ||
| """The Template ID.""" | ||
| name: NotRequired[str] | ||
| """The name of the template.""" | ||
| alias: NotRequired[str] | ||
| """The alias of the template.""" | ||
| subject: NotRequired[str] | ||
| """Email subject.""" | ||
| reply_to: NotRequired[Union[List[str], str]] | ||
| """Reply-to email address(es).""" | ||
| html: NotRequired[str] | ||
| """The HTML version of the template.""" | ||
| text: NotRequired[str] | ||
| """The plain text version of the message.""" | ||
| variables: NotRequired[List[Variable]] | ||
| """The array of variables used in the template.""" | ||
| class UpdateResponse(TypedDict): | ||
| """Response from updating a template. | ||
| Attributes: | ||
| id (str): The Template ID. | ||
| object (str): The object type (always "template"). | ||
| """ | ||
| id: str | ||
| """The Template ID.""" | ||
| object: str | ||
| """The object type (always "template").""" | ||
| class ListParams(TypedDict): | ||
| """Parameters for listing templates. | ||
| Attributes: | ||
| limit (int): The number of templates to return (max 100). | ||
| after (str): Return templates after this cursor. | ||
| before (str): Return templates before this cursor. | ||
| """ | ||
| limit: NotRequired[int] | ||
| """The number of templates to return (max 100).""" | ||
| after: NotRequired[str] | ||
| """Return templates after this cursor.""" | ||
| before: NotRequired[str] | ||
| """Return templates before this cursor.""" | ||
| class ListResponse(TypedDict): | ||
| """Response from listing templates. | ||
| Attributes: | ||
| object (str): The object type (always "list"). | ||
| data (List[TemplateListItem]): Array of template list items with a subset of template properties. | ||
| has_more (bool): Whether there are more results available. | ||
| """ | ||
| object: str | ||
| """The object type (always "list").""" | ||
| data: List[TemplateListItem] | ||
| """Array of template list items with a subset of template properties.""" | ||
| has_more: bool | ||
| """Whether there are more results available.""" | ||
| class PublishResponse(TypedDict): | ||
| """Response from publishing a template. | ||
| Attributes: | ||
| id (str): The Template ID. | ||
| object (str): The object type (always "template"). | ||
| """ | ||
| id: str | ||
| """The Template ID.""" | ||
| object: str | ||
| """The object type (always "template").""" | ||
| class DuplicateResponse(TypedDict): | ||
| """Response from duplicating a template. | ||
| Attributes: | ||
| id (str): The Template ID of the duplicated template. | ||
| object (str): The object type (always "template"). | ||
| """ | ||
| id: str | ||
| """The Template ID of the duplicated template.""" | ||
| object: str | ||
| """The object type (always "template").""" | ||
| class RemoveResponse(TypedDict): | ||
| """Response from removing a template. | ||
| Attributes: | ||
| id (str): The Template ID. | ||
| object (str): The object type (always "template"). | ||
| deleted (bool): Whether the template was deleted. | ||
| """ | ||
| id: str | ||
| """The Template ID.""" | ||
| object: str | ||
| """The object type (always "template").""" | ||
| deleted: bool | ||
| """Whether the template was deleted.""" | ||
| @classmethod | ||
| def create(cls, params: CreateParams) -> CreateResponse: | ||
| """Create a new template. | ||
| Before you can use a template, you must publish it first. To publish a template, | ||
| use the Templates dashboard or publish() method. | ||
| Args: | ||
| params: The template creation parameters. | ||
| Returns: | ||
| CreateResponse: The created template response with ID and object type. | ||
| """ | ||
| path = "/templates" | ||
| resp = request.Request[Templates.CreateResponse]( | ||
| path=path, params=cast(Dict[Any, Any], params), verb="post" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def get(cls, template_id: str) -> Template: | ||
| """Retrieve a template by ID. | ||
| Args: | ||
| template_id: The Template ID. | ||
| Returns: | ||
| Template: The template object. | ||
| """ | ||
| path = f"/templates/{template_id}" | ||
| resp = request.Request[Template]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def list(cls, params: Optional[ListParams] = None) -> ListResponse: | ||
| """List all templates with pagination support. | ||
| Args: | ||
| params: Optional pagination parameters (limit, after, before). | ||
| Returns: | ||
| ListResponse: The paginated list of templates. | ||
| """ | ||
| base_path = "/templates" | ||
| query_params = cast(Dict[Any, Any], params) if params else None | ||
| path = PaginationHelper.build_paginated_path(base_path, query_params) | ||
| resp = request.Request[Templates.ListResponse]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def update(cls, params: UpdateParams) -> UpdateResponse: | ||
| """Update an existing template. | ||
| Args: | ||
| params: The template update parameters (must include id). | ||
| Returns: | ||
| UpdateResponse: The updated template response with ID and object type. | ||
| """ | ||
| template_id = params["id"] | ||
| path = f"/templates/{template_id}" | ||
| # Remove 'id' from params before sending | ||
| update_params = {k: v for k, v in params.items() if k != "id"} | ||
| resp = request.Request[Templates.UpdateResponse]( | ||
| path=path, params=cast(Dict[Any, Any], update_params), verb="patch" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def publish(cls, template_id: str) -> PublishResponse: | ||
| """Publish a template to make it available for use. | ||
| Before you can use a template to send emails, you must publish it first. | ||
| Args: | ||
| template_id: The Template ID. | ||
| Returns: | ||
| PublishResponse: The published template response with ID and object type. | ||
| """ | ||
| path = f"/templates/{template_id}/publish" | ||
| resp = request.Request[Templates.PublishResponse]( | ||
| path=path, params={}, verb="post" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def duplicate(cls, template_id: str) -> DuplicateResponse: | ||
| """Duplicate a template. | ||
| Creates a copy of the specified template with all its properties and variables. | ||
| Args: | ||
| template_id: The Template ID to duplicate. | ||
| Returns: | ||
| DuplicateResponse: The duplicated template response with new ID and object type. | ||
| """ | ||
| path = f"/templates/{template_id}/duplicate" | ||
| resp = request.Request[Templates.DuplicateResponse]( | ||
| path=path, params={}, verb="post" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def remove(cls, template_id: str) -> RemoveResponse: | ||
| """Delete a template. | ||
| Args: | ||
| template_id: The Template ID. | ||
| Returns: | ||
| RemoveResponse: The deletion response with ID, object type, and deleted status. | ||
| """ | ||
| path = f"/templates/{template_id}" | ||
| resp = request.Request[Templates.RemoveResponse]( | ||
| path=path, params={}, verb="delete" | ||
| ).perform_with_content() | ||
| return resp |
| from typing_extensions import TypedDict | ||
| class Topic(TypedDict): | ||
| id: str | ||
| """ | ||
| The unique identifier of the topic. | ||
| """ | ||
| name: str | ||
| """ | ||
| The topic name. | ||
| """ | ||
| default_subscription: str | ||
| """ | ||
| The default subscription preference for new contacts. Possible values: opt_in or opt_out. | ||
| """ | ||
| description: str | ||
| """ | ||
| The topic description. | ||
| """ | ||
| created_at: str | ||
| """ | ||
| The date and time the topic was created. | ||
| """ |
| from typing import Any, Dict, List, Optional, cast | ||
| from typing_extensions import NotRequired, TypedDict | ||
| from resend import request | ||
| from resend.pagination_helper import PaginationHelper | ||
| from ._topic import Topic | ||
| class Topics: | ||
| class CreateTopicResponse(TypedDict): | ||
| """ | ||
| CreateTopicResponse is the type that wraps the response of the topic that was created | ||
| Attributes: | ||
| id (str): The ID of the created topic | ||
| """ | ||
| id: str | ||
| """ | ||
| The ID of the created topic | ||
| """ | ||
| class CreateParams(TypedDict): | ||
| name: str | ||
| """ | ||
| The topic name. Max length is 50 characters. | ||
| """ | ||
| default_subscription: str | ||
| """ | ||
| The default subscription preference for new contacts. Possible values: opt_in or opt_out. | ||
| This value cannot be changed later. | ||
| """ | ||
| description: NotRequired[str] | ||
| """ | ||
| The topic description. Max length is 200 characters. | ||
| """ | ||
| class UpdateTopicResponse(TypedDict): | ||
| """ | ||
| UpdateTopicResponse is the type that wraps the response of the topic that was updated | ||
| Attributes: | ||
| id (str): The ID of the updated topic | ||
| """ | ||
| id: str | ||
| """ | ||
| The ID of the updated topic | ||
| """ | ||
| class UpdateParams(TypedDict, total=False): | ||
| name: str | ||
| """ | ||
| The topic name. Max length is 50 characters. | ||
| """ | ||
| description: str | ||
| """ | ||
| The topic description. Max length is 200 characters. | ||
| """ | ||
| class RemoveTopicResponse(TypedDict): | ||
| """ | ||
| RemoveTopicResponse is the type that wraps the response of the topic that was removed | ||
| Attributes: | ||
| object (str): The object type, "topic" | ||
| id (str): The ID of the removed topic | ||
| deleted (bool): Whether the topic was deleted | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type, "topic" | ||
| """ | ||
| id: str | ||
| """ | ||
| The ID of the removed topic | ||
| """ | ||
| deleted: bool | ||
| """ | ||
| Whether the topic was deleted | ||
| """ | ||
| class ListParams(TypedDict): | ||
| limit: NotRequired[int] | ||
| """ | ||
| Number of topics to retrieve. Maximum is 100, and minimum is 1. | ||
| """ | ||
| after: NotRequired[str] | ||
| """ | ||
| The ID after which we'll retrieve more topics (for pagination). | ||
| This ID will not be included in the returned list. | ||
| Cannot be used with the before parameter. | ||
| """ | ||
| before: NotRequired[str] | ||
| """ | ||
| The ID before which we'll retrieve more topics (for pagination). | ||
| This ID will not be included in the returned list. | ||
| Cannot be used with the after parameter. | ||
| """ | ||
| class ListResponse(TypedDict): | ||
| """ | ||
| ListResponse type that wraps a list of topic objects with pagination metadata | ||
| Attributes: | ||
| object (str): The object type, always "list" | ||
| data (List[Topic]): A list of topic objects | ||
| has_more (bool): Whether there are more results available | ||
| """ | ||
| object: str | ||
| """ | ||
| The object type, always "list" | ||
| """ | ||
| data: List[Topic] | ||
| """ | ||
| A list of topic objects | ||
| """ | ||
| has_more: bool | ||
| """ | ||
| Whether there are more results available for pagination | ||
| """ | ||
| @classmethod | ||
| def create(cls, params: CreateParams) -> CreateTopicResponse: | ||
| """ | ||
| Create a topic. | ||
| see more: https://resend.com/docs/api-reference/topics/create-topic | ||
| Args: | ||
| params (CreateParams): The topic creation parameters | ||
| - name: The topic name (max 50 characters) | ||
| - default_subscription: The default subscription preference ("opt_in" or "opt_out") | ||
| - description: Optional topic description (max 200 characters) | ||
| Returns: | ||
| CreateTopicResponse: The created topic response with the topic ID | ||
| """ | ||
| path = "/topics" | ||
| resp = request.Request[Topics.CreateTopicResponse]( | ||
| path=path, params=cast(Dict[Any, Any], params), verb="post" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def get(cls, id: str) -> Topic: | ||
| """ | ||
| Retrieve a single topic by its ID. | ||
| see more: https://resend.com/docs/api-reference/topics/get-topic | ||
| Args: | ||
| id (str): The topic ID | ||
| Returns: | ||
| Topic: The topic object | ||
| """ | ||
| path = f"/topics/{id}" | ||
| resp = request.Request[Topic]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def update(cls, id: str, params: UpdateParams) -> UpdateTopicResponse: | ||
| """ | ||
| Update an existing topic. | ||
| see more: https://resend.com/docs/api-reference/topics/update-topic | ||
| Args: | ||
| id (str): The topic ID | ||
| params (UpdateParams): The topic update parameters | ||
| - name: Optional topic name (max 50 characters) | ||
| - description: Optional topic description (max 200 characters) | ||
| Returns: | ||
| UpdateTopicResponse: The updated topic response with the topic ID | ||
| """ | ||
| path = f"/topics/{id}" | ||
| resp = request.Request[Topics.UpdateTopicResponse]( | ||
| path=path, params=cast(Dict[Any, Any], params), verb="patch" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def remove(cls, id: str) -> RemoveTopicResponse: | ||
| """ | ||
| Delete a single topic. | ||
| see more: https://resend.com/docs/api-reference/topics/delete-topic | ||
| Args: | ||
| id (str): The topic ID | ||
| Returns: | ||
| RemoveTopicResponse: The removed topic response | ||
| """ | ||
| path = f"/topics/{id}" | ||
| resp = request.Request[Topics.RemoveTopicResponse]( | ||
| path=path, params={}, verb="delete" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
| def list(cls, params: Optional[ListParams] = None) -> ListResponse: | ||
| """ | ||
| Retrieve a list of topics. | ||
| see more: https://resend.com/docs/api-reference/topics/list-topics | ||
| Args: | ||
| params (Optional[ListParams]): Optional pagination parameters | ||
| - limit: Number of topics to retrieve (max 100, min 1). | ||
| If not provided, all topics will be returned without pagination. | ||
| - after: ID after which to retrieve more topics | ||
| - before: ID before which to retrieve more topics | ||
| Returns: | ||
| ListResponse: A list of topic objects | ||
| """ | ||
| base_path = "/topics" | ||
| query_params = cast(Dict[Any, Any], params) if params else None | ||
| path = PaginationHelper.build_paginated_path(base_path, query_params) | ||
| resp = request.Request[Topics.ListResponse]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: resend | ||
| Version: 2.18.0 | ||
| Version: 2.19.0 | ||
| Summary: Resend Python SDK | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/resendlabs/resend-python |
| Metadata-Version: 2.1 | ||
| Name: resend | ||
| Version: 2.18.0 | ||
| Version: 2.19.0 | ||
| Summary: Resend Python SDK | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/resendlabs/resend-python |
@@ -28,5 +28,13 @@ LICENSE.md | ||
| resend/broadcasts/_broadcasts.py | ||
| resend/contact_properties/__init__.py | ||
| resend/contact_properties/_contact_properties.py | ||
| resend/contact_properties/_contact_property.py | ||
| resend/contacts/__init__.py | ||
| resend/contacts/_contact.py | ||
| resend/contacts/_contact_topic.py | ||
| resend/contacts/_contacts.py | ||
| resend/contacts/_topics.py | ||
| resend/contacts/segments/__init__.py | ||
| resend/contacts/segments/_contact_segment.py | ||
| resend/contacts/segments/_contact_segments.py | ||
| resend/domains/__init__.py | ||
@@ -38,8 +46,20 @@ resend/domains/_domain.py | ||
| resend/emails/_attachment.py | ||
| resend/emails/_attachments.py | ||
| resend/emails/_batch.py | ||
| resend/emails/_email.py | ||
| resend/emails/_emails.py | ||
| resend/emails/_received_email.py | ||
| resend/emails/_receiving.py | ||
| resend/emails/_tag.py | ||
| resend/segments/__init__.py | ||
| resend/segments/_segment.py | ||
| resend/segments/_segments.py | ||
| resend/templates/__init__.py | ||
| resend/templates/_template.py | ||
| resend/templates/_templates.py | ||
| resend/topics/__init__.py | ||
| resend/topics/_topic.py | ||
| resend/topics/_topics.py | ||
| resend/webhooks/__init__.py | ||
| resend/webhooks/_webhook.py | ||
| resend/webhooks/_webhooks.py |
+40
-4
@@ -9,10 +9,20 @@ import os | ||
| from .broadcasts._broadcasts import Broadcasts | ||
| from .contact_properties._contact_properties import ContactProperties | ||
| from .contact_properties._contact_property import ContactProperty | ||
| from .contacts._contact import Contact | ||
| from .contacts._contact_topic import ContactTopic, TopicSubscriptionUpdate | ||
| from .contacts._contacts import Contacts | ||
| from .contacts._topics import Topics as ContactsTopics | ||
| from .contacts.segments._contact_segment import ContactSegment | ||
| from .contacts.segments._contact_segments import ContactSegments | ||
| from .domains._domain import Domain | ||
| from .domains._domains import Domains | ||
| from .emails._attachment import Attachment, RemoteAttachment | ||
| from .emails._attachments import Attachments as EmailAttachments | ||
| from .emails._batch import Batch, BatchValidationError | ||
| from .emails._email import Email | ||
| from .emails._emails import Emails | ||
| from .emails._emails import Emails, EmailTemplate | ||
| from .emails._received_email import (EmailAttachment, EmailAttachmentDetails, | ||
| ListReceivedEmail, ReceivedEmail) | ||
| from .emails._receiving import Receiving as EmailsReceiving | ||
| from .emails._tag import Tag | ||
@@ -22,2 +32,8 @@ from .http_client import HTTPClient | ||
| from .request import Request | ||
| from .segments._segment import Segment | ||
| from .segments._segments import Segments | ||
| from .templates._template import Template, TemplateListItem, Variable | ||
| from .templates._templates import Templates | ||
| from .topics._topic import Topic | ||
| from .topics._topics import Topics | ||
| from .version import __version__, get_version | ||
@@ -35,5 +51,2 @@ from .webhooks._webhook import (VerifyWebhookOptions, Webhook, WebhookEvent, | ||
| # API resources | ||
| from .emails._emails import Emails # noqa | ||
| __all__ = [ | ||
@@ -49,7 +62,16 @@ "__version__", | ||
| "Contacts", | ||
| "ContactProperties", | ||
| "Broadcasts", | ||
| "Segments", | ||
| "Templates", | ||
| "Webhooks", | ||
| "Topics", | ||
| # Types | ||
| "Audience", | ||
| "Contact", | ||
| "ContactSegment", | ||
| "ContactSegments", | ||
| "ContactProperty", | ||
| "ContactTopic", | ||
| "TopicSubscriptionUpdate", | ||
| "Domain", | ||
@@ -60,4 +82,9 @@ "ApiKey", | ||
| "RemoteAttachment", | ||
| "EmailTemplate", | ||
| "Tag", | ||
| "Broadcast", | ||
| "Segment", | ||
| "Template", | ||
| "TemplateListItem", | ||
| "Variable", | ||
| "Webhook", | ||
@@ -68,5 +95,14 @@ "WebhookEvent", | ||
| "VerifyWebhookOptions", | ||
| "Topic", | ||
| "BatchValidationError", | ||
| "ReceivedEmail", | ||
| "EmailAttachment", | ||
| "EmailAttachmentDetails", | ||
| "ListReceivedEmail", | ||
| # Receiving types (for type hints) | ||
| "EmailsReceiving", | ||
| "EmailAttachments", | ||
| "ContactsTopics", | ||
| # Default HTTP Client | ||
| "RequestsClient", | ||
| ] |
@@ -1,7 +0,7 @@ | ||
| from typing import Any, Dict, List, Optional, cast | ||
| import warnings | ||
| from typing import List, Optional | ||
| from typing_extensions import NotRequired, TypedDict | ||
| from resend import request | ||
| from resend.pagination_helper import PaginationHelper | ||
| from resend.segments._segments import Segments | ||
@@ -117,10 +117,13 @@ from ._audience import Audience | ||
| CreateAudienceResponse: The created audience response | ||
| .. deprecated:: | ||
| Use Segments.create() instead. Audiences is now an alias for Segments. | ||
| """ | ||
| warnings.warn( | ||
| "Audiences is deprecated. Use Segments instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return Segments.create(params) | ||
| path = "/audiences" | ||
| resp = request.Request[Audiences.CreateAudienceResponse]( | ||
| path=path, params=cast(Dict[Any, Any], params), verb="post" | ||
| ).perform_with_content() | ||
| return resp | ||
| @classmethod | ||
@@ -141,10 +144,12 @@ def list(cls, params: Optional[ListParams] = None) -> ListResponse: | ||
| ListResponse: A list of audience objects | ||
| .. deprecated:: | ||
| Use Segments.list() instead. Audiences is now an alias for Segments. | ||
| """ | ||
| base_path = "/audiences" | ||
| query_params = cast(Dict[Any, Any], params) if params else None | ||
| path = PaginationHelper.build_paginated_path(base_path, query_params) | ||
| resp = request.Request[Audiences.ListResponse]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp | ||
| warnings.warn( | ||
| "Audiences is deprecated. Use Segments instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return Segments.list(params) | ||
@@ -162,8 +167,12 @@ @classmethod | ||
| Audience: The audience object | ||
| .. deprecated:: | ||
| Use Segments.get() instead. Audiences is now an alias for Segments. | ||
| """ | ||
| path = f"/audiences/{id}" | ||
| resp = request.Request[Audience]( | ||
| path=path, params={}, verb="get" | ||
| ).perform_with_content() | ||
| return resp | ||
| warnings.warn( | ||
| "Audiences is deprecated. Use Segments instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return Segments.get(id) | ||
@@ -181,7 +190,11 @@ @classmethod | ||
| RemoveAudienceResponse: The removed audience response | ||
| .. deprecated:: | ||
| Use Segments.remove() instead. Audiences is now an alias for Segments. | ||
| """ | ||
| path = f"/audiences/{id}" | ||
| resp = request.Request[Audiences.RemoveAudienceResponse]( | ||
| path=path, params={}, verb="delete" | ||
| ).perform_with_content() | ||
| return resp | ||
| warnings.warn( | ||
| "Audiences is deprecated. Use Segments instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return Segments.remove(id) |
@@ -23,5 +23,12 @@ from typing import List, Union | ||
| """ | ||
| audience_id: str | ||
| segment_id: Union[str, None] | ||
| """ | ||
| The unique identifier of the segment. | ||
| """ | ||
| audience_id: Union[str, None] | ||
| """ | ||
| The unique identifier of the audience. | ||
| .. deprecated:: | ||
| Use segment_id instead. | ||
| """ | ||
@@ -28,0 +35,0 @@ name: str |
@@ -35,3 +35,4 @@ from typing import Any, Dict, List, Optional, Union, cast | ||
| from (str): The sender email address | ||
| audience_id (str): The ID of the audience you want to send to. | ||
| segment_id (NotRequired[str]): The ID of the segment you want to send to. | ||
| audience_id (NotRequired[str]): The ID of the audience you want to send to. (deprecated: use segment_id) | ||
| subject (str): Email subject. | ||
@@ -44,5 +45,12 @@ reply_to (NotRequired[Union[List[str], str]]): Reply-to email address(es). | ||
| audience_id: str | ||
| segment_id: NotRequired[str] | ||
| """ | ||
| The ID of the segment you want to send to. | ||
| """ | ||
| audience_id: NotRequired[str] | ||
| """ | ||
| The ID of the audience you want to send to. | ||
| .. deprecated:: | ||
| Use segment_id instead. | ||
| """ | ||
@@ -75,4 +83,5 @@ subject: str | ||
| broadcast_id (str): The ID of the broadcast you want to update. | ||
| audience_id (str): The ID of the audience you want to send to. | ||
| from (str): The sender email address | ||
| segment_id (NotRequired[str]): The ID of the segment you want to send to. | ||
| audience_id (NotRequired[str]): The ID of the audience you want to send to. (deprecated: use segment_id) | ||
| from (NotRequired[str]): The sender email address | ||
| subject (NotRequired[str]): Email subject. | ||
@@ -89,5 +98,12 @@ reply_to (NotRequired[Union[List[str], str]]): Reply-to email address(es). | ||
| """ | ||
| segment_id: NotRequired[str] | ||
| """ | ||
| The ID of the segment you want to send to. | ||
| """ | ||
| audience_id: NotRequired[str] | ||
| """ | ||
| The ID of the audience you want to send to. | ||
| .. deprecated:: | ||
| Use segment_id instead. | ||
| """ | ||
@@ -94,0 +110,0 @@ subject: NotRequired[str] |
@@ -0,1 +1,3 @@ | ||
| from typing import Any, Dict | ||
| from typing_extensions import NotRequired, TypedDict | ||
@@ -29,1 +31,5 @@ | ||
| """ | ||
| properties: NotRequired[Dict[str, Any]] | ||
| """ | ||
| Custom properties for the contact. Only available for global contacts. | ||
| """ |
@@ -9,5 +9,10 @@ from typing import Any, Dict, List, Optional, cast | ||
| from ._contact import Contact | ||
| from ._topics import Topics | ||
| from .segments._contact_segments import ContactSegments | ||
| class Contacts: | ||
| # Sub-API for managing contact-segment associations | ||
| Segments = ContactSegments | ||
| Topics = Topics | ||
@@ -115,6 +120,2 @@ class RemoveContactResponse(TypedDict): | ||
| class CreateParams(TypedDict): | ||
| audience_id: str | ||
| """ | ||
| The audience id. | ||
| """ | ||
| email: str | ||
@@ -124,2 +125,6 @@ """ | ||
| """ | ||
| audience_id: NotRequired[str] | ||
| """ | ||
| The audience id. If not provided, creates a global contact. | ||
| """ | ||
| first_name: NotRequired[str] | ||
@@ -137,16 +142,20 @@ """ | ||
| """ | ||
| properties: NotRequired[Dict[str, Any]] | ||
| """ | ||
| Custom properties for the contact. Only supported for global contacts (when audience_id is not provided). | ||
| """ | ||
| class UpdateParams(TypedDict): | ||
| audience_id: str | ||
| """ | ||
| The audience id. | ||
| """ | ||
| id: NotRequired[str] | ||
| """ | ||
| The contact id. | ||
| The contact id. Either id or email must be provided. | ||
| """ | ||
| email: NotRequired[str] | ||
| """ | ||
| The email of the contact. | ||
| The email of the contact. Either id or email must be provided. | ||
| """ | ||
| audience_id: NotRequired[str] | ||
| """ | ||
| The audience id. If not provided, updates a global contact. | ||
| """ | ||
| first_name: NotRequired[str] | ||
@@ -164,2 +173,6 @@ """ | ||
| """ | ||
| properties: NotRequired[Dict[str, Any]] | ||
| """ | ||
| Custom properties for the contact. Only supported for global contacts (when audience_id is not provided). | ||
| """ | ||
@@ -170,2 +183,3 @@ @classmethod | ||
| Create a new contact. | ||
| Can create either a global contact or an audience-specific contact. | ||
| see more: https://resend.com/docs/api-reference/contacts/create-contact | ||
@@ -175,2 +189,4 @@ | ||
| params (CreateParams): The contact creation parameters | ||
| - If audience_id is provided: creates audience-specific contact | ||
| - If audience_id is omitted: creates global contact with optional properties field | ||
@@ -180,4 +196,11 @@ Returns: | ||
| """ | ||
| audience_id = params.get("audience_id") | ||
| path = f"/audiences/{params['audience_id']}/contacts" | ||
| if audience_id: | ||
| # Audience-specific contact (no properties support) | ||
| path = f"/audiences/{audience_id}/contacts" | ||
| else: | ||
| # Global contact (supports properties) | ||
| path = "/contacts" | ||
| resp = request.Request[Contacts.CreateContactResponse]( | ||
@@ -192,2 +215,3 @@ path=path, params=cast(Dict[Any, Any], params), verb="post" | ||
| Update an existing contact. | ||
| Can update either a global contact or an audience-specific contact. | ||
| see more: https://resend.com/docs/api-reference/contacts/update-contact | ||
@@ -197,2 +221,4 @@ | ||
| params (UpdateParams): The contact update parameters | ||
| - If audience_id is provided: updates audience-specific contact | ||
| - If audience_id is omitted: updates global contact with optional properties field | ||
@@ -205,5 +231,15 @@ Returns: | ||
| val = params.get("id") if params.get("id") is not None else params.get("email") | ||
| # Email takes precedence over id (matching Node.js behavior) | ||
| contact_identifier = ( | ||
| params.get("email") if params.get("email") is not None else params.get("id") | ||
| ) | ||
| audience_id = params.get("audience_id") | ||
| path = f"/audiences/{params['audience_id']}/contacts/{val}" | ||
| if audience_id: | ||
| # Audience-specific contact (no properties support) | ||
| path = f"/audiences/{audience_id}/contacts/{contact_identifier}" | ||
| else: | ||
| # Global contact (supports properties) | ||
| path = f"/contacts/{contact_identifier}" | ||
| resp = request.Request[Contacts.UpdateContactResponse]( | ||
@@ -216,10 +252,11 @@ path=path, params=cast(Dict[Any, Any], params), verb="patch" | ||
| def list( | ||
| cls, audience_id: str, params: Optional[ListParams] = None | ||
| cls, audience_id: Optional[str] = None, params: Optional[ListParams] = None | ||
| ) -> ListResponse: | ||
| """ | ||
| List all contacts for the provided audience. | ||
| List all contacts. | ||
| Can list either global contacts or audience-specific contacts. | ||
| see more: https://resend.com/docs/api-reference/contacts/list-contacts | ||
| Args: | ||
| audience_id (str): The audience ID | ||
| audience_id (Optional[str]): The audience ID. If not provided, lists all global contacts. | ||
| params (Optional[ListParams]): Optional pagination parameters | ||
@@ -234,3 +271,9 @@ - limit: Number of contacts to retrieve (max 100, min 1). | ||
| """ | ||
| base_path = f"/audiences/{audience_id}/contacts" | ||
| if audience_id: | ||
| # Audience-specific contacts | ||
| base_path = f"/audiences/{audience_id}/contacts" | ||
| else: | ||
| # Global contacts | ||
| base_path = "/contacts" | ||
| query_params = cast(Dict[Any, Any], params) if params else None | ||
@@ -245,12 +288,16 @@ path = PaginationHelper.build_paginated_path(base_path, query_params) | ||
| def get( | ||
| cls, audience_id: str, id: Optional[str] = None, email: Optional[str] = None | ||
| cls, | ||
| audience_id: Optional[str] = None, | ||
| id: Optional[str] = None, | ||
| email: Optional[str] = None, | ||
| ) -> Contact: | ||
| """ | ||
| Get a contact. | ||
| Can retrieve either a global contact or an audience-specific contact. | ||
| see more: https://resend.com/docs/api-reference/contacts/get-contact | ||
| Args: | ||
| id (str): The contact ID | ||
| audience_id (str): The audience ID | ||
| email (Optional[str]): The contact email | ||
| audience_id (Optional[str]): The audience ID. If not provided, retrieves global contact. | ||
| id (Optional[str]): The contact ID. Either id or email must be provided. | ||
| email (Optional[str]): The contact email. Either id or email must be provided. | ||
@@ -260,7 +307,14 @@ Returns: | ||
| """ | ||
| contact = email if id is None else id | ||
| if contact is None: | ||
| # Email takes precedence over id (matching Node.js behavior) | ||
| contact_identifier = email if email is not None else id | ||
| if contact_identifier is None: | ||
| raise ValueError("id or email must be provided") | ||
| path = f"/audiences/{audience_id}/contacts/{contact}" | ||
| if audience_id: | ||
| # Audience-specific contact | ||
| path = f"/audiences/{audience_id}/contacts/{contact_identifier}" | ||
| else: | ||
| # Global contact | ||
| path = f"/contacts/{contact_identifier}" | ||
| resp = request.Request[Contact]( | ||
@@ -273,12 +327,16 @@ path=path, params={}, verb="get" | ||
| def remove( | ||
| cls, audience_id: str, id: Optional[str] = None, email: Optional[str] = None | ||
| cls, | ||
| audience_id: Optional[str] = None, | ||
| id: Optional[str] = None, | ||
| email: Optional[str] = None, | ||
| ) -> RemoveContactResponse: | ||
| """ | ||
| Remove a contact by ID or by Email | ||
| Remove a contact by ID or by Email. | ||
| Can remove either a global contact or an audience-specific contact. | ||
| see more: https://resend.com/docs/api-reference/contacts/delete-contact | ||
| Args: | ||
| audience_id (str): The audience ID | ||
| id (str): The contact ID | ||
| email (str): The contact email | ||
| audience_id (Optional[str]): The audience ID. If not provided, removes global contact. | ||
| id (Optional[str]): The contact ID. Either id or email must be provided. | ||
| email (Optional[str]): The contact email. Either id or email must be provided. | ||
@@ -288,7 +346,14 @@ Returns: | ||
| """ | ||
| contact = email if id is None else id | ||
| if contact is None: | ||
| # Email takes precedence over id (matching Node.js behavior) | ||
| contact_identifier = email if email is not None else id | ||
| if contact_identifier is None: | ||
| raise ValueError("id or email must be provided") | ||
| path = f"/audiences/{audience_id}/contacts/{contact}" | ||
| if audience_id: | ||
| # Audience-specific contact | ||
| path = f"/audiences/{audience_id}/contacts/{contact_identifier}" | ||
| else: | ||
| # Global contact | ||
| path = f"/contacts/{contact_identifier}" | ||
| resp = request.Request[Contacts.RemoveContactResponse]( | ||
@@ -295,0 +360,0 @@ path=path, params={}, verb="delete" |
@@ -7,3 +7,5 @@ from typing import Any, Dict, List, Optional, Union, cast | ||
| from resend.emails._attachment import Attachment, RemoteAttachment | ||
| from resend.emails._attachments import Attachments | ||
| from resend.emails._email import Email | ||
| from resend.emails._receiving import Receiving | ||
| from resend.emails._tag import Tag | ||
@@ -13,2 +15,21 @@ from resend.pagination_helper import PaginationHelper | ||
| class EmailTemplate(TypedDict): | ||
| """ | ||
| EmailTemplate is the class that wraps template configuration for email sending. | ||
| Attributes: | ||
| id (str): The template ID. | ||
| variables (NotRequired[Dict[str, Union[str, int]]]): Optional variables to be used in the template. | ||
| """ | ||
| id: str | ||
| """ | ||
| The template ID. | ||
| """ | ||
| variables: NotRequired[Dict[str, Union[str, int]]] | ||
| """ | ||
| Optional variables to be used in the template. | ||
| """ | ||
| class _UpdateParams(TypedDict): | ||
@@ -54,3 +75,3 @@ id: str | ||
| { | ||
| "from": str, | ||
| "from": NotRequired[str], | ||
| }, | ||
@@ -65,3 +86,3 @@ ) | ||
| """ | ||
| subject: str | ||
| subject: NotRequired[str] | ||
| """ | ||
@@ -107,5 +128,11 @@ The subject of the email. | ||
| """ | ||
| template: NotRequired[EmailTemplate] | ||
| """ | ||
| Template configuration for sending emails using predefined templates. | ||
| """ | ||
| class Emails: | ||
| Attachments = Attachments | ||
| Receiving = Receiving | ||
@@ -144,5 +171,5 @@ class CancelScheduledEmailResponse(_CancelScheduledEmailResponse): | ||
| Attributes: | ||
| from (str): The email address to send the email from. | ||
| from (NotRequired[str]): The email address to send the email from. | ||
| to (Union[str, List[str]]): List of email addresses to send the email to. | ||
| subject (str): The subject of the email. | ||
| subject (NotRequired[str]): The subject of the email. | ||
| bcc (NotRequired[Union[List[str], str]]): Bcc | ||
@@ -156,2 +183,3 @@ cc (NotRequired[Union[List[str], str]]): Cc | ||
| tags (NotRequired[List[Tag]]): List of tags to be added to the email. | ||
| template (NotRequired[EmailTemplate]): Template configuration for sending emails using predefined templates. | ||
| """ | ||
@@ -158,0 +186,0 @@ |
@@ -1,2 +0,2 @@ | ||
| __version__ = "2.18.0" | ||
| __version__ = "2.19.0" | ||
@@ -3,0 +3,0 @@ |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
174834
80.21%64
45.45%4583
80.29%