Skip to main content

SendGrid library for Python

Project description

|Travis Badge|

**This library allows you to quickly and easily use the SendGrid Web API
via Python.**

Currently this library supports our `v2 Mail
endpoint <https://sendgrid.com/docs/API_Reference/Web_API/mail.html>`__
and the `v3 Web
API <https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html>`__.

Installation
============

``pip install sendgrid``

or

``easy_install sendgrid``

Dependencies
------------

- The SendGrid Service, starting at the `free
level <https://sendgrid.com/free?source=sendgrid-python>`__
- `SMTAPI-Python <https://github.com/sendgrid/smtpapi-python>`__
- `Python-HTTP-Client <https://github.com/sendgrid/python-http-client>`__

Environment Variables (for v3 Web API)
--------------------------------------

`Sample
.env <https://github.com/sendgrid/sendgrid-python/blob/python_http_client/.env_sample>`__,
please rename to ``.env`` and add your `SendGrid API
Key <https://app.sendgrid.com/settings/api_keys>`__, or you can pass
your API Key into the SendGridClient constructor.

Quick Start
===========

v2 Mail Send endpoint (Send an Email)
-------------------------------------

.. code:: python

import sendgrid

sg = sendgrid.SendGridClient('YOUR_SENDGRID_API_KEY')


message = sendgrid.Mail()
message.add_to('John Doe <john@email.com>')
message.set_subject('Example')
message.set_html('Body')
message.set_text('Body')
message.set_from('Doe John <doe@email.com>')
status, msg = sg.send(message)
print(status, msg)

#or

message = sendgrid.Mail(to='john@email.com', subject='Example', html='Body', text='Body', from_email='doe@email.com')
status, msg = sg.send(message)
print(status, msg)

v3 Web API endpoints
--------------------

.. code:: python

import sendgrid

sg = sendgrid.SendGridAPIClient(apikey='YOUR_SENDGRID_API_KEY')
# You can also store your API key an .env variable 'SENDGRID_API_KEY'

response = sg.client.api_keys.get()
print(response.status_code)
print(response.response_body)
print(response.response_headers)

Announcements
=============

**BREAKING CHANGE as of 2016.03.01**

Version ``2.0.0`` is a breaking change for the **Web API v3 endpoints**.
The mail send endpoint is not affected by this update.

Version 2.0.0 brings you full support for all Web API v3 endpoints. We
have the following resources to get you started quickly:

- `SendGrid
Documentation <https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html>`__
- `Usage
Documentation <https://github.com/sendgrid/sendgrid-python/blob/master/USAGE.md>`__
- `Example
Code <https://github.com/sendgrid/sendgrid-python/blob/master/examples>`__

Thank you for your continued support!

For the **v2 Mail Send Endpoint**, if you upgrade to version ``1.2.x``,
the ``add_to`` method behaves differently. In the past this method
defaulted to using the ``SMTPAPI`` header. Now you must explicitly call
the ``smtpapi.add_to`` method. More on the ``SMTPAPI`` section.

Roadmap
-------

`Milestones <https://github.com/sendgrid/sendgrid-python/milestones>`__

How to Contribute
-----------------

We encourage contribution to our libraries, please see our
`CONTRIBUTING <https://github.com/sendgrid/sendgrid-python/blob/master/CONTRIBUTING.md>`__
guide for details.

- `Feature
Request <https://github.com/sendgrid/sendgrid-python/blob/master/CONTRIBUTING.md#feature_request>`__
- `Bug
Reports <https://github.com/sendgrid/sendgrid-python/blob/master/CONTRIBUTING.md#submit_a_bug_report>`__
- `Improvements to the
Codebase <https://github.com/sendgrid/sendgrid-python/blob/master/CONTRIBUTING.md#improvements_to_the_codebase>`__

Usage
-----

- `SendGrid
Docs <https://sendgrid.com/docs/API_Reference/index.html>`__
- `v2 Mail
Send <https://github.com/sendgrid/sendgrid-python/blob/master/USAGE_v2.md>`__
- `v3 Web
API <https://github.com/sendgrid/sendgrid-python/blob/master/USAGE.md>`__
- `Example
Code <https://github.com/sendgrid/sendgrid-python/blob/master/examples>`__

Unsupported Libraries
---------------------

- `Official and Unsupported SendGrid
Libraries <https://sendgrid.com/docs/Integrate/libraries.html>`__

About
=====

[SendGrid Logo]
.. |SendGrid Logo| image:: https://assets3.sendgrid.com/mkt/assets/logos\_brands/small/sglogo\_2015\_blue-9c87423c2ff2ff393ebce1ab3bd018a4.png
:target: https://www.sendgrid.com


sendgrid-python is guided and supported by the SendGrid `Developer
Experience Team <mailto:dx@sendgrid.com>`__.

sendgrid-python is maintained and funded by SendGrid, Inc. The names and
logos for sendgrid-python are trademarks of SendGrid, Inc.

.. |Travis Badge| image:: https://travis-ci.org/sendgrid/sendgrid-python.svg?branch=master
:target: https://travis-ci.org/sendgrid/sendgrid-python

Project details


Release history Release notifications | RSS feed

This version

2.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sendgrid-2.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sendgrid-2.1.0-py2-none-any.whl (26.8 kB view details)

Uploaded Python 2

File details

Details for the file sendgrid-2.1.0.tar.gz.

File metadata

  • Download URL: sendgrid-2.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sendgrid-2.1.0.tar.gz
Algorithm Hash digest
SHA256 3c20b69ddf39a11a9028e873b872a6112efdcbf7d0523854e6be42b674929e50
MD5 55cc2f4d0d9304d852ef8fd1ae3eb41a
BLAKE2b-256 f036febe7b88788103d560406f4720e42f0c19fd0c97d048c439ec865d16fa92

See more details on using hashes here.

File details

Details for the file sendgrid-2.1.0-py2-none-any.whl.

File metadata

File hashes

Hashes for sendgrid-2.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 7580ed4269c3e56f04b85ed66f6a6743524c8e7ab3c22dc9662937fea66190ad
MD5 4d4bfc3dc58428b0005752d6ba03ccc0
BLAKE2b-256 ee0d1518825f444103be692cd3ae26897d951d1d1e4a390234fd5da80eed83a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page