Skip to content

Commit 1850c5c

Browse files
chore: v1.0.0 release (#82)
Co-authored-by: Pedro Impulcetto <[email protected]>
1 parent 544b451 commit 1850c5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1431
-459
lines changed

.github/workflows/test.yaml renamed to .github/workflows/ci.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: tests
22
on: [push, pull_request]
33

44
jobs:
5-
lint:
6-
name: Lint
5+
lint-mypy:
6+
name: Lint, Mypy
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
@@ -18,8 +18,6 @@ jobs:
1818
run: pip install tox
1919
- name: Check code quality with flake8
2020
run: tox -e lint
21-
- name: Check package metadata with Pyroma
22-
run: tox -e pyroma
2321
- name: Check static typing with MyPy
2422
run: tox -e mypy
2523
tests:

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
77
[![PyPI](https://img.shields.io/pypi/v/resend)](https://pypi.org/project/resend/)
88
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/resend)](https://pypi.org/project/resend)
9+
910
---
1011

1112
## Installation
@@ -29,14 +30,16 @@ resend.api_key = "re_yourkey"
2930

3031
## Example
3132

33+
You can get an overview about all parameters in the [Send Email](https://resend.com/docs/api-reference/emails/send-email) API reference.
34+
3235
```py
3336
import os
3437
import resend
3538

3639
resend.api_key = "re_yourkey"
3740

38-
params = {
39-
"from": "[email protected]",
41+
params: resend.Emails.SendParams = {
42+
"sender": "[email protected]",
4043
"to": ["[email protected]"],
4144
"subject": "hi",
4245
"html": "<strong>hello, world!</strong>",

examples/api_keys.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
if not os.environ["RESEND_API_KEY"]:
66
raise EnvironmentError("RESEND_API_KEY is missing")
77

8+
create_params: resend.ApiKeys.CreateParams = {
9+
"name": "example.com",
10+
}
811

9-
key = resend.ApiKeys.create(
10-
{
11-
"name": "prod",
12-
}
13-
)
14-
print(key)
12+
key = resend.ApiKeys.create(params=create_params)
13+
print("Created new api key")
14+
print(f"Key id: {key.id} and token: {key.token}")
1515

1616
keys = resend.ApiKeys.list()
17-
print(keys)
17+
for key in keys:
18+
print(key.id)
19+
print(key.name)
20+
print(key.created_at)
1821

19-
resend.ApiKeys.remove(key["id"])
22+
if len(keys) > 0:
23+
resend.ApiKeys.remove(api_key_id=keys[0].id)

examples/audiences.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
raise EnvironmentError("RESEND_API_KEY is missing")
77

88

9-
audience = resend.Audiences.create(
10-
{
11-
"name": "New Audience from Python SDK",
12-
}
13-
)
14-
print(audience)
9+
create_params: resend.Audiences.CreateParams = {
10+
"name": "New Audience from Python SDK",
11+
}
12+
audience = resend.Audiences.create(create_params)
13+
print(f"Created audience: {audience.id}")
14+
print(f"{audience.name} created")
1515

16-
aud = resend.Audiences.get(audience["id"])
17-
print(aud)
16+
aud = resend.Audiences.get(audience.id)
17+
print("Retrieved audience:", aud.id, aud.name, aud.created_at)
1818

1919
audiences = resend.Audiences.list()
20-
print(audiences)
20+
print("List of audiences:", [a.id for a in audiences])
2121

22-
rmed = resend.Audiences.remove(audience["id"])
23-
print(rmed)
22+
rmed = resend.Audiences.remove(id=audience.id)
23+
print(f"Deleted audience: {rmed.id} {rmed.deleted}")

examples/batch_email_send.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
import os
2+
from typing import List
23

34
import resend
45

56
if not os.environ["RESEND_API_KEY"]:
67
raise EnvironmentError("RESEND_API_KEY is missing")
78

89

9-
params = [
10+
params: List[resend.Emails.SendParams] = [
1011
{
11-
"from": "[email protected]",
12-
"to": ["delivered@resend.dev"],
12+
"sender": "[email protected]",
13+
"to": ["delivered@resende.dev"],
1314
"subject": "hey",
1415
"html": "<strong>hello, world!</strong>",
1516
},
1617
{
17-
"from": "[email protected]",
18-
"to": ["delivered@resend.dev"],
18+
"sender": "[email protected]",
19+
"to": ["delivered@resende.dev"],
1920
"subject": "hello",
2021
"html": "<strong>hello, world!</strong>",
2122
},
2223
]
2324

2425
emails = resend.Batch.send(params)
25-
print(emails)
26+
for email in emails:
27+
print(f"Email sent with id: {email.id}")

examples/contacts.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,48 @@
55
if not os.environ["RESEND_API_KEY"]:
66
raise EnvironmentError("RESEND_API_KEY is missing")
77

8+
# replace with some audience id
9+
audience_id: str = "ca4e37c5-a82a-4199-a3b8-bf912a6472aa"
810

9-
audience_id = "78b8d3bc-a55a-45a3-aee6-6ec0a5e13d7e"
10-
11-
contact = resend.Contacts.create(
12-
{
13-
"audience_id": audience_id,
14-
"email": "[email protected]",
15-
"first_name": "Steve",
16-
"last_name": "Wozniak",
17-
"unsubscribed": True,
18-
}
19-
)
20-
print("created contact !")
21-
print(contact)
22-
23-
update_params = {
11+
create_params: resend.Contacts.CreateParams = {
2412
"audience_id": audience_id,
25-
"id": contact["id"],
26-
"last_name": "Updated",
13+
"email": "[email protected]",
14+
"first_name": "Steve",
15+
"last_name": "Wozniak",
2716
"unsubscribed": False,
2817
}
2918

19+
contact = resend.Contacts.create(create_params)
20+
print(f"Created contact with ID: {contact.id}")
21+
22+
update_params: resend.Contacts.UpdateParams = {
23+
"audience_id": audience_id,
24+
"id": contact.id,
25+
"unsubscribed": False,
26+
"first_name": "Steve1",
27+
}
28+
3029
updated = resend.Contacts.update(update_params)
3130
print("updated contact !")
3231
print(updated)
3332

34-
cont = resend.Contacts.get(audience_id=audience_id, id=contact["id"])
35-
print(cont)
33+
cont = resend.Contacts.get(audience_id=audience_id, id=contact.id)
34+
print("Retrieved contact")
35+
print(cont.id)
36+
print(cont.email)
37+
print(cont.first_name)
38+
print(cont.last_name)
3639

3740
contacts = resend.Contacts.list(audience_id=audience_id)
38-
print(contacts)
41+
print("List of contacts")
42+
for contact in contacts:
43+
print(
44+
f"ID: {contact.id}, Email: {contact.email}, First Name: {contact.first_name}, Last Name: {contact.last_name}, Created At: {contact.created_at}, Unsubscribed: {contact.unsubscribed}"
45+
)
3946

4047
# remove by email
41-
rmed = resend.Contacts.remove(audience_id=audience_id, email="[email protected]")
48+
# rmed = resend.Contacts.remove(audience_id=audience_id, email=cont.email)
4249

4350
# remove by id
44-
# rmed = resend.Contacts.remove(audience_id=audience_id, id=contact["id"])
45-
print(rmed)
51+
rmed = resend.Contacts.remove(audience_id=audience_id, id=cont.id)
52+
print(f"Removed contact - ID: {rmed.id} Deleted: {rmed.deleted}")

examples/domains.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,39 @@
66
raise EnvironmentError("RESEND_API_KEY is missing")
77

88

9-
domain = resend.Domains.create(
10-
{
11-
"name": "domain.io",
12-
}
13-
)
14-
print(domain)
15-
16-
retrieved = resend.Domains.get(domain_id=domain["id"])
17-
print(retrieved)
18-
19-
update_params = {
20-
"id": domain["id"],
9+
create_params: resend.Domains.CreateParams = {
10+
"name": "example.com",
11+
"region": "us-east-1",
12+
}
13+
domain = resend.Domains.create(params=create_params)
14+
print(f"Crated domain {domain.name} with id {domain.id}")
15+
16+
retrieved = resend.Domains.get(domain_id=domain.id)
17+
print(retrieved.__dict__)
18+
for record in retrieved.records:
19+
print(record.__dict__)
20+
21+
update_params: resend.Domains.UpdateParams = {
22+
"id": domain.id,
2123
"open_tracking": True,
2224
"click_tracking": True,
2325
}
2426

25-
updated = resend.Domains.update(update_params)
26-
print(updated)
27+
updated_domain = resend.Domains.update(update_params)
28+
print(f"Updated domain: {updated_domain.id}")
2729

2830
domains = resend.Domains.list()
29-
print(domains)
31+
if not domains:
32+
print("No domains found")
33+
for domain in domains:
34+
print(domain.__dict__)
3035

31-
resend.Domains.verify(domain_id=domain["id"])
36+
resend.Domains.verify(domain_id=domain.id)
3237
print("domain verified")
3338

34-
resend.Domains.remove(domain_id=domain["id"])
35-
print("domain removed")
39+
domain = resend.Domains.remove(domain_id=domain.id)
40+
print(f"domain id: {domain.id} deleted: {domain.deleted}")
41+
42+
domain = resend.Domains.verify(domain_id=domain.id)
43+
print(f"Verified domain: {domain.id}")
44+
print(domain.id)

examples/simple_email.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
if not os.environ["RESEND_API_KEY"]:
66
raise EnvironmentError("RESEND_API_KEY is missing")
77

8-
9-
params = {
10-
"from": "[email protected]",
8+
params: resend.Emails.SendParams = {
9+
"sender": "[email protected]",
1110
"to": ["[email protected]"],
1211
"subject": "hi",
1312
"html": "<strong>hello, world!</strong>",
@@ -21,7 +20,8 @@
2120
}
2221

2322
email = resend.Emails.send(params)
24-
print(email)
23+
print(f"Email sent with id: {email.id}")
2524

26-
email_resp = resend.Emails.get(email_id=email["id"])
27-
print(email_resp)
25+
email_resp = resend.Emails.get(email_id=email.id)
26+
print(f"Retrieved email: {email_resp.id}")
27+
print(email_resp.__dict__)

examples/with_attachments.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@
66
raise EnvironmentError("RESEND_API_KEY is missing")
77

88

9-
f = open(
9+
# Read file
10+
f: bytes = open(
1011
os.path.join(os.path.dirname(__file__), "../resources/invoice.pdf"), "rb"
1112
).read()
1213

13-
params = {
14-
"from": "[email protected]",
15-
14+
# Define the file attachment
15+
attachment: resend.Attachment = {"filename": "invoice.pdf", "content": list(f)}
16+
17+
# Define the email parameters
18+
params: resend.Emails.SendParams = {
19+
"sender": "[email protected]",
20+
"to": ["[email protected]"],
1621
"subject": "hi",
1722
"html": "<strong>hello, world!</strong>",
18-
"attachments": [{"filename": "invoice.pdf", "content": list(f)}],
23+
"attachments": [attachment],
1924
}
2025

2126
r = resend.Emails.send(params)
22-
print(r)
27+
print("Sent email with attachment")
28+
print(f"Email ID: {r.id}")

examples/with_b64_attachments.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,28 @@
66
if not os.environ["RESEND_API_KEY"]:
77
raise EnvironmentError("RESEND_API_KEY is missing")
88

9+
# Read file
910
f = open(
1011
os.path.join(os.path.dirname(__file__), "../resources/invoice.pdf"), "rb"
1112
).read()
1213

13-
b64 = base64.b64encode(f)
14-
b64_str = b64.decode("utf-8")
14+
# Read file bytes as a base64 string
15+
b64: bytes = base64.b64encode(f)
16+
b64_str: str = b64.decode("utf-8")
1517

16-
params = {
17-
"from": "[email protected]",
18+
# Create attachment object from base64 string
19+
b64_attachment: resend.Attachment = {"filename": "invoice.pdf", "content": b64_str}
20+
21+
# Email params
22+
params: resend.Emails.SendParams = {
23+
"sender": "[email protected]",
1824
"to": ["[email protected]"],
1925
"subject": "hello with base64 attachments",
2026
"html": "<strong>hello, world!</strong>",
21-
"attachments": [{"filename": "invoice.pdf", "content": b64_str}],
27+
"attachments": [b64_attachment],
2228
}
2329

30+
# Send email
2431
email = resend.Emails.send(params)
25-
print(email)
32+
print("Email sent with base64 string attachment")
33+
print(f"Email ID: {email.id}")

0 commit comments

Comments
 (0)