mailchannels 0.1.1__py3-none-any.whl

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 (40) hide show
  1. mailchannels/__init__.py +149 -0
  2. mailchannels/check_domain/__init__.py +28 -0
  3. mailchannels/check_domain/check_domain.py +182 -0
  4. mailchannels/check_domain/types.py +99 -0
  5. mailchannels/client.py +254 -0
  6. mailchannels/compatibility.py +42 -0
  7. mailchannels/dkim/__init__.py +28 -0
  8. mailchannels/dkim/dkim.py +570 -0
  9. mailchannels/dkim/types.py +77 -0
  10. mailchannels/emails/__init__.py +49 -0
  11. mailchannels/emails/emails.py +369 -0
  12. mailchannels/emails/types.py +462 -0
  13. mailchannels/exceptions.py +170 -0
  14. mailchannels/http_client.py +72 -0
  15. mailchannels/http_client_async.py +90 -0
  16. mailchannels/http_protocols.py +37 -0
  17. mailchannels/metrics/__init__.py +36 -0
  18. mailchannels/metrics/metrics.py +760 -0
  19. mailchannels/metrics/types.py +109 -0
  20. mailchannels/py.typed +1 -0
  21. mailchannels/query.py +41 -0
  22. mailchannels/response.py +192 -0
  23. mailchannels/routes.py +109 -0
  24. mailchannels/sub_accounts/__init__.py +39 -0
  25. mailchannels/sub_accounts/sub_accounts.py +1051 -0
  26. mailchannels/sub_accounts/types.py +117 -0
  27. mailchannels/suppressions/__init__.py +22 -0
  28. mailchannels/suppressions/suppressions.py +320 -0
  29. mailchannels/suppressions/types.py +53 -0
  30. mailchannels/usage/__init__.py +10 -0
  31. mailchannels/usage/types.py +15 -0
  32. mailchannels/usage/usage.py +72 -0
  33. mailchannels/version.py +15 -0
  34. mailchannels/webhooks/__init__.py +57 -0
  35. mailchannels/webhooks/types.py +160 -0
  36. mailchannels/webhooks/webhooks.py +936 -0
  37. mailchannels-0.1.1.dist-info/METADATA +749 -0
  38. mailchannels-0.1.1.dist-info/RECORD +40 -0
  39. mailchannels-0.1.1.dist-info/WHEEL +4 -0
  40. mailchannels-0.1.1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,149 @@
