Skip to content

Commit

Permalink
chore: v1.0.0 release (#82)
Browse files Browse the repository at this point in the history
Co-authored-by: Pedro Impulcetto <[email protected]>
  • Loading branch information
drish and pedroimpulcetto authored May 9, 2024
1 parent 544b451 commit 1850c5c
Show file tree
Hide file tree
Showing 56 changed files with 1,431 additions and 459 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/test.yaml → .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: tests
on: [push, pull_request]

jobs:
lint:
name: Lint
lint-mypy:
name: Lint, Mypy
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -18,8 +18,6 @@ jobs:
run: pip install tox
- name: Check code quality with flake8
run: tox -e lint
- name: Check package metadata with Pyroma
run: tox -e pyroma
- name: Check static typing with MyPy
run: tox -e mypy
tests:
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![PyPI](https://img.shields.io/pypi/v/resend)](https://pypi.org/project/resend/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/resend)](https://pypi.org/project/resend)

---

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

## Example

You can get an overview about all parameters in the [Send Email](https://resend.com/docs/api-reference/emails/send-email) API reference.

```py
import os
import resend

resend.api_key = "re_yourkey"

params = {
"from": "[email protected]",
params: resend.Emails.SendParams = {
"sender": "[email protected]",
"to": ["[email protected]"],
"subject": "hi",
"html": "<strong>hello, world!</strong>",
Expand Down
20 changes: 12 additions & 8 deletions examples/api_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
if not os.environ["RESEND_API_KEY"]:
raise EnvironmentError("RESEND_API_KEY is missing")

create_params: resend.ApiKeys.CreateParams = {
"name": "example.com",
}

key = resend.ApiKeys.create(
{
"name": "prod",
}
)
print(key)
key = resend.ApiKeys.create(params=create_params)
print("Created new api key")
print(f"Key id: {key.id} and token: {key.token}")

keys = resend.ApiKeys.list()
print(keys)
for key in keys:
print(key.id)
print(key.name)
print(key.created_at)

resend.ApiKeys.remove(key["id"])
if len(keys) > 0:
resend.ApiKeys.remove(api_key_id=keys[0].id)
22 changes: 11 additions & 11 deletions examples/audiences.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
raise EnvironmentError("RESEND_API_KEY is missing")


audience = resend.Audiences.create(
{
"name": "New Audience from Python SDK",
}
)
print(audience)
create_params: resend.Audiences.CreateParams = {
"name": "New Audience from Python SDK",
}
audience = resend.Audiences.create(create_params)
print(f"Created audience: {audience.id}")
print(f"{audience.name} created")

aud = resend.Audiences.get(audience["id"])
print(aud)
aud = resend.Audiences.get(audience.id)
print("Retrieved audience:", aud.id, aud.name, aud.created_at)

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

rmed = resend.Audiences.remove(audience["id"])
print(rmed)
rmed = resend.Audiences.remove(id=audience.id)
print(f"Deleted audience: {rmed.id} {rmed.deleted}")
14 changes: 8 additions & 6 deletions examples/batch_email_send.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import os
from typing import List

import resend

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


params = [
params: List[resend.Emails.SendParams] = [
{
"from": "[email protected]",
"to": ["delivered@resend.dev"],
"sender": "[email protected]",
"to": ["delivered@resende.dev"],
"subject": "hey",
"html": "<strong>hello, world!</strong>",
},
{
"from": "[email protected]",
"to": ["delivered@resend.dev"],
"sender": "[email protected]",
"to": ["delivered@resende.dev"],
"subject": "hello",
"html": "<strong>hello, world!</strong>",
},
]

emails = resend.Batch.send(params)
print(emails)
for email in emails:
print(f"Email sent with id: {email.id}")
53 changes: 30 additions & 23 deletions examples/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,48 @@
if not os.environ["RESEND_API_KEY"]:
raise EnvironmentError("RESEND_API_KEY is missing")

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

audience_id = "78b8d3bc-a55a-45a3-aee6-6ec0a5e13d7e"

contact = resend.Contacts.create(
{
"audience_id": audience_id,
"email": "[email protected]",
"first_name": "Steve",
"last_name": "Wozniak",
"unsubscribed": True,
}
)
print("created contact !")
print(contact)

update_params = {
create_params: resend.Contacts.CreateParams = {
"audience_id": audience_id,
"id": contact["id"],
"last_name": "Updated",
"email": "[email protected]",
"first_name": "Steve",
"last_name": "Wozniak",
"unsubscribed": False,
}

contact = resend.Contacts.create(create_params)
print(f"Created contact with ID: {contact.id}")

update_params: resend.Contacts.UpdateParams = {
"audience_id": audience_id,
"id": contact.id,
"unsubscribed": False,
"first_name": "Steve1",
}

updated = resend.Contacts.update(update_params)
print("updated contact !")
print(updated)

cont = resend.Contacts.get(audience_id=audience_id, id=contact["id"])
print(cont)
cont = resend.Contacts.get(audience_id=audience_id, id=contact.id)
print("Retrieved contact")
print(cont.id)
print(cont.email)
print(cont.first_name)
print(cont.last_name)

contacts = resend.Contacts.list(audience_id=audience_id)
print(contacts)
print("List of contacts")
for contact in contacts:
print(
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}"
)

# remove by email
rmed = resend.Contacts.remove(audience_id=audience_id, email="[email protected]")
# rmed = resend.Contacts.remove(audience_id=audience_id, email=cont.email)

# remove by id
# rmed = resend.Contacts.remove(audience_id=audience_id, id=contact["id"])
print(rmed)
rmed = resend.Contacts.remove(audience_id=audience_id, id=cont.id)
print(f"Removed contact - ID: {rmed.id} Deleted: {rmed.deleted}")
45 changes: 27 additions & 18 deletions examples/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,39 @@
raise EnvironmentError("RESEND_API_KEY is missing")


domain = resend.Domains.create(
{
"name": "domain.io",
}
)
print(domain)

retrieved = resend.Domains.get(domain_id=domain["id"])
print(retrieved)

update_params = {
"id": domain["id"],
create_params: resend.Domains.CreateParams = {
"name": "example.com",
"region": "us-east-1",
}
domain = resend.Domains.create(params=create_params)
print(f"Crated domain {domain.name} with id {domain.id}")

retrieved = resend.Domains.get(domain_id=domain.id)
print(retrieved.__dict__)
for record in retrieved.records:
print(record.__dict__)

update_params: resend.Domains.UpdateParams = {
"id": domain.id,
"open_tracking": True,
"click_tracking": True,
}

updated = resend.Domains.update(update_params)
print(updated)
updated_domain = resend.Domains.update(update_params)
print(f"Updated domain: {updated_domain.id}")

domains = resend.Domains.list()
print(domains)
if not domains:
print("No domains found")
for domain in domains:
print(domain.__dict__)

resend.Domains.verify(domain_id=domain["id"])
resend.Domains.verify(domain_id=domain.id)
print("domain verified")

resend.Domains.remove(domain_id=domain["id"])
print("domain removed")
domain = resend.Domains.remove(domain_id=domain.id)
print(f"domain id: {domain.id} deleted: {domain.deleted}")

domain = resend.Domains.verify(domain_id=domain.id)
print(f"Verified domain: {domain.id}")
print(domain.id)
12 changes: 6 additions & 6 deletions examples/simple_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
if not os.environ["RESEND_API_KEY"]:
raise EnvironmentError("RESEND_API_KEY is missing")


params = {
"from": "[email protected]",
params: resend.Emails.SendParams = {
"sender": "[email protected]",
"to": ["[email protected]"],
"subject": "hi",
"html": "<strong>hello, world!</strong>",
Expand All @@ -21,7 +20,8 @@
}

email = resend.Emails.send(params)
print(email)
print(f"Email sent with id: {email.id}")

email_resp = resend.Emails.get(email_id=email["id"])
print(email_resp)
email_resp = resend.Emails.get(email_id=email.id)
print(f"Retrieved email: {email_resp.id}")
print(email_resp.__dict__)
18 changes: 12 additions & 6 deletions examples/with_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
raise EnvironmentError("RESEND_API_KEY is missing")


f = open(
# Read file
f: bytes = open(
os.path.join(os.path.dirname(__file__), "../resources/invoice.pdf"), "rb"
).read()

params = {
"from": "[email protected]",
"to": "[email protected]",
# Define the file attachment
attachment: resend.Attachment = {"filename": "invoice.pdf", "content": list(f)}

# Define the email parameters
params: resend.Emails.SendParams = {
"sender": "[email protected]",
"to": ["[email protected]"],
"subject": "hi",
"html": "<strong>hello, world!</strong>",
"attachments": [{"filename": "invoice.pdf", "content": list(f)}],
"attachments": [attachment],
}

r = resend.Emails.send(params)
print(r)
print("Sent email with attachment")
print(f"Email ID: {r.id}")
20 changes: 14 additions & 6 deletions examples/with_b64_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@
if not os.environ["RESEND_API_KEY"]:
raise EnvironmentError("RESEND_API_KEY is missing")

# Read file
f = open(
os.path.join(os.path.dirname(__file__), "../resources/invoice.pdf"), "rb"
).read()

b64 = base64.b64encode(f)
b64_str = b64.decode("utf-8")
# Read file bytes as a base64 string
b64: bytes = base64.b64encode(f)
b64_str: str = b64.decode("utf-8")

params = {
"from": "[email protected]",
# Create attachment object from base64 string
b64_attachment: resend.Attachment = {"filename": "invoice.pdf", "content": b64_str}

# Email params
params: resend.Emails.SendParams = {
"sender": "[email protected]",
"to": ["[email protected]"],
"subject": "hello with base64 attachments",
"html": "<strong>hello, world!</strong>",
"attachments": [{"filename": "invoice.pdf", "content": b64_str}],
"attachments": [b64_attachment],
}

# Send email
email = resend.Emails.send(params)
print(email)
print("Email sent with base64 string attachment")
print(f"Email ID: {email.id}")
18 changes: 18 additions & 0 deletions examples/with_exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os

import resend

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

params: resend.Emails.SendParams = {
"sender": "[email protected]",
"to": ["invalid"],
"subject": "hi",
"html": "<strong>hello, world!</strong>",
}

try:
email = resend.Emails.send(params)
except resend.exceptions.ResendError as e:
print(f"Error sending email: {e}")
Loading

0 comments on commit 1850c5c

Please sign in to comment.