|
1 | 1 | import os |
| 2 | +from typing import Union |
2 | 3 |
|
3 | 4 | from .api_keys._api_key import ApiKey |
4 | 5 | from .api_keys._api_keys import ApiKeys |
|
16 | 17 | from .emails._emails import Emails |
17 | 18 | from .emails._tag import Tag |
18 | 19 | from .http_client import HTTPClient |
| 20 | +from .http_client_async import \ |
| 21 | + AsyncHTTPClient # Okay to import AsyncHTTPClient since it is just an interface. |
19 | 22 | from .http_client_requests import RequestsClient |
20 | 23 | from .request import Request |
21 | | - |
22 | | -# Async imports (optional - only available with pip install resend[async]) |
23 | | -try: |
24 | | - from .http_client_async import AsyncHTTPClient |
25 | | - from .http_client_httpx import HTTPXClient |
26 | | - from .async_request import AsyncRequest |
27 | | -except ImportError: |
28 | | - # Async classes not available without httpx dependency |
29 | | - pass |
30 | 24 | from .version import __version__, get_version |
31 | 25 |
|
| 26 | +# Type for clients that support both sync and async |
| 27 | +ResendHTTPClient = Union[HTTPClient, AsyncHTTPClient] |
| 28 | + |
| 29 | +# This is the client that is set by default HTTP Client |
| 30 | +# But this can be overridden by the user and set to an async client. |
| 31 | +default_http_client: ResendHTTPClient = RequestsClient() |
| 32 | + |
| 33 | + |
32 | 34 | # Config vars |
33 | 35 | api_key = os.environ.get("RESEND_API_KEY") |
34 | 36 | api_url = os.environ.get("RESEND_API_URL", "https://api.resend.com") |
35 | 37 |
|
36 | | -# HTTP Client |
37 | | -default_http_client: HTTPClient = RequestsClient() |
38 | 38 |
|
39 | 39 | # API resources |
40 | 40 | from .emails._emails import Emails # noqa |
|
66 | 66 |
|
67 | 67 | # Add async exports if available |
68 | 68 | try: |
69 | | - from .http_client_httpx import HTTPXClient |
70 | | - __all__.extend([ |
71 | | - "AsyncHTTPClient", |
72 | | - "HTTPXClient", |
73 | | - "AsyncRequest" |
74 | | - ]) |
| 69 | + from .async_request import AsyncRequest # noqa: F401 |
| 70 | + from .http_client_httpx import HTTPXClient # noqa: F401 |
| 71 | + |
| 72 | + __all__.extend(["AsyncHTTPClient", "HTTPXClient", "AsyncRequest"]) |
75 | 73 | except ImportError: |
76 | 74 | pass |
0 commit comments