pyramid_sendgrid_webhooks package

Submodules

pyramid_sendgrid_webhooks.errors module

Exception classes raised when parsing fails

exception pyramid_sendgrid_webhooks.errors.UnknownEventError[source]

Bases: exceptions.KeyError

Raised when an unfamiliar event is received

pyramid_sendgrid_webhooks.parser module

Parses webhook events from request

pyramid_sendgrid_webhooks.parser.parse_event_data(request, event_data)[source]

Returns a single BaseWebhookEvent instance

pyramid_sendgrid_webhooks.parser.webhooks_from_request(request)[source]

Generates a sequence of BaseWebhookEvent instances

pyramid_sendgrid_webhooks.pyramid_sendgrid_webhooks module

Module contents

Pyramid plugin to receive, parse, and dispatch Sendgrid Webhook events

To use this app, add a configuration statement with your intended webhook callback path:

config.include(‘pyramid_sendgrid_webhooks’, ‘/sendgrid/webhooks’)

Then, set up subscribers for any events that you want to be notified of:

from pyramid_sendgrid_webhooks import events

def handle_bounce(event):
request = event.request print event.reason

... config.add_subscriber(handle_bounce, events.BounceEvent)

Currently the app adds a single endpoint at ‘{PREFIX}/receive’. This will be the webhook path to give to Sendgrid. In the example above, the full endpoint would therefore be at /sendgrid/webhooks/receive.

pyramid_sendgrid_webhooks.includeme(config)[source]

Adds route and view configuration

pyramid_sendgrid_webhooks.receive_events(request)[source]