Home
The Mister Webhooks API is organized around the MisterWebhooksConsumer class. Its sole purpose is
to support writing event consumers easily. The result is a minimal API.
Here's an example of the smallest possible Mister Webhooks client:
from mister_webhooks import ConnectionProfile, MisterWebhooksConsumer
import sys, pprint
if __name__ == "__main__":
topic, profile_path = sys.argv[1:]
profile = ConnectionProfile.from_file(profile_path)
consumer = MisterWebhooksConsumer(topic, profile)
consumer.run(pprint.pprint)
This program takes the topic to consume from as its first command-line argument and the path to the connection profile file as its second. It loads the connection profile from disk, uses it to create a consumer, and then runs the consumer loop, pretty-printing every webhook event as it comes in.
ConnectionProfile
dataclass
ConnectionProfile represents the data within a Mister Webhooks connection profile. A ConnectionProfile is usually created using one of the static methods, and then used to instantiate a MisterWebhooksConsumer.
Attributes:
| Name | Type | Description |
|---|---|---|
consumer_name |
str
|
Name of this consumer. |
auth_mechanism |
Literal
|
'plain'): SASL authentication mechanism this consumer uses. |
auth_secret |
str
|
(str): The secret to be used in SASL authentication. |
kafka_bootstrap |
str
|
(str): Kafka DNS domain & port to use to find brokers. |
Source code in python/mister_webhooks/connection_profile.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
from_file(path)
staticmethod
from_file reads a ConnectionProfile from a Mister Webhooks connection profile file.
Source code in python/mister_webhooks/connection_profile.py
24 25 26 27 28 29 30 31 32 33 34 35 | |
HTTPMethod
Bases: Enum
HTTPMethod represents the HTTP method used to transmit the webhook event.
Only the document manipulation methods are encoded here, namely:
- GET
- HEAD
- POST
- PUT
- PATCH
- DELETE
Source code in python/mister_webhooks/webhook_event.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
MisterWebhooksConsumer
MisterWebhooksConsumer is a message consumer for Mister Webhooks events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topic
|
str
|
The Mister Webhooks topic to consume from. |
required |
profile
|
ConnectionProfile
|
The connection profile to connect with. |
required |
Source code in python/mister_webhooks/client.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
run(cb)
Run runs the consumer and passes each incoming webhook event to the provided callback. It automatically takes care of offset bookkeeping when the callback runs without error. All exceptions thrown by the callback are re-raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cb
|
Callable[[WebhookEvent], None]
|
The callback to run on each message. |
required |
Source code in python/mister_webhooks/client.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
WebhookEvent
dataclass
WebhookEvent represents a received webhook event
Source code in python/mister_webhooks/webhook_event.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
headers
instance-attribute
HTTP headers captured from the webhook request
method
instance-attribute
HTTP method used to transmit the webhook event
payload
instance-attribute
Webhook request body
timestamp
instance-attribute
Time at which the webhook event occurred