Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

resend

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resend - npm Package Compare versions

Comparing version
2.18.0a3
to
2.18.0
+1
-1
PKG-INFO
Metadata-Version: 2.1
Name: resend
Version: 2.18.0a3
Version: 2.18.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.0a3
Version: 2.18.0
Summary: Resend Python SDK

@@ -5,0 +5,0 @@ Home-page: https://github.com/resendlabs/resend-python

@@ -37,17 +37,8 @@ LICENSE.md

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/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

@@ -14,9 +14,5 @@ import os

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, EmailTemplate
from .emails._received_email import (EmailAttachment, EmailAttachmentDetails,
ListReceivedEmail, ReceivedEmail)
from .emails._receiving import Receiving as EmailsReceiving
from .emails._emails import Emails
from .emails._tag import Tag

@@ -26,6 +22,2 @@ from .http_client import HTTPClient

from .request import Request
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

@@ -43,2 +35,5 @@ from .webhooks._webhook import (VerifyWebhookOptions, Webhook, WebhookEvent,

# API resources
from .emails._emails import Emails # noqa
__all__ = [

@@ -55,5 +50,3 @@ "__version__",

"Broadcasts",
"Templates",
"Webhooks",
"Topics",
# Types

@@ -67,8 +60,4 @@ "Audience",

"RemoteAttachment",
"EmailTemplate",
"Tag",
"Broadcast",
"Template",
"TemplateListItem",
"Variable",
"Webhook",

@@ -79,13 +68,5 @@ "WebhookEvent",

"VerifyWebhookOptions",
"Topic",
"BatchValidationError",
"ReceivedEmail",
"EmailAttachment",
"EmailAttachmentDetails",
"ListReceivedEmail",
# Receiving types (for type hints)
"EmailsReceiving",
"EmailAttachments",
# Default HTTP Client
"RequestsClient",
]

@@ -7,5 +7,3 @@ 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

@@ -15,21 +13,2 @@ 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):

@@ -75,3 +54,3 @@ id: str

{
"from": NotRequired[str],
"from": str,
},

@@ -86,3 +65,3 @@ )

"""
subject: NotRequired[str]
subject: str
"""

@@ -128,11 +107,5 @@ The subject of the email.

"""
template: NotRequired[EmailTemplate]
"""
Template configuration for sending emails using predefined templates.
"""
class Emails:
Attachments = Attachments
Receiving = Receiving

@@ -171,5 +144,5 @@ class CancelScheduledEmailResponse(_CancelScheduledEmailResponse):

Attributes:
from (NotRequired[str]): The email address to send the email from.
from (str): The email address to send the email from.
to (Union[str, List[str]]): List of email addresses to send the email to.
subject (NotRequired[str]): The subject of the email.
subject (str): The subject of the email.
bcc (NotRequired[Union[List[str], str]]): Bcc

@@ -183,3 +156,2 @@ 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.
"""

@@ -186,0 +158,0 @@

@@ -1,2 +0,2 @@

__version__ = "2.18.0a3"
__version__ = "2.18.0"

@@ -3,0 +3,0 @@

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
"""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