|
5 | 5 | from resend import request |
6 | 6 | from resend.domains._domain import Domain |
7 | 7 |
|
| 8 | +# Async imports (optional - only available with pip install resend[async]) |
| 9 | +try: |
| 10 | + from resend.async_request import AsyncRequest |
| 11 | +except ImportError: |
| 12 | + pass |
| 13 | + |
8 | 14 | TlsOptions = Literal["enforced", "opportunistic"] |
9 | 15 |
|
10 | 16 |
|
@@ -171,3 +177,108 @@ def verify(cls, domain_id: str) -> Domain: |
171 | 177 | path=path, params={}, verb="post" |
172 | 178 | ).perform_with_content() |
173 | 179 | return resp |
| 180 | + |
| 181 | + @classmethod |
| 182 | + async def create_async(cls, params: CreateParams) -> Domain: |
| 183 | + """ |
| 184 | + Create a domain through the Resend Email API (async). |
| 185 | + see more: https://resend.com/docs/api-reference/domains/create-domain |
| 186 | +
|
| 187 | + Args: |
| 188 | + params (CreateParams): The domain creation parameters |
| 189 | +
|
| 190 | + Returns: |
| 191 | + Domain: The new domain object |
| 192 | + """ |
| 193 | + path = "/domains" |
| 194 | + resp = await AsyncRequest[Domain]( |
| 195 | + path=path, params=cast(Dict[Any, Any], params), verb="post" |
| 196 | + ).perform_with_content() |
| 197 | + return resp |
| 198 | + |
| 199 | + @classmethod |
| 200 | + async def update_async(cls, params: UpdateParams) -> Domain: |
| 201 | + """ |
| 202 | + Update an existing domain (async). |
| 203 | + see more: https://resend.com/docs/api-reference/domains/update-domain |
| 204 | +
|
| 205 | + Args: |
| 206 | + params (UpdateParams): The domain update parameters |
| 207 | +
|
| 208 | + Returns: |
| 209 | + Domain: The updated domain object |
| 210 | + """ |
| 211 | + path = f"/domains/{params['id']}" |
| 212 | + resp = await AsyncRequest[Domain]( |
| 213 | + path=path, params=cast(Dict[Any, Any], params), verb="patch" |
| 214 | + ).perform_with_content() |
| 215 | + return resp |
| 216 | + |
| 217 | + @classmethod |
| 218 | + async def get_async(cls, domain_id: str) -> Domain: |
| 219 | + """ |
| 220 | + Retrieve a single domain for the authenticated user (async). |
| 221 | + see more: https://resend.com/docs/api-reference/domains/get-domain |
| 222 | +
|
| 223 | + Args: |
| 224 | + domain_id (str): The domain ID |
| 225 | +
|
| 226 | + Returns: |
| 227 | + Domain: The domain object |
| 228 | + """ |
| 229 | + path = f"/domains/{domain_id}" |
| 230 | + resp = await AsyncRequest[Domain]( |
| 231 | + path=path, params={}, verb="get" |
| 232 | + ).perform_with_content() |
| 233 | + return resp |
| 234 | + |
| 235 | + @classmethod |
| 236 | + async def list_async(cls) -> ListResponse: |
| 237 | + """ |
| 238 | + Retrieve a list of domains for the authenticated user (async). |
| 239 | + see more: https://resend.com/docs/api-reference/domains/list-domains |
| 240 | +
|
| 241 | + Returns: |
| 242 | + ListResponse: A list of domain objects |
| 243 | + """ |
| 244 | + path = "/domains" |
| 245 | + resp = await AsyncRequest[_ListResponse]( |
| 246 | + path=path, params={}, verb="get" |
| 247 | + ).perform_with_content() |
| 248 | + return resp |
| 249 | + |
| 250 | + @classmethod |
| 251 | + async def remove_async(cls, domain_id: str) -> Domain: |
| 252 | + """ |
| 253 | + Remove an existing domain (async). |
| 254 | + see more: https://resend.com/docs/api-reference/domains/delete-domain |
| 255 | +
|
| 256 | + Args: |
| 257 | + domain_id (str): The domain ID |
| 258 | +
|
| 259 | + Returns: |
| 260 | + Domain: The removed domain object |
| 261 | + """ |
| 262 | + path = f"/domains/{domain_id}" |
| 263 | + resp = await AsyncRequest[Domain]( |
| 264 | + path=path, params={}, verb="delete" |
| 265 | + ).perform_with_content() |
| 266 | + return resp |
| 267 | + |
| 268 | + @classmethod |
| 269 | + async def verify_async(cls, domain_id: str) -> Domain: |
| 270 | + """ |
| 271 | + Verify an existing domain (async). |
| 272 | + see more: https://resend.com/docs/api-reference/domains/verify-domain |
| 273 | +
|
| 274 | + Args: |
| 275 | + domain_id (str): The domain ID |
| 276 | +
|
| 277 | + Returns: |
| 278 | + Domain: The verified domain object |
| 279 | + """ |
| 280 | + path = f"/domains/{domain_id}/verify" |
| 281 | + resp = await AsyncRequest[Domain]( |
| 282 | + path=path, params={}, verb="post" |
| 283 | + ).perform_with_content() |
| 284 | + return resp |
0 commit comments