agentemail 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. agentemail-0.1.0/.gitignore +30 -0
  2. agentemail-0.1.0/PKG-INFO +125 -0
  3. agentemail-0.1.0/README.md +99 -0
  4. agentemail-0.1.0/__init__.py +89 -0
  5. agentemail-0.1.0/_default_clients.py +30 -0
  6. agentemail-0.1.0/client.py +225 -0
  7. agentemail-0.1.0/core/__init__.py +127 -0
  8. agentemail-0.1.0/core/api_error.py +23 -0
  9. agentemail-0.1.0/core/client_wrapper.py +133 -0
  10. agentemail-0.1.0/core/datetime_utils.py +70 -0
  11. agentemail-0.1.0/core/file.py +67 -0
  12. agentemail-0.1.0/core/force_multipart.py +18 -0
  13. agentemail-0.1.0/core/http_client.py +839 -0
  14. agentemail-0.1.0/core/http_response.py +59 -0
  15. agentemail-0.1.0/core/http_sse/__init__.py +42 -0
  16. agentemail-0.1.0/core/http_sse/_api.py +148 -0
  17. agentemail-0.1.0/core/http_sse/_decoders.py +61 -0
  18. agentemail-0.1.0/core/http_sse/_exceptions.py +7 -0
  19. agentemail-0.1.0/core/http_sse/_models.py +17 -0
  20. agentemail-0.1.0/core/jsonable_encoder.py +120 -0
  21. agentemail-0.1.0/core/logging.py +107 -0
  22. agentemail-0.1.0/core/parse_error.py +36 -0
  23. agentemail-0.1.0/core/pydantic_utilities.py +634 -0
  24. agentemail-0.1.0/core/query_encoder.py +58 -0
  25. agentemail-0.1.0/core/remove_none_from_dict.py +11 -0
  26. agentemail-0.1.0/core/request_options.py +35 -0
  27. agentemail-0.1.0/core/serialization.py +276 -0
  28. agentemail-0.1.0/environment.py +7 -0
  29. agentemail-0.1.0/errors/__init__.py +34 -0
  30. agentemail-0.1.0/errors/unprocessable_entity_error.py +11 -0
  31. agentemail-0.1.0/pyproject.toml +51 -0
  32. agentemail-0.1.0/sdk/__init__.py +4 -0
  33. agentemail-0.1.0/sdk/client.py +470 -0
  34. agentemail-0.1.0/sdk/raw_client.py +638 -0
  35. agentemail-0.1.0/types/__init__.py +68 -0
  36. agentemail-0.1.0/types/attachment_response.py +29 -0
  37. agentemail-0.1.0/types/email_detail.py +36 -0
  38. agentemail-0.1.0/types/email_detail_raw_headers.py +5 -0
  39. agentemail-0.1.0/types/http_validation_error.py +20 -0
  40. agentemail-0.1.0/types/inbox_response.py +27 -0
  41. agentemail-0.1.0/types/paginated_response_inbox_response.py +24 -0
  42. agentemail-0.1.0/types/paginated_response_thread_summary.py +24 -0
  43. agentemail-0.1.0/types/thread_detail.py +33 -0
  44. agentemail-0.1.0/types/thread_summary.py +31 -0
  45. agentemail-0.1.0/types/validation_error.py +24 -0
  46. agentemail-0.1.0/types/validation_error_loc_item.py +5 -0
