|
5 | 5 | from resend import request |
6 | 6 | from resend.api_keys._api_key import ApiKey |
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 |
|
9 | 15 | class _ListResponse(TypedDict): |
10 | 16 | data: List[ApiKey] |
@@ -90,3 +96,54 @@ def remove(cls, api_key_id: str) -> None: |
90 | 96 | # This would raise if failed |
91 | 97 | request.Request[None](path=path, params={}, verb="delete").perform() |
92 | 98 | return None |
| 99 | + |
| 100 | + @classmethod |
| 101 | + async def create_async(cls, params: CreateParams) -> ApiKey: |
| 102 | + """ |
| 103 | + Add a new API key to authenticate communications with Resend (async). |
| 104 | + see more: https://resend.com/docs/api-reference/api-keys/create-api-key |
| 105 | +
|
| 106 | + Args: |
| 107 | + params (CreateParams): The API key creation parameters |
| 108 | +
|
| 109 | + Returns: |
| 110 | + ApiKey: The new API key object |
| 111 | + """ |
| 112 | + path = "/api-keys" |
| 113 | + resp = await AsyncRequest[ApiKey]( |
| 114 | + path=path, params=cast(Dict[Any, Any], params), verb="post" |
| 115 | + ).perform_with_content() |
| 116 | + return resp |
| 117 | + |
| 118 | + @classmethod |
| 119 | + async def list_async(cls) -> ListResponse: |
| 120 | + """ |
| 121 | + Retrieve a list of API keys for the authenticated user (async). |
| 122 | + see more: https://resend.com/docs/api-reference/api-keys/list-api-keys |
| 123 | +
|
| 124 | + Returns: |
| 125 | + ListResponse: A list of API key objects |
| 126 | + """ |
| 127 | + path = "/api-keys" |
| 128 | + resp = await AsyncRequest[_ListResponse]( |
| 129 | + path=path, params={}, verb="get" |
| 130 | + ).perform_with_content() |
| 131 | + return resp |
| 132 | + |
| 133 | + @classmethod |
| 134 | + async def remove_async(cls, api_key_id: str) -> None: |
| 135 | + """ |
| 136 | + Remove an existing API key (async). |
| 137 | + see more: https://resend.com/docs/api-reference/api-keys/delete-api-key |
| 138 | +
|
| 139 | + Args: |
| 140 | + api_key_id (str): The ID of the API key to remove |
| 141 | +
|
| 142 | + Returns: |
| 143 | + None |
| 144 | + """ |
| 145 | + path = f"/api-keys/{api_key_id}" |
| 146 | + |
| 147 | + # This would raise if failed |
| 148 | + await AsyncRequest[None](path=path, params={}, verb="delete").perform() |
| 149 | + return None |
0 commit comments