argilla.webhooks
¶
Webhooks are a way for web applications to notify each other when something happens. For example, you might want to be notified when a new dataset is created in Argilla.
Usage Examples¶
To listen for incoming webhooks, you can use the webhook_listener
decorator function to register a function to be called
when a webhook is received:
from argilla.webhooks import webhook_listener
@webhook_listener(events="dataset.created")
async def my_webhook_listener(dataset):
print(dataset)
To manually create a new webhook, instantiate the Webhook
object with the client and the name:
webhook = rg.Webhook(
url="https://somehost.com/webhook",
events=["dataset.created"],
description="My webhook"
)
webhook.create()
To retrieve a list of existing webhooks, use the client.webhooks
attribute:
Webhook
¶
Bases: Resource
The Webhook
resource. It represents a webhook that can be used to receive events from the Argilla Server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL of the webhook endpoint. |
required |
events |
List[EventType]
|
The events that the webhook is subscribed to. |
required |
description |
Optional[str]
|
The description of the webhook. |
None
|
_client |
Argilla
|
The client used to interact with the Argilla Server. |
None
|
Source code in src/argilla/webhooks/_resource.py
url: str
property
writable
¶
The URL of the webhook.
events: List[EventType]
property
writable
¶
The events that the webhook is subscribed to.
enabled: bool
property
writable
¶
Whether the webhook is enabled.
description: Optional[str]
property
writable
¶
The description of the webhook.
secret: str
property
¶
The secret of the webhook.
webhook_listener(events, description=None, client=None, server=None, raw_event=False)
¶
Decorator to create a webhook listener for a function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
events |
Union[str, List[str]]
|
The events to listen to. |
required |
description |
Optional[str]
|
The description of the webhook. |
None
|
client |
Optional[Argilla]
|
The Argilla client to use. Defaults to the default client. |
None
|
server |
Optional[FastAPI]
|
The FastAPI server to use. Defaults to the default server. |
None
|
raw_event |
bool
|
Whether to pass the raw event to the function. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Callable |
Callable
|
The decorated function. |
Source code in src/argilla/webhooks/_helpers.py
get_webhook_server()
¶
Get the current webhook server. If it does not exist, it will create one.
Returns:
Name | Type | Description |
---|---|---|
FastAPI |
FastAPI
|
The webhook server. |
Source code in src/argilla/webhooks/_helpers.py
set_webhook_server(app)
¶
Set the webhook server. This should only be called once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app |
FastAPI
|
The webhook server. |
required |
Source code in src/argilla/webhooks/_helpers.py
WebhookHandler
¶
The WebhookHandler
class is used to handle incoming webhook requests. This class handles the
request verification and event object creation.
Attributes:
Name | Type | Description |
---|---|---|
webhook |
Webhook
|
The webhook object. |
Source code in src/argilla/webhooks/_handler.py
handle(func, raw_event=False)
¶
This method handles the incoming webhook requests and calls the provided function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable
|
The function to be called when a webhook event is received. |
required |
raw_event |
bool
|
Whether to pass the raw event object to the function. |
False
|
Returns:
Source code in src/argilla/webhooks/_handler.py
WebhookEvent
¶
Bases: BaseModel
A webhook event.
Attributes:
Name | Type | Description |
---|---|---|
type |
EventType
|
The type of the event. |
timestamp |
datetime
|
The timestamp of the event. |
data |
dict
|
The data of the event. |
Source code in src/argilla/webhooks/_event.py
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
parsed(client)
¶
Parse the webhook event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client |
Argilla
|
The Argilla client. |
required |
Returns:
Name | Type | Description |
---|---|---|
Event |
Union[RecordEvent, DatasetEvent, UserResponseEvent, WebhookEvent]
|
The parsed event. |
Source code in src/argilla/webhooks/_event.py
DatasetEvent
¶
Bases: BaseModel
A parsed dataset event.
Attributes:
Name | Type | Description |
---|---|---|
type |
EventType
|
The type of the event. |
timestamp |
datetime
|
The timestamp of the event. |
dataset |
Dataset
|
The dataset of the event. |
Source code in src/argilla/webhooks/_event.py
RecordEvent
¶
Bases: BaseModel
A parsed record event.
Attributes:
Name | Type | Description |
---|---|---|
type |
EventType
|
The type of the event. |
timestamp |
datetime
|
The timestamp of the event. |
record |
Record
|
The record of the event. |
Source code in src/argilla/webhooks/_event.py
UserResponseEvent
¶
Bases: BaseModel
A parsed user response event.
Attributes:
Name | Type | Description |
---|---|---|
type |
EventType
|
The type of the event. |
timestamp |
datetime
|
The timestamp of the event. |
response |
UserResponse
|
The user response of the event. |