1
+ """Python SDK for the MailChannels Email API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+
7
+ from .check_domain import (
8
+ CheckDomain,
9
+ CheckDomainParams,
10
+ CheckDomainResource,
11
+ CheckDomainResult,
12
+ CheckResults,
13
+ DkimResult,
14
+ DkimSetting,
15
+ DomainCheckVerdict,
16
+ LockdownResult,
17
+ SenderDomainResult,
18
+ SpfResult,
19
+ )
20
+ from .client import DEFAULT_BASE_URL, Client
21
+ from .compatibility import API_SPEC_COMPATIBILITY, ApiSpecCompatibility
22
+ from .dkim import Dkim
23
+ from .emails import (
24
+ UNSUBSCRIBE_URL_PLACEHOLDER,
25
+ Attachment,
26
+ Content,
27
+ EmailAddress,
28
+ EmailHeaders,
29
+ EmailParams,
30
+ Emails,
31
+ Personalization,
32
+ QueuedSendResponse,
33
+ SendParams,
34
+ SendResponse,
35
+ SendResult,
36
+ TrackingSettings,
37
+ TrackingToggle,
38
+ )
39
+ from .exceptions import (
40
+ ApiError,
41
+ AsyncClientNotConfigured,
42
+ AuthenticationError,
43
+ BadGatewayError,
44
+ ConfigurationError,
45
+ ConflictError,
46
+ ForbiddenError,
47
+ InvalidRequestError,
48
+ MailChannelsError,
49
+ PayloadTooLargeError,
50
+ RateLimitError,
51
+ ResponseValidationError,
52
+ ServerError,
53
+ )
54
+ from .http_client import RequestsClient
55
+ from .http_client_async import HTTPXClient
56
+ from .http_protocols import AsyncHTTPClient, SyncHTTPClient
57
+ from .metrics import Metrics
58
+ from .response import EmptyResponse, SDKResponse
59
+ from .sub_accounts import SubAccounts
60
+ from .suppressions import Suppressions
61
+ from .usage import Usage, UsageStats
62
+ from .version import __version__, get_version
63
+ from .webhooks import (
64
+ SignatureParameters,
65
+ WebhookEventPayload,
66
+ Webhooks,
67
+ parse_signature_input,
68
+ signature_is_fresh,
69
+ signature_key_id,
70
+ verify_content_digest,
71
+ verify_webhook_signature,
72
+ )
73
+
74
+ api_key: str | None = os.environ.get("MAILCHANNELS_API_KEY")
75
+ base_url: str = os.environ.get("MAILCHANNELS_API_URL", DEFAULT_BASE_URL)
76
+ default_http_client: RequestsClient | None = None
77
+ default_async_http_client: HTTPXClient | None = None
78
+ strict_responses: bool = False
79
+
80
+ __all__ = [
81
+ "ApiError",
82
+ "ApiSpecCompatibility",
83
+ "AsyncHTTPClient",
84
+ "AsyncClientNotConfigured",
85
+ "Attachment",
86
+ "AuthenticationError",
87
+ "BadGatewayError",
88
+ "Client",
89
+ "ConfigurationError",
90
+ "ConflictError",
91
+ "Content",
92
+ "CheckDomainParams",
93
+ "CheckDomain",
94
+ "CheckDomainResult",
95
+ "CheckDomainResource",
96
+ "CheckResults",
97
+ "Dkim",
98
+ "DkimResult",
99
+ "DkimSetting",
100
+ "DomainCheckVerdict",
101
+ "EmailAddress",
102
+ "EmptyResponse",
103
+ "EmailHeaders",
104
+ "EmailParams",
105
+ "Emails",
106
+ "ForbiddenError",
107
+ "HTTPXClient",
108
+ "InvalidRequestError",
109
+ "LockdownResult",
110
+ "MailChannelsError",
111
+ "Metrics",
112
+ "PayloadTooLargeError",
113
+ "Personalization",
114
+ "QueuedSendResponse",
115
+ "RateLimitError",
116
+ "ResponseValidationError",
117
+ "RequestsClient",
118
+ "SendParams",
119
+ "SendResponse",
120
+ "SendResult",
121
+ "SenderDomainResult",
122
+ "ServerError",
123
+ "SDKResponse",
124
+ "SignatureParameters",
125
+ "SpfResult",
126
+ "SubAccounts",
127
+ "Suppressions",
128
+ "SyncHTTPClient",
129
+ "TrackingSettings",
130
+ "TrackingToggle",
131
+ "UNSUBSCRIBE_URL_PLACEHOLDER",
132
+ "Usage",
133
+ "UsageStats",
134
+ "WebhookEventPayload",
135
+ "Webhooks",
136
+ "API_SPEC_COMPATIBILITY",
137
+ "__version__",
138
+ "api_key",
139
+ "base_url",
140
+ "default_async_http_client",
141
+ "default_http_client",
142
+ "get_version",
143
+ "strict_responses",
144
+ "parse_signature_input",
145
+ "signature_is_fresh",
146
+ "signature_key_id",
147
+ "verify_content_digest",
148
+ "verify_webhook_signature",
149
+ ]
@@ -0,0 +1,28 @@
1
+ """Domain-check resource exports."""
2
+
3
+ from .check_domain import CheckDomain, CheckDomainResource
4
+ from .types import (
5
+ CheckDomainParams,
6
+ CheckDomainResult,
7
+ CheckResults,
8
+ DkimResult,
9
+ DkimSetting,
10
+ DomainCheckVerdict,
11
+ LockdownResult,
12
+ SenderDomainResult,
13
+ SpfResult,
14
+ )
15
+
16
+ __all__ = [
17
+ "CheckDomain",
18
+ "CheckDomainParams",
19
+ "CheckDomainResource",
20
+ "CheckDomainResult",
21
+ "CheckResults",
22
+ "DkimResult",
23
+ "DkimSetting",
24
+ "DomainCheckVerdict",
25
+ "LockdownResult",
26
+ "SenderDomainResult",
27
+ "SpfResult",
28
+ ]
@@ -0,0 +1,182 @@
1
+ """Domain configuration check resource implementation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import logging
6
+ from typing import Any, Generic, Literal, TypeVar, overload
7
+
8
+ from pydantic import ValidationError
9
+
10
+ from ..exceptions import MailChannelsError
11
+ from ..response import MailChannelsResponse
12
+ from .types import CheckDomainParams, CheckDomainResult, DkimSetting
13
+
14
+ logger = logging.getLogger(__name__)
15
+ StrictResponses = TypeVar("StrictResponses", bound=bool)
16
+
17
+
18
+ class CheckDomainResource(Generic[StrictResponses]):
19
+ """Client-bound domain configuration check operations."""
20
+
21
+ def __init__(self, client: Any) -> None:
22
+ """Create a domain checks resource bound to a client."""
23
+ self._client = client
24
+
25
+ @overload
26
+ def check(
27
+ self: CheckDomainResource[Literal[True]],
28
+ domain: str,
29
+ *,
30
+ sender_id: str | None = None,
31
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = None,
32
+ ) -> CheckDomainResult: ...
33
+
34
+ @overload
35
+ def check(
36
+ self: CheckDomainResource[Literal[False]],
37
+ domain: str,
38
+ *,
39
+ sender_id: str | None = None,
40
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = None,
41
+ ) -> MailChannelsResponse: ...
42
+
43
+ @overload
44
+ def check(
45
+ self,
46
+ domain: str,
47
+ *,
48
+ sender_id: str | None = None,
49
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = None,
50
+ ) -> CheckDomainResult | MailChannelsResponse: ...
51
+
52
+ def check(
53
+ self,
54
+ domain: str,
55
+ *,
56
+ sender_id: str | None = None,
57
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = None,
58
+ ) -> CheckDomainResult | MailChannelsResponse:
59
+ """Check DKIM, SPF, sender-domain DNS, and Domain Lockdown status."""
60
+ payload = _check_domain_payload(
61
+ domain,
62
+ sender_id=sender_id,
63
+ dkim_settings=dkim_settings,
64
+ )
65
+ logger.info("Checking MailChannels domain configuration domain=%s", domain)
66
+ return self._client.request(
67
+ "POST",
68
+ "/check-domain",
69
+ json=payload,
70
+ response_model=CheckDomainResult,
71
+ )
72
+
73
+ @overload
74
+ async def check_async(
75
+ self: CheckDomainResource[Literal[True]],
76
+ domain: str,
77
+ *,
78
+ sender_id: str | None = None,
79
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = None,
80
+ ) -> CheckDomainResult: ...
81
+
82
+ @overload
83
+ async def check_async(
84
+ self: CheckDomainResource[Literal[False]],
85
+ domain: str,
86
+ *,
87
+ sender_id: str | None = None,
88
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = None,
89
+ ) -> MailChannelsResponse: ...
90
+
91
+ @overload
92
+ async def check_async(
93
+ self,
94
+ domain: str,
95
+ *,
96
+ sender_id: str | None = None,
97
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = None,
98
+ ) -> CheckDomainResult | MailChannelsResponse: ...
99
+
100
+ async def check_async(
101
+ self,
102
+ domain: str,
103
+ *,
104
+ sender_id: str | None = None,
105
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = None,
106
+ ) -> CheckDomainResult | MailChannelsResponse:
107
+ """Check domain configuration status using async HTTP."""
108
+ payload = _check_domain_payload(
109
+ domain,
110
+ sender_id=sender_id,
111
+ dkim_settings=dkim_settings,
112
+ )
113
+ logger.info(
114
+ "Checking MailChannels domain configuration using async HTTP domain=%s",
115
+ domain,
116
+ )
117
+ return await self._client.request_async(
118
+ "POST",
119
+ "/check-domain",
120
+ json=payload,
121
+ response_model=CheckDomainResult,
122
+ )
123
+
124
+
125
+ class CheckDomain:
126
+ """Module-level domain configuration check operations."""
127
+
128
+ @classmethod
129
+ def check(
130
+ cls,
131
+ domain: str,
132
+ *,
133
+ sender_id: str | None = None,
134
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = None,
135
+ ) -> CheckDomainResult | MailChannelsResponse:
136
+ """Check DKIM, SPF, sender-domain DNS, and Domain Lockdown status."""
137
+ from ..client import get_default_client
138
+
139
+ return get_default_client().check_domain.check(
140
+ domain,
141
+ sender_id=sender_id,
142
+ dkim_settings=dkim_settings,
143
+ )
144
+
145
+ @classmethod
146
+ async def check_async(
147
+ cls,
148
+ domain: str,
149
+ *,
150
+ sender_id: str | None = None,
151
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = None,
152
+ ) -> CheckDomainResult | MailChannelsResponse:
153
+ """Check domain configuration status using async HTTP."""
154
+ from ..client import get_default_client
155
+
156
+ return await get_default_client().check_domain.check_async(
157
+ domain,
158
+ sender_id=sender_id,
159
+ dkim_settings=dkim_settings,
160
+ )
161
+
162
+
163
+ def _check_domain_payload(
164
+ domain: str,
165
+ *,
166
+ sender_id: str | None = None,
167
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = None,
168
+ ) -> dict[str, Any]:
169
+ """Build and validate a `/check-domain` request payload."""
170
+ try:
171
+ params = CheckDomainParams(
172
+ domain=domain,
173
+ sender_id=sender_id,
174
+ dkim_settings=dkim_settings,
175
+ )
176
+ except ValidationError as error:
177
+ logger.error("Invalid MailChannels domain check parameters: %s", error)
178
+ raise MailChannelsError(
179
+ "Invalid domain check parameters.",
180
+ code="InvalidDomainCheckParameters",
181
+ ) from error
182
+ return params.model_dump(exclude_none=True)
@@ -0,0 +1,99 @@
1
+ """Domain configuration check request and response types."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Literal
6
+
7
+ from pydantic import BaseModel, ConfigDict, Field
8
+
9
+ DomainCheckVerdict = Literal["passed", "failed"]
10
+
11
+
12
+ class DkimSetting(BaseModel):
13
+ """DKIM settings used by the domain check endpoint."""
14
+
15
+ dkim_domain: str | None = None
16
+ dkim_selector: str | None = None
17
+ dkim_private_key: str | None = None
18
+
19
+
20
+ class CheckDomainParams(BaseModel):
21
+ """Request body for `/check-domain`."""
22
+
23
+ domain: str
24
+ sender_id: str | None = None
25
+ dkim_settings: list[DkimSetting | dict[str, str]] | None = Field(
26
+ default=None,
27
+ max_length=10,
28
+ )
29
+
30
+
31
+ class DkimResult(BaseModel):
32
+ """One DKIM result returned by the domain check endpoint."""
33
+
34
+ model_config = ConfigDict(extra="allow")
35
+
36
+ dkim_domain: str | None = None
37
+ dkim_selector: str | None = None
38
+ dkim_key_status: str | None = None
39
+ reason: str | None = None
40
+ verdict: DomainCheckVerdict | None = None
41
+
42
+
43
+ class LockdownResult(BaseModel):
44
+ """Domain Lockdown check result."""
45
+
46
+ model_config = ConfigDict(extra="allow")
47
+
48
+ reason: str | None = None
49
+ verdict: DomainCheckVerdict | None = None
50
+
51
+
52
+ class SpfResult(BaseModel):
53
+ """SPF check result."""
54
+
55
+ model_config = ConfigDict(extra="allow")
56
+
57
+ reason: str | None = None
58
+ spfRecord: str | None = None
59
+ spfRecordError: str | None = None
60
+ verdict: DomainCheckVerdict | None = None
61
+
62
+
63
+ class SenderDomainRecordResult(BaseModel):
64
+ """A or MX record check result for sender-domain validation."""
65
+
66
+ model_config = ConfigDict(extra="allow")
67
+
68
+ reason: str | None = None
69
+ verdict: DomainCheckVerdict | None = None
70
+
71
+
72
+ class SenderDomainResult(BaseModel):
73
+ """Sender-domain DNS check result."""
74
+
75
+ model_config = ConfigDict(extra="allow")
76
+
77
+ a: SenderDomainRecordResult | None = None
78
+ mx: SenderDomainRecordResult | None = None
79
+ verdict: DomainCheckVerdict | None = None
80
+
81
+
82
+ class CheckResults(BaseModel):
83
+ """Grouped check results returned by `/check-domain`."""
84
+
85
+ model_config = ConfigDict(extra="allow")
86
+
87
+ dkim: list[DkimResult] | None = None
88
+ domain_lockdown: LockdownResult | None = None
89
+ sender_domain: SenderDomainResult | None = None
90
+ spf: SpfResult | None = None
91
+
92
+
93
+ class CheckDomainResult(BaseModel):
94
+ """Domain configuration check response model."""
95
+
96
+ model_config = ConfigDict(extra="allow")
97
+
98
+ check_results: CheckResults | None = None
99
+ references: list[str] | None = None