Skip to content

Commit a945dcf

Browse files
Updated documentation
1 parent 3877a8f commit a945dcf

File tree

88 files changed

+2988
-1264
lines changed

Some content is hidden

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

88 files changed

+2988
-1264
lines changed

.github/PULL_REQUEST_TEMPLATE

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!--
2-
We appreciate the effort for this pull request but before that please make sure you read the contribution guidelines given above, then fill out the blanks below.
2+
We appreciate the effort for this pull request, but before that, please make sure you read the [contribution guidelines](https://github.com/sendgrid/sendgrid-python/blob/v4/CONTRIBUTING.md), and then fill out the blanks below.
33

44

55
Please enter each Issue number you are resolving in your PR after one of the following words [Fixes, Closes, Resolves]. This will auto-link these issues and close them when this PR is merged!
66
e.g.
77
Fixes #1
88
Closes #2
99
-->
10-
# Fixes #
10+
# Fixes #X
1111

1212
### Checklist
1313
- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar)
@@ -19,6 +19,5 @@ Closes #2
1919

2020
### Short description of what this PR does:
2121
-
22-
-
2322

24-
If you have questions, please send an email to [SendGrid](mailto:[email protected]), or file a GitHub Issue in this repository.
23+
If you have questions, please send an email to [Twilio SendGrid](mailto:[email protected]), or file a GitHub Issue in this repository.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ htmlcov
2222
temp.py
2323
.vscode
2424
live_test.py
25+
__pycache__
26+
example.pdf

README.rst

+48-42
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,23 @@ With Mail Helper Class
104104

105105
.. code:: python
106106
107-
import sendgrid
108107
import os
109-
from sendgrid.helpers.mail import *
110-
111-
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
112-
from_email = Email("[email protected]")
113-
to_email = Email("[email protected]")
114-
subject = "Sending with SendGrid is Fun"
115-
content = Content("text/plain", "and easy to do anywhere, even with Python")
116-
mail = Mail(from_email, subject, to_email, content)
117-
response = sg.client.mail.send.post(request_body=mail.get())
118-
print(response.status_code)
119-
print(response.body)
120-
print(response.headers)
108+
from sendgrid import SendGridAPIClient
109+
from sendgrid.helpers.mail import Mail
110+
111+
message = Mail(
112+
from_email='[email protected]',
113+
to_emails='[email protected]',
114+
subject='Sending with SendGrid is Fun',
115+
html_content='<strong>and easy to do anywhere, even with Python</strong>')
116+
try:
117+
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
118+
response = sg.send(message)
119+
print(response.status_code)
120+
print(response.body)
121+
print(response.headers)
122+
except Exception as e:
123+
print(e.message)
121124
122125
The ``Mail`` constructor creates a `personalization object`_ for you.
123126
`Here <https://github.com/sendgrid/sendgrid-python/blob/master/examples/helpers/mail/mail_example.py#L16>`__ is an example of how to add it.
@@ -130,45 +133,48 @@ The following is the minimum needed code to send an email without the /mail/send
130133

131134
.. code:: python
132135
133-
import sendgrid
134136
import os
137+
from sendgrid import SendGridAPIClient
135138
136-
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
137-
data = {
138-
"personalizations": [
139-
{
140-
"to": [
139+
message = {
140+
'personalizations': [
141+
{
142+
'to': [
143+
{
144+
'email': '[email protected]'
145+
}
146+
],
147+
'subject': 'Sending with SendGrid is Fun'
148+
}
149+
],
150+
'from': {
151+
'email': '[email protected]'
152+
},
153+
'content': [
141154
{
142-
"email": "[email protected]"
155+
'type': 'text/plain',
156+
'value': 'and easy to do anywhere, even with Python'
143157
}
144-
],
145-
"subject": "Sending with SendGrid is Fun"
146-
}
147-
],
148-
"from": {
149-
"email": "[email protected]"
150-
},
151-
"content": [
152-
{
153-
"type": "text/plain",
154-
"value": "and easy to do anywhere, even with Python"
155-
}
156-
]
158+
]
157159
}
158-
response = sg.client.mail.send.post(request_body=data)
159-
print(response.status_code)
160-
print(response.body)
161-
print(response.headers)
160+
try:
161+
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
162+
response = sg.send(message)
163+
print(response.status_code)
164+
print(response.body)
165+
print(response.headers)
166+
except Exception as e:
167+
print(e.message)
162168
163169
General v3 Web API Usage (With `Fluent Interface`_)
164170
---------------------------------------------------
165171

166172
.. code:: python
167173
168-
import sendgrid
169174
import os
175+
from sendgrid import SendGridAPIClient
170176
171-
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
177+
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
172178
response = sg.client.suppression.bounces.get()
173179
print(response.status_code)
174180
print(response.body)
@@ -179,11 +185,11 @@ General v3 Web API Usage (Without `Fluent Interface`_)
179185

180186
.. code:: python
181187
182-
import sendgrid
183188
import os
189+
from sendgrid import SendGridAPIClient
184190
185-
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
186-
response = sg.client._("suppression/bounces").get()
191+
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
192+
response = sg.client._('suppression/bounces').get()
187193
print(response.status_code)
188194
print(response.body)
189195
print(response.headers)

TROUBLESHOOTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ To read the error message returned by SendGrid's API in Python 2.X:
3838
import urllib2
3939

4040
try:
41-
response = sg.client.mail.send.post(request_body=mail.get())
41+
response = sendgrid_client.send(request_body=mail.get())
4242
except urllib2.HTTPError as e:
4343
print(e.read())
4444
```
@@ -48,7 +48,7 @@ To read the error message returned by SendGrid's API in Python 3.X:
4848
```python
4949
import urllib
5050
try:
51-
response = sg.client.mail.send.post(request_body=mail.get())
51+
response = sendgrid_client.send(request_body=mail.get())
5252
except urllib.error.HTTPError as e:
5353
print(e.read())
5454
```

USAGE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ This documentation is based on our [OAI specification](https://github.com/sendgr
33
# INITIALIZATION
44

55
```python
6-
import sendgrid
6+
from sendgrid import SendGridAPIClient
77
import os
88

99

10-
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
10+
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
1111
```
1212

1313
# Table of Contents

docker-test/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Use Docker to easily try out or contribute to the sendgrid-python library.
1+
Use Docker to easily test the sendgrid-python library.
22

33
This Docker image contains:
44
- Python 3.6

docker/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- `v3.2.2`
2121
- `v3.2.1`
2222
- `v3.2.0`
23+
2324
# Quick reference
2425
- **Where to get help:**
2526
[Contact SendGrid Support](https://support.sendgrid.com/hc/en-us)

0 commit comments

Comments
 (0)