mailfloss 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.
- mailfloss-0.1.0/LICENSE +21 -0
- mailfloss-0.1.0/PKG-INFO +185 -0
- mailfloss-0.1.0/README.md +154 -0
- mailfloss-0.1.0/pyproject.toml +43 -0
- mailfloss-0.1.0/setup.cfg +4 -0
- mailfloss-0.1.0/src/mailfloss/__init__.py +22 -0
- mailfloss-0.1.0/src/mailfloss/_transport.py +38 -0
- mailfloss-0.1.0/src/mailfloss/client.py +264 -0
- mailfloss-0.1.0/src/mailfloss/errors.py +39 -0
- mailfloss-0.1.0/src/mailfloss/py.typed +0 -0
- mailfloss-0.1.0/src/mailfloss/resources.py +380 -0
- mailfloss-0.1.0/src/mailfloss/types.py +599 -0
- mailfloss-0.1.0/src/mailfloss.egg-info/PKG-INFO +185 -0
- mailfloss-0.1.0/src/mailfloss.egg-info/SOURCES.txt +16 -0
- mailfloss-0.1.0/src/mailfloss.egg-info/dependency_links.txt +1 -0
- mailfloss-0.1.0/src/mailfloss.egg-info/top_level.txt +1 -0
- mailfloss-0.1.0/tests/test_client.py +278 -0
- mailfloss-0.1.0/tests/test_resources.py +187 -0
mailfloss-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mailfloss
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
mailfloss-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mailfloss
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Mailfloss Python SDK — email verification API client (zero dependencies)
|
|
5
|
+
Author-email: Mailfloss <support@mailfloss.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mailfloss/mailfloss-python
|
|
8
|
+
Project-URL: Repository, https://github.com/mailfloss/mailfloss-python
|
|
9
|
+
Project-URL: Documentation, https://developers.mailfloss.com
|
|
10
|
+
Project-URL: Changelog, https://github.com/mailfloss/mailfloss-python/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: mailfloss,email,verification,email-verification,api,sdk
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Communications :: Email
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# Mailfloss Python SDK
|
|
33
|
+
|
|
34
|
+
The official Python SDK for the [Mailfloss](https://mailfloss.com) email
|
|
35
|
+
verification API. Zero runtime dependencies — standard library only.
|
|
36
|
+
|
|
37
|
+
- Full coverage of the Mailfloss v1 public API
|
|
38
|
+
- Automatic retries (429/5xx, `Retry-After` aware, exponential backoff + jitter)
|
|
39
|
+
- Automatic `Idempotency-Key` on every POST
|
|
40
|
+
- Fully typed (`TypedDict` models, ships `py.typed`)
|
|
41
|
+
- Python 3.9+
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install mailfloss
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Authentication
|
|
50
|
+
|
|
51
|
+
Get your API key from the Mailfloss dashboard, then either pass it directly:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from mailfloss import Mailfloss
|
|
55
|
+
|
|
56
|
+
client = Mailfloss(api_key="mf_rk_your_key_here")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
or set it in the environment and construct the client with no arguments:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
export MAILFLOSS_API_KEY="mf_rk_your_key_here"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from mailfloss import Mailfloss
|
|
67
|
+
|
|
68
|
+
client = Mailfloss()
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Every request is sent with `Authorization: Bearer <key>`. If no key is
|
|
72
|
+
available, the constructor raises `MailflossConfigError`.
|
|
73
|
+
|
|
74
|
+
## Quickstart
|
|
75
|
+
|
|
76
|
+
### Verify a single email — `GET /v1/verify`
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from mailfloss import Mailfloss
|
|
80
|
+
|
|
81
|
+
client = Mailfloss()
|
|
82
|
+
|
|
83
|
+
result = client.verify("jane@example.com")
|
|
84
|
+
print(result["status"]) # "passed" | "undeliverable" | "risky" | "unknown"
|
|
85
|
+
print(result["passed"]) # True if safe to send
|
|
86
|
+
print(result["reason"]) # e.g. "available", "nonexistent", ...
|
|
87
|
+
if result.get("suggestion"):
|
|
88
|
+
print("Did you mean:", result["suggestion"])
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Verify a batch — `POST /v1/batch-verify`
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
job = client.batch_verify.create(
|
|
95
|
+
emails=["jane@example.com", "joe@exmaple.com"],
|
|
96
|
+
webhook_url="https://example.com/hooks/mailfloss", # optional callback
|
|
97
|
+
)
|
|
98
|
+
job_id = job["id"]
|
|
99
|
+
|
|
100
|
+
# Poll progress...
|
|
101
|
+
status = client.batch_verify.status(job_id)
|
|
102
|
+
print(status["status"], status.get("progress"))
|
|
103
|
+
|
|
104
|
+
# ...then page through results
|
|
105
|
+
page = client.batch_verify.results(job_id, per_page=500)
|
|
106
|
+
for row in page.get("results", []):
|
|
107
|
+
print(row)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Error handling
|
|
111
|
+
|
|
112
|
+
Non-2xx responses raise `MailflossError` with structured fields:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from mailfloss import Mailfloss, MailflossError
|
|
116
|
+
|
|
117
|
+
client = Mailfloss()
|
|
118
|
+
try:
|
|
119
|
+
client.jobs.get("does-not-exist")
|
|
120
|
+
except MailflossError as err:
|
|
121
|
+
print(err.status) # 404
|
|
122
|
+
print(err.code) # stable machine-readable code
|
|
123
|
+
print(err.message) # human-readable message
|
|
124
|
+
print(err.type) # e.g. "not_found_error"
|
|
125
|
+
print(err.request_id) # for support correlation
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Requests failing with 429 or 5xx (and connection errors) are retried
|
|
129
|
+
automatically up to `max_retries` (default 3), honoring the server's
|
|
130
|
+
`Retry-After` header when present.
|
|
131
|
+
|
|
132
|
+
## API surface
|
|
133
|
+
|
|
134
|
+
| Resource | Methods |
|
|
135
|
+
|---|---|
|
|
136
|
+
| Single verify | `client.verify(email, timeout=None)` |
|
|
137
|
+
| Batch verify | `client.batch_verify.create(emails, webhook_url=None)` / `.status(id)` / `.results(id, per_page=None, next=None)` / `.cancel(id)` |
|
|
138
|
+
| Jobs | `client.jobs.list(per_page=None, cursor=None, source=None, status=None)` / `.get(id)` |
|
|
139
|
+
| Users | `client.users.list(per_page=None, cursor=None)` / `.get(user_id)` |
|
|
140
|
+
| Reports | `client.reports.usage(period=None, connection_id=None)` |
|
|
141
|
+
| Key check | `client.check_key()` |
|
|
142
|
+
| Account | `client.account.get()` / `.update({...})` |
|
|
143
|
+
| Organization | `client.organization.get()` |
|
|
144
|
+
| Integrations | `client.integrations.list()` / `.get(type)` |
|
|
145
|
+
| Connections | `client.integrations.connections.create(type, credentials, name=None)` / `.get(type, id)` / `.update(type, id, {...})` / `.delete(type, id)` / `.sync(type, id)` / `.test(type, id)` |
|
|
146
|
+
| Keyword rules | `client.integrations.keywords.list(type, connection_id, list)` / `.add(type, connection_id, list, rules)` / `.delete(type, connection_id, list, rule_id)` |
|
|
147
|
+
| Erasures | `client.erasures.create(emails, webhook_url=None)` |
|
|
148
|
+
|
|
149
|
+
List endpoints return `{"data": [...], "pagination": {"next_cursor", "has_more"}}`.
|
|
150
|
+
|
|
151
|
+
## Configuration
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
client = Mailfloss(
|
|
155
|
+
api_key="mf_rk_...", # or MAILFLOSS_API_KEY
|
|
156
|
+
base_url="https://api.mailfloss.com/v1", # default
|
|
157
|
+
max_retries=3, # retries on 429/5xx/conn errors
|
|
158
|
+
timeout=30.0, # socket timeout, seconds
|
|
159
|
+
transport=None, # injectable low-level transport
|
|
160
|
+
)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Idempotency
|
|
164
|
+
|
|
165
|
+
Every POST automatically carries an `Idempotency-Key` header (UUIDv4),
|
|
166
|
+
generated once per call so retries replay the same key. Supply your own when
|
|
167
|
+
you want cross-process dedup:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
client.batch_verify.create(
|
|
171
|
+
emails=["jane@example.com"],
|
|
172
|
+
idempotency_key="order-12345-verify", # gitleaks:allow — docs example, not a secret
|
|
173
|
+
)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Development
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
cd sdks/python
|
|
180
|
+
PYTHONPATH=src python3 -m unittest discover -s tests -v
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Mailfloss Python SDK
|
|
2
|
+
|
|
3
|
+
The official Python SDK for the [Mailfloss](https://mailfloss.com) email
|
|
4
|
+
verification API. Zero runtime dependencies — standard library only.
|
|
5
|
+
|
|
6
|
+
- Full coverage of the Mailfloss v1 public API
|
|
7
|
+
- Automatic retries (429/5xx, `Retry-After` aware, exponential backoff + jitter)
|
|
8
|
+
- Automatic `Idempotency-Key` on every POST
|
|
9
|
+
- Fully typed (`TypedDict` models, ships `py.typed`)
|
|
10
|
+
- Python 3.9+
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install mailfloss
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Authentication
|
|
19
|
+
|
|
20
|
+
Get your API key from the Mailfloss dashboard, then either pass it directly:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from mailfloss import Mailfloss
|
|
24
|
+
|
|
25
|
+
client = Mailfloss(api_key="mf_rk_your_key_here")
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
or set it in the environment and construct the client with no arguments:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
export MAILFLOSS_API_KEY="mf_rk_your_key_here"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from mailfloss import Mailfloss
|
|
36
|
+
|
|
37
|
+
client = Mailfloss()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Every request is sent with `Authorization: Bearer <key>`. If no key is
|
|
41
|
+
available, the constructor raises `MailflossConfigError`.
|
|
42
|
+
|
|
43
|
+
## Quickstart
|
|
44
|
+
|
|
45
|
+
### Verify a single email — `GET /v1/verify`
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from mailfloss import Mailfloss
|
|
49
|
+
|
|
50
|
+
client = Mailfloss()
|
|
51
|
+
|
|
52
|
+
result = client.verify("jane@example.com")
|
|
53
|
+
print(result["status"]) # "passed" | "undeliverable" | "risky" | "unknown"
|
|
54
|
+
print(result["passed"]) # True if safe to send
|
|
55
|
+
print(result["reason"]) # e.g. "available", "nonexistent", ...
|
|
56
|
+
if result.get("suggestion"):
|
|
57
|
+
print("Did you mean:", result["suggestion"])
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Verify a batch — `POST /v1/batch-verify`
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
job = client.batch_verify.create(
|
|
64
|
+
emails=["jane@example.com", "joe@exmaple.com"],
|
|
65
|
+
webhook_url="https://example.com/hooks/mailfloss", # optional callback
|
|
66
|
+
)
|
|
67
|
+
job_id = job["id"]
|
|
68
|
+
|
|
69
|
+
# Poll progress...
|
|
70
|
+
status = client.batch_verify.status(job_id)
|
|
71
|
+
print(status["status"], status.get("progress"))
|
|
72
|
+
|
|
73
|
+
# ...then page through results
|
|
74
|
+
page = client.batch_verify.results(job_id, per_page=500)
|
|
75
|
+
for row in page.get("results", []):
|
|
76
|
+
print(row)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Error handling
|
|
80
|
+
|
|
81
|
+
Non-2xx responses raise `MailflossError` with structured fields:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from mailfloss import Mailfloss, MailflossError
|
|
85
|
+
|
|
86
|
+
client = Mailfloss()
|
|
87
|
+
try:
|
|
88
|
+
client.jobs.get("does-not-exist")
|
|
89
|
+
except MailflossError as err:
|
|
90
|
+
print(err.status) # 404
|
|
91
|
+
print(err.code) # stable machine-readable code
|
|
92
|
+
print(err.message) # human-readable message
|
|
93
|
+
print(err.type) # e.g. "not_found_error"
|
|
94
|
+
print(err.request_id) # for support correlation
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Requests failing with 429 or 5xx (and connection errors) are retried
|
|
98
|
+
automatically up to `max_retries` (default 3), honoring the server's
|
|
99
|
+
`Retry-After` header when present.
|
|
100
|
+
|
|
101
|
+
## API surface
|
|
102
|
+
|
|
103
|
+
| Resource | Methods |
|
|
104
|
+
|---|---|
|
|
105
|
+
| Single verify | `client.verify(email, timeout=None)` |
|
|
106
|
+
| Batch verify | `client.batch_verify.create(emails, webhook_url=None)` / `.status(id)` / `.results(id, per_page=None, next=None)` / `.cancel(id)` |
|
|
107
|
+
| Jobs | `client.jobs.list(per_page=None, cursor=None, source=None, status=None)` / `.get(id)` |
|
|
108
|
+
| Users | `client.users.list(per_page=None, cursor=None)` / `.get(user_id)` |
|
|
109
|
+
| Reports | `client.reports.usage(period=None, connection_id=None)` |
|
|
110
|
+
| Key check | `client.check_key()` |
|
|
111
|
+
| Account | `client.account.get()` / `.update({...})` |
|
|
112
|
+
| Organization | `client.organization.get()` |
|
|
113
|
+
| Integrations | `client.integrations.list()` / `.get(type)` |
|
|
114
|
+
| Connections | `client.integrations.connections.create(type, credentials, name=None)` / `.get(type, id)` / `.update(type, id, {...})` / `.delete(type, id)` / `.sync(type, id)` / `.test(type, id)` |
|
|
115
|
+
| Keyword rules | `client.integrations.keywords.list(type, connection_id, list)` / `.add(type, connection_id, list, rules)` / `.delete(type, connection_id, list, rule_id)` |
|
|
116
|
+
| Erasures | `client.erasures.create(emails, webhook_url=None)` |
|
|
117
|
+
|
|
118
|
+
List endpoints return `{"data": [...], "pagination": {"next_cursor", "has_more"}}`.
|
|
119
|
+
|
|
120
|
+
## Configuration
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
client = Mailfloss(
|
|
124
|
+
api_key="mf_rk_...", # or MAILFLOSS_API_KEY
|
|
125
|
+
base_url="https://api.mailfloss.com/v1", # default
|
|
126
|
+
max_retries=3, # retries on 429/5xx/conn errors
|
|
127
|
+
timeout=30.0, # socket timeout, seconds
|
|
128
|
+
transport=None, # injectable low-level transport
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Idempotency
|
|
133
|
+
|
|
134
|
+
Every POST automatically carries an `Idempotency-Key` header (UUIDv4),
|
|
135
|
+
generated once per call so retries replay the same key. Supply your own when
|
|
136
|
+
you want cross-process dedup:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
client.batch_verify.create(
|
|
140
|
+
emails=["jane@example.com"],
|
|
141
|
+
idempotency_key="order-12345-verify", # gitleaks:allow — docs example, not a secret
|
|
142
|
+
)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Development
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
cd sdks/python
|
|
149
|
+
PYTHONPATH=src python3 -m unittest discover -s tests -v
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mailfloss"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official Mailfloss Python SDK — email verification API client (zero dependencies)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
authors = [{ name = "Mailfloss", email = "support@mailfloss.com" }]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
dependencies = []
|
|
14
|
+
keywords = ["mailfloss", "email", "verification", "email-verification", "api", "sdk"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Programming Language :: Python :: 3.14",
|
|
28
|
+
"Topic :: Communications :: Email",
|
|
29
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
30
|
+
"Typing :: Typed",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/mailfloss/mailfloss-python"
|
|
35
|
+
Repository = "https://github.com/mailfloss/mailfloss-python"
|
|
36
|
+
Documentation = "https://developers.mailfloss.com"
|
|
37
|
+
Changelog = "https://github.com/mailfloss/mailfloss-python/blob/main/CHANGELOG.md"
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.packages.find]
|
|
40
|
+
where = ["src"]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.package-data]
|
|
43
|
+
mailfloss = ["py.typed"]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Official Mailfloss Python SDK.
|
|
2
|
+
|
|
3
|
+
Usage::
|
|
4
|
+
|
|
5
|
+
from mailfloss import Mailfloss
|
|
6
|
+
|
|
7
|
+
client = Mailfloss(api_key="mf_rk_...") # or set MAILFLOSS_API_KEY
|
|
8
|
+
result = client.verify("jane@example.com")
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .client import DEFAULT_BASE_URL, Mailfloss
|
|
12
|
+
from .errors import MailflossConfigError, MailflossError
|
|
13
|
+
|
|
14
|
+
__version__ = "0.1.0"
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"Mailfloss",
|
|
18
|
+
"MailflossError",
|
|
19
|
+
"MailflossConfigError",
|
|
20
|
+
"DEFAULT_BASE_URL",
|
|
21
|
+
"__version__",
|
|
22
|
+
]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Default HTTP transport built on the standard library only.
|
|
2
|
+
|
|
3
|
+
A transport is any callable with the signature::
|
|
4
|
+
|
|
5
|
+
transport(method, url, headers, body, timeout) -> (status, headers, body)
|
|
6
|
+
|
|
7
|
+
where ``body`` (request) is ``bytes`` or ``None``, the returned ``status`` is
|
|
8
|
+
an ``int``, the returned ``headers`` is a ``dict`` (case as sent by the
|
|
9
|
+
server), and the returned ``body`` is ``bytes``. HTTP-level error statuses
|
|
10
|
+
(4xx/5xx) must be RETURNED, not raised; only network/connection failures may
|
|
11
|
+
raise (``OSError`` and subclasses).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import urllib.error
|
|
17
|
+
import urllib.request
|
|
18
|
+
from typing import Dict, Optional, Tuple
|
|
19
|
+
|
|
20
|
+
__all__ = ["urllib_transport"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def urllib_transport(
|
|
24
|
+
method: str,
|
|
25
|
+
url: str,
|
|
26
|
+
headers: Dict[str, str],
|
|
27
|
+
body: Optional[bytes],
|
|
28
|
+
timeout: float,
|
|
29
|
+
) -> Tuple[int, Dict[str, str], bytes]:
|
|
30
|
+
"""Perform an HTTP request with ``urllib.request``."""
|
|
31
|
+
request = urllib.request.Request(url, data=body, headers=headers, method=method)
|
|
32
|
+
try:
|
|
33
|
+
with urllib.request.urlopen(request, timeout=timeout) as response:
|
|
34
|
+
return response.status, dict(response.headers.items()), response.read()
|
|
35
|
+
except urllib.error.HTTPError as exc:
|
|
36
|
+
# Non-2xx responses: surface as data, not as an exception.
|
|
37
|
+
payload = exc.read() if exc.fp is not None else b""
|
|
38
|
+
return exc.code, dict(exc.headers.items()), payload
|