@@ -0,0 +1,30 @@
1
+ .vercel/
2
+ .venv/
3
+ venv/
4
+ __pycache__/
5
+ *.pyc
6
+ *.pyo
7
+ *.pyd
8
+ .Python
9
+ .DS_Store
10
+ .env*
11
+
12
+ # Cloudflare Worker
13
+ .wrangler/
14
+ cloudflare-worker/node_modules/
15
+ cloudflare-worker/dist/
16
+ cloudflare-worker/.env.local
17
+ cloudflare-worker/wrangler.toml.local
18
+ cloudflare-worker/.wrangler
19
+
20
+ # Node
21
+ node_modules/
22
+ npm-debug.log
23
+ yarn-error.log
24
+
25
+ # IDE
26
+ .vscode/
27
+ .idea/
28
+ *.swp
29
+ *.swo
30
+ dist
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.4
2
+ Name: agentemail
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for the AgentEmail API — create and manage email inboxes programmatically.
5
+ Project-URL: Homepage, https://agentemail.co
6
+ Project-URL: Documentation, https://agentemail.co/docs
7
+ Project-URL: Repository, https://github.com/mbaiswar/agentemailpy
8
+ Author-email: AgentEmail <support@agentemail.co>
9
+ License: MIT
10
+ Keywords: agentemail,api,email,inbox,sdk
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Communications :: Email
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.8
23
+ Requires-Dist: httpx>=0.21.2
24
+ Requires-Dist: pydantic>=1.9.2
25
+ Description-Content-Type: text/markdown
26
+
27
+ # agentemail
28
+
29
+ Official Python SDK for the [AgentEmail](https://agentemail.co) API.
30
+
31
+ Create and manage email inboxes programmatically for your AI agents and applications.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install agentemail
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ```python
42
+ from agentemail import AgentemailApi
43
+
44
+ client = AgentemailApi(api_key="aem_your_api_key_here")
45
+
46
+ # List your inboxes
47
+ inboxes = client.sdk.list_inboxes()
48
+ print(inboxes.data)
49
+
50
+ # Create a new inbox
51
+ inbox = client.sdk.create_inbox(name="hello")
52
+ print(inbox.name) # "hello"
53
+ # Full address: hello@agentemail.co
54
+
55
+ # List email threads
56
+ threads = client.sdk.list_threads(inbox_id=inbox.id)
57
+ for thread in threads.data:
58
+ print(thread.subject, thread.message_count)
59
+
60
+ # Get a full thread with all messages
61
+ thread = client.sdk.get_thread(inbox_id=inbox.id, thread_id=threads.data[0].id)
62
+ for message in thread.messages:
63
+ print(message.from_address, message.body_text)
64
+
65
+ # Check usage vs plan limits
66
+ usage = client.sdk.get_usage()
67
+ print(f"Inboxes: {usage.inboxes.used}/{usage.inboxes.limit}")
68
+ ```
69
+
70
+ ## Async Usage
71
+
72
+ ```python
73
+ import asyncio
74
+ from agentemail import AsyncAgentemailApi
75
+
76
+ async def main():
77
+ client = AsyncAgentemailApi(api_key="aem_your_api_key_here")
78
+ inboxes = await client.sdk.list_inboxes()
79
+ print(inboxes.data)
80
+
81
+ asyncio.run(main())
82
+ ```
83
+
84
+ ## Authentication
85
+
86
+ Generate an API key from your [AgentEmail dashboard](https://app.agentemail.co/api-keys).
87
+
88
+ ```python
89
+ import os
90
+ from agentemail import AgentemailApi
91
+
92
+ client = AgentemailApi(api_key=os.environ["AGENTEMAIL_API_KEY"])
93
+ ```
94
+
95
+ ## API Reference
96
+
97
+ ### Inboxes
98
+
99
+ | Method | Description |
100
+ |--------|-------------|
101
+ | `client.sdk.list_inboxes()` | List all your inboxes (paginated) |
102
+ | `client.sdk.create_inbox(name=...)` | Create a new inbox |
103
+
104
+ ### Emails & Threads
105
+
106
+ | Method | Description |
107
+ |--------|-------------|
108
+ | `client.sdk.list_threads(inbox_id=...)` | List email threads for an inbox |
109
+ | `client.sdk.get_thread(inbox_id=..., thread_id=...)` | Get a thread with all messages |
110
+
111
+ ### Usage
112
+
113
+ | Method | Description |
114
+ |--------|-------------|
115
+ | `client.sdk.get_usage()` | Get current usage vs plan limits |
116
+
117
+ ## Links
118
+
119
+ - [Documentation](https://agentemail.co/docs)
120
+ - [Dashboard](https://app.agentemail.co)
121
+ - [GitHub](https://github.com/mbaiswar/agentemailpy)
122
+
123
+ ## License
124
+
125
+ MIT
@@ -0,0 +1,99 @@
1
+ # agentemail
2
+
3
+ Official Python SDK for the [AgentEmail](https://agentemail.co) API.
4
+
5
+ Create and manage email inboxes programmatically for your AI agents and applications.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install agentemail
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```python
16
+ from agentemail import AgentemailApi
17
+
18
+ client = AgentemailApi(api_key="aem_your_api_key_here")
19
+
20
+ # List your inboxes
21
+ inboxes = client.sdk.list_inboxes()
22
+ print(inboxes.data)
23
+
24
+ # Create a new inbox
25
+ inbox = client.sdk.create_inbox(name="hello")
26
+ print(inbox.name) # "hello"
27
+ # Full address: hello@agentemail.co
28
+
29
+ # List email threads
30
+ threads = client.sdk.list_threads(inbox_id=inbox.id)
31
+ for thread in threads.data:
32
+ print(thread.subject, thread.message_count)
33
+
34
+ # Get a full thread with all messages
35
+ thread = client.sdk.get_thread(inbox_id=inbox.id, thread_id=threads.data[0].id)
36
+ for message in thread.messages:
37
+ print(message.from_address, message.body_text)
38
+
39
+ # Check usage vs plan limits
40
+ usage = client.sdk.get_usage()
41
+ print(f"Inboxes: {usage.inboxes.used}/{usage.inboxes.limit}")
42
+ ```
43
+
44
+ ## Async Usage
45
+
46
+ ```python
47
+ import asyncio
48
+ from agentemail import AsyncAgentemailApi
49
+
50
+ async def main():
51
+ client = AsyncAgentemailApi(api_key="aem_your_api_key_here")
52
+ inboxes = await client.sdk.list_inboxes()
53
+ print(inboxes.data)
54
+
55
+ asyncio.run(main())
56
+ ```
57
+
58
+ ## Authentication
59
+
60
+ Generate an API key from your [AgentEmail dashboard](https://app.agentemail.co/api-keys).
61
+
62
+ ```python
63
+ import os
64
+ from agentemail import AgentemailApi
65
+
66
+ client = AgentemailApi(api_key=os.environ["AGENTEMAIL_API_KEY"])
67
+ ```
68
+
69
+ ## API Reference
70
+
71
+ ### Inboxes
72
+
73
+ | Method | Description |
74
+ |--------|-------------|
75
+ | `client.sdk.list_inboxes()` | List all your inboxes (paginated) |
76
+ | `client.sdk.create_inbox(name=...)` | Create a new inbox |
77
+
78
+ ### Emails & Threads
79
+
80
+ | Method | Description |
81
+ |--------|-------------|
82
+ | `client.sdk.list_threads(inbox_id=...)` | List email threads for an inbox |
83
+ | `client.sdk.get_thread(inbox_id=..., thread_id=...)` | Get a thread with all messages |
84
+
85
+ ### Usage
86
+
87
+ | Method | Description |
88
+ |--------|-------------|
89
+ | `client.sdk.get_usage()` | Get current usage vs plan limits |
90
+
91
+ ## Links
92
+
93
+ - [Documentation](https://agentemail.co/docs)
94
+ - [Dashboard](https://app.agentemail.co)
95
+ - [GitHub](https://github.com/mbaiswar/agentemailpy)
96
+
97
+ ## License
98
+
99
+ MIT
@@ -0,0 +1,89 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ # isort: skip_file
4
+
5
+ import typing
6
+ from importlib import import_module
7
+
8
+ if typing.TYPE_CHECKING:
9
+ from .types import (
10
+ AttachmentResponse,
11
+ EmailDetail,
12
+ EmailDetailRawHeaders,
13
+ HttpValidationError,
14
+ InboxResponse,
15
+ PaginatedResponseInboxResponse,
16
+ PaginatedResponseThreadSummary,
17
+ ThreadDetail,
18
+ ThreadSummary,
19
+ ValidationError,
20
+ ValidationErrorLocItem,
21
+ )
22
+ from .errors import UnprocessableEntityError
23
+ from . import sdk
24
+ from ._default_clients import DefaultAioHttpClient, DefaultAsyncHttpxClient
25
+ from .client import AgentemailApi, AsyncAgentemailApi
26
+ from .environment import AgentemailApiEnvironment
27
+ _dynamic_imports: typing.Dict[str, str] = {
28
+ "AgentemailApi": ".client",
29
+ "AgentemailApiEnvironment": ".environment",
30
+ "AsyncAgentemailApi": ".client",
31
+ "AttachmentResponse": ".types",
32
+ "DefaultAioHttpClient": "._default_clients",
33
+ "DefaultAsyncHttpxClient": "._default_clients",
34
+ "EmailDetail": ".types",
35
+ "EmailDetailRawHeaders": ".types",
36
+ "HttpValidationError": ".types",
37
+ "InboxResponse": ".types",
38
+ "PaginatedResponseInboxResponse": ".types",
39
+ "PaginatedResponseThreadSummary": ".types",
40
+ "ThreadDetail": ".types",
41
+ "ThreadSummary": ".types",
42
+ "UnprocessableEntityError": ".errors",
43
+ "ValidationError": ".types",
44
+ "ValidationErrorLocItem": ".types",
45
+ "sdk": ".sdk",
46
+ }
47
+
48
+
49
+ def __getattr__(attr_name: str) -> typing.Any:
50
+ module_name = _dynamic_imports.get(attr_name)
51
+ if module_name is None:
52
+ raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
53
+ try:
54
+ module = import_module(module_name, __package__)
55
+ if module_name == f".{attr_name}":
56
+ return module
57
+ else:
58
+ return getattr(module, attr_name)
59
+ except ImportError as e:
60
+ raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
61
+ except AttributeError as e:
62
+ raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
63
+
64
+
65
+ def __dir__():
66
+ lazy_attrs = list(_dynamic_imports.keys())
67
+ return sorted(lazy_attrs)
68
+
69
+
70
+ __all__ = [
71
+ "AgentemailApi",
72
+ "AgentemailApiEnvironment",
73
+ "AsyncAgentemailApi",
74
+ "AttachmentResponse",
75
+ "DefaultAioHttpClient",
76
+ "DefaultAsyncHttpxClient",
77
+ "EmailDetail",
78
+ "EmailDetailRawHeaders",
79
+ "HttpValidationError",
80
+ "InboxResponse",
81
+ "PaginatedResponseInboxResponse",
82
+ "PaginatedResponseThreadSummary",
83
+ "ThreadDetail",
84
+ "ThreadSummary",
85
+ "UnprocessableEntityError",
86
+ "ValidationError",
87
+ "ValidationErrorLocItem",
88
+ "sdk",
89
+ ]
@@ -0,0 +1,30 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ import typing
4
+
5
+ import httpx
6
+
7
+ SDK_DEFAULT_TIMEOUT = 60
8
+
9
+ try:
10
+ import httpx_aiohttp # type: ignore[import-not-found]
11
+ except ImportError:
12
+
13
+ class DefaultAioHttpClient(httpx.AsyncClient): # type: ignore
14
+ def __init__(self, **kwargs: typing.Any) -> None:
15
+ raise RuntimeError("To use the aiohttp client, install the aiohttp extra: pip install agentemail[aiohttp]")
16
+
17
+ else:
18
+
19
+ class DefaultAioHttpClient(httpx_aiohttp.HttpxAiohttpClient): # type: ignore
20
+ def __init__(self, **kwargs: typing.Any) -> None:
21
+ kwargs.setdefault("timeout", SDK_DEFAULT_TIMEOUT)
22
+ kwargs.setdefault("follow_redirects", True)
23
+ super().__init__(**kwargs)
24
+
25
+
26
+ class DefaultAsyncHttpxClient(httpx.AsyncClient):
27
+ def __init__(self, **kwargs: typing.Any) -> None:
28
+ kwargs.setdefault("timeout", SDK_DEFAULT_TIMEOUT)
29
+ kwargs.setdefault("follow_redirects", True)
30
+ super().__init__(**kwargs)
@@ -0,0 +1,225 @@
1
+ # This file was auto-generated by Fern from our API Definition.
2
+
3
+ from __future__ import annotations
4
+
5
+ import typing
6
+
7
+ import httpx
8
+ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
9
+ from .core.logging import LogConfig, Logger
10
+ from .environment import AgentemailApiEnvironment
11
+
12
+ if typing.TYPE_CHECKING:
13
+ from .sdk.client import AsyncSdkClient, SdkClient
14
+
15
+
16
+ class AgentemailApi:
17
+ """
18
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
19
+
20
+ Parameters
21
+ ----------
22
+ base_url : typing.Optional[str]
23
+ The base url to use for requests from the client.
24
+
25
+ environment : AgentemailApiEnvironment
26
+ The environment to use for requests from the client. from .environment import AgentemailApiEnvironment
27
+
28
+
29
+
30
+ Defaults to AgentemailApiEnvironment.PRODUCTION
31
+
32
+
33
+
34
+ api_key : str
35
+ token : typing.Union[str, typing.Callable[[], str]]
36
+ headers : typing.Optional[typing.Dict[str, str]]
37
+ Additional headers to send with every request.
38
+
39
+ timeout : typing.Optional[float]
40
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
41
+
42
+ max_retries : typing.Optional[int]
43
+ The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.
44
+
45
+ follow_redirects : typing.Optional[bool]
46
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
47
+
48
+ httpx_client : typing.Optional[httpx.Client]
49
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
50
+
51
+ logging : typing.Optional[typing.Union[LogConfig, Logger]]
52
+ Configure logging for the SDK. Accepts a LogConfig dict with 'level' (debug/info/warn/error), 'logger' (custom logger implementation), and 'silent' (boolean, defaults to True) fields. You can also pass a pre-configured Logger instance.
53
+
54
+ Examples
55
+ --------
56
+ from agentemail import AgentemailApi
57
+
58
+ client = AgentemailApi(
59
+ api_key="YOUR_API_KEY",
60
+ token="YOUR_TOKEN",
61
+ )
62
+ """
63
+
64
+ def __init__(
65
+ self,
66
+ *,
67
+ base_url: typing.Optional[str] = None,
68
+ environment: AgentemailApiEnvironment = AgentemailApiEnvironment.PRODUCTION,
69
+ api_key: str,
70
+ token: typing.Union[str, typing.Callable[[], str]],
71
+ headers: typing.Optional[typing.Dict[str, str]] = None,
72
+ timeout: typing.Optional[float] = None,
73
+ max_retries: typing.Optional[int] = None,
74
+ follow_redirects: typing.Optional[bool] = True,
75
+ httpx_client: typing.Optional[httpx.Client] = None,
76
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
77
+ ):
78
+ _defaulted_timeout = (
79
+ timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
80
+ )
81
+ _defaulted_max_retries = max_retries if max_retries is not None else 2
82
+ self._client_wrapper = SyncClientWrapper(
83
+ base_url=_get_base_url(base_url=base_url, environment=environment),
84
+ api_key=api_key,
85
+ token=token,
86
+ headers=headers,
87
+ httpx_client=httpx_client
88
+ if httpx_client is not None
89
+ else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
90
+ if follow_redirects is not None
91
+ else httpx.Client(timeout=_defaulted_timeout),
92
+ timeout=_defaulted_timeout,
93
+ max_retries=_defaulted_max_retries,
94
+ logging=logging,
95
+ )
96
+ self._sdk: typing.Optional[SdkClient] = None
97
+
98
+ @property
99
+ def sdk(self):
100
+ if self._sdk is None:
101
+ from .sdk.client import SdkClient # noqa: E402
102
+
103
+ self._sdk = SdkClient(client_wrapper=self._client_wrapper)
104
+ return self._sdk
105
+
106
+
107
+ def _make_default_async_client(
108
+ timeout: typing.Optional[float],
109
+ follow_redirects: typing.Optional[bool],
110
+ ) -> httpx.AsyncClient:
111
+ try:
112
+ import httpx_aiohttp # type: ignore[import-not-found]
113
+ except ImportError:
114
+ pass
115
+ else:
116
+ if follow_redirects is not None:
117
+ return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout, follow_redirects=follow_redirects)
118
+ return httpx_aiohttp.HttpxAiohttpClient(timeout=timeout)
119
+
120
+ if follow_redirects is not None:
121
+ return httpx.AsyncClient(timeout=timeout, follow_redirects=follow_redirects)
122
+ return httpx.AsyncClient(timeout=timeout)
123
+
124
+
125
+ class AsyncAgentemailApi:
126
+ """
127
+ Use this class to access the different functions within the SDK. You can instantiate any number of clients with different configuration that will propagate to these functions.
128
+
129
+ Parameters
130
+ ----------
131
+ base_url : typing.Optional[str]
132
+ The base url to use for requests from the client.
133
+
134
+ environment : AgentemailApiEnvironment
135
+ The environment to use for requests from the client. from .environment import AgentemailApiEnvironment
136
+
137
+
138
+
139
+ Defaults to AgentemailApiEnvironment.PRODUCTION
140
+
141
+
142
+
143
+ api_key : str
144
+ token : typing.Union[str, typing.Callable[[], str]]
145
+ headers : typing.Optional[typing.Dict[str, str]]
146
+ Additional headers to send with every request.
147
+
148
+ async_token : typing.Optional[typing.Callable[[], typing.Awaitable[str]]]
149
+ An async callable that returns a bearer token. Use this when token acquisition involves async I/O (e.g., refreshing tokens via an async HTTP client). When provided, this is used instead of the synchronous token for async requests.
150
+
151
+ timeout : typing.Optional[float]
152
+ The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced.
153
+
154
+ max_retries : typing.Optional[int]
155
+ The default maximum number of retries for failed requests. Defaults to 2. Per-request `max_retries` in `request_options` takes precedence over this value.
156
+
157
+ follow_redirects : typing.Optional[bool]
158
+ Whether the default httpx client follows redirects or not, this is irrelevant if a custom httpx client is passed in.
159
+
160
+ httpx_client : typing.Optional[httpx.AsyncClient]
161
+ The httpx client to use for making requests, a preconfigured client is used by default, however this is useful should you want to pass in any custom httpx configuration.
162
+
163
+ logging : typing.Optional[typing.Union[LogConfig, Logger]]
164
+ Configure logging for the SDK. Accepts a LogConfig dict with 'level' (debug/info/warn/error), 'logger' (custom logger implementation), and 'silent' (boolean, defaults to True) fields. You can also pass a pre-configured Logger instance.
165
+
166
+ Examples
167
+ --------
168
+ from agentemail import AsyncAgentemailApi
169
+
170
+ client = AsyncAgentemailApi(
171
+ api_key="YOUR_API_KEY",
172
+ token="YOUR_TOKEN",
173
+ )
174
+ """
175
+
176
+ def __init__(
177
+ self,
178
+ *,
179
+ base_url: typing.Optional[str] = None,
180
+ environment: AgentemailApiEnvironment = AgentemailApiEnvironment.PRODUCTION,
181
+ api_key: str,
182
+ token: typing.Union[str, typing.Callable[[], str]],
183
+ headers: typing.Optional[typing.Dict[str, str]] = None,
184
+ async_token: typing.Optional[typing.Callable[[], typing.Awaitable[str]]] = None,
185
+ timeout: typing.Optional[float] = None,
186
+ max_retries: typing.Optional[int] = None,
187
+ follow_redirects: typing.Optional[bool] = True,
188
+ httpx_client: typing.Optional[httpx.AsyncClient] = None,
189
+ logging: typing.Optional[typing.Union[LogConfig, Logger]] = None,
190
+ ):
191
+ _defaulted_timeout = (
192
+ timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read
193
+ )
194
+ _defaulted_max_retries = max_retries if max_retries is not None else 2
195
+ self._client_wrapper = AsyncClientWrapper(
196
+ base_url=_get_base_url(base_url=base_url, environment=environment),
197
+ api_key=api_key,
198
+ token=token,
199
+ headers=headers,
200
+ async_token=async_token,
201
+ httpx_client=httpx_client
202
+ if httpx_client is not None
203
+ else _make_default_async_client(timeout=_defaulted_timeout, follow_redirects=follow_redirects),
204
+ timeout=_defaulted_timeout,
205
+ max_retries=_defaulted_max_retries,
206
+ logging=logging,
207
+ )
208
+ self._sdk: typing.Optional[AsyncSdkClient] = None
209
+
210
+ @property
211
+ def sdk(self):
212
+ if self._sdk is None:
213
+ from .sdk.client import AsyncSdkClient # noqa: E402
214
+
215
+ self._sdk = AsyncSdkClient(client_wrapper=self._client_wrapper)
216
+ return self._sdk
217
+
218
+
219
+ def _get_base_url(*, base_url: typing.Optional[str] = None, environment: AgentemailApiEnvironment) -> str:
220
+ if base_url is not None:
221
+ return base_url
222
+ elif environment is not None:
223
+ return environment.value
224
+ else:
225
+ raise Exception("Please pass in either base_url or environment to construct the client")