22 "cells" : [
33 {
44 "cell_type" : " markdown" ,
5- "id" : " registered-pressure" ,
6- "metadata" : {},
5+ "source" : [
6+ " <td>\n " ,
7+ " <a target=\" _blank\" href=\" https://labelbox.com\" ><img src=\" https://labelbox.com/blog/content/images/2021/02/logo-v4.svg\" width=256/></a>\n " ,
8+ " </td>"
9+ ],
10+ "metadata" : {}
11+ },
12+ {
13+ "cell_type" : " markdown" ,
14+ "source" : [
15+ " <td>\n " ,
16+ " <a href=\" https://colab.research.google.com/github/Labelbox/labelbox-python/blob/develop/examples/project_configuration/webhooks.ipynb\" target=\" _blank\" ><img\n " ,
17+ " src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" ></a>\n " ,
18+ " </td>\n " ,
19+ " \n " ,
20+ " <td>\n " ,
21+ " <a href=\" https://github.com/Labelbox/labelbox-python/blob/develop/examples/project_configuration/webhooks.ipynb\" target=\" _blank\" ><img\n " ,
22+ " src=\" https://img.shields.io/badge/GitHub-100000?logo=github&logoColor=white\" alt=\" GitHub\" ></a>\n " ,
23+ " </td>"
24+ ],
25+ "metadata" : {}
26+ },
27+ {
28+ "cell_type" : " markdown" ,
729 "source" : [
830 " # Webhook Configuration"
9- ]
31+ ],
32+ "metadata" : {}
1033 },
1134 {
1235 "cell_type" : " markdown" ,
13- "id" : " surface-message" ,
14- "metadata" : {},
1536 "source" : [
16- " * Webhooks are supported for the following events:\n " ,
17- " 1. label_created\n " ,
18- " 2. label_updated\n " ,
19- " 3. label_deleted\n " ,
20- " 4. review_created\n " ,
21- " 5. review_updated"
22- ]
37+ " Webhooks are supported for the following events:\n " ,
38+ " * label_created\n " ,
39+ " * label_updated\n " ,
40+ " * label_deleted\n " ,
41+ " * review_created\n " ,
42+ " * review_updated"
43+ ],
44+ "metadata" : {}
2345 },
2446 {
2547 "cell_type" : " code" ,
2648 "execution_count" : null ,
27- "id" : " authentic-necessity" ,
28- "metadata" : {},
29- "outputs" : [],
3049 "source" : [
3150 " !pip install labelbox\n " ,
3251 " !pip install requests\n " ,
3352 " !pip install hmac\n " ,
3453 " !pip install hashlib\n " ,
3554 " !pip install flask\n " ,
3655 " !pip install Werkzeug"
37- ]
56+ ],
57+ "outputs" : [],
58+ "metadata" : {}
3859 },
3960 {
4061 "cell_type" : " code" ,
4162 "execution_count" : null ,
42- "id" : " responsible-clinton" ,
43- "metadata" : {},
44- "outputs" : [],
4563 "source" : [
4664 " from labelbox import Client, Webhook\n " ,
4765 " from flask import Flask, request\n " ,
5472 " import os\n " ,
5573 " from getpass import getpass\n " ,
5674 " import socket"
57- ]
75+ ],
76+ "outputs" : [],
77+ "metadata" : {}
5878 },
5979 {
6080 "cell_type" : " code" ,
6181 "execution_count" : null ,
62- "id" : " foreign-theorem" ,
63- "metadata" : {},
64- "outputs" : [],
6582 "source" : [
6683 " # If you don't want to give google access to drive you can skip this cell\n " ,
6784 " # and manually set `API_KEY` below.\n " ,
7895 " API_KEY = getpass(\" Please enter your labelbox api key\" )\n " ,
7996 " if COLAB:\n " ,
8097 " envvar_handler.add_env(\" LABELBOX_API_KEY\" , API_KEY)"
81- ]
98+ ],
99+ "outputs" : [],
100+ "metadata" : {}
82101 },
83102 {
84103 "cell_type" : " code" ,
85104 "execution_count" : null ,
86- "id" : " satellite-impossible" ,
87- "metadata" : {},
88- "outputs" : [],
89105 "source" : [
90106 " # Set this to a project that you want to use for the webhook\n " ,
91107 " PROJECT_ID = \"\"\n " ,
92108 " # Only update this if you have an on-prem deployment\n " ,
93109 " ENDPOINT = \" https://api.labelbox.com/graphql\" "
94- ]
110+ ],
111+ "outputs" : [],
112+ "metadata" : {}
95113 },
96114 {
97115 "cell_type" : " code" ,
98116 "execution_count" : null ,
99- "id" : " clean-ireland" ,
100- "metadata" : {},
101- "outputs" : [],
102117 "source" : [
103118 " client = Client(api_key=API_KEY, endpoint=ENDPOINT)"
104- ]
119+ ],
120+ "outputs" : [],
121+ "metadata" : {}
105122 },
106123 {
107124 "cell_type" : " code" ,
108125 "execution_count" : null ,
109- "id" : " bacterial-cheat" ,
110- "metadata" : {},
111- "outputs" : [],
112126 "source" : [
113127 " # We are using port 3001 for this example.\n " ,
114128 " # Feel free to set to whatever port you want\n " ,
115129 " WH_PORT = 3001"
116- ]
130+ ],
131+ "outputs" : [],
132+ "metadata" : {}
117133 },
118134 {
119135 "cell_type" : " markdown" ,
120- "id" : " owned-halifax" ,
121- "metadata" : {},
122136 "source" : [
123137 " ### Configure NGROK (Optional)\n " ,
124138 " * If you do not have a public ip address then follow along\n " ,
128142 " 2. Download ngrok and extract the zip file\n " ,
129143 " 3. Add ngrok to your path\n " ,
130144 " 4. Add the authtoken `ngrok authtoken <token>`"
131- ]
145+ ],
146+ "metadata" : {}
132147 },
133148 {
134149 "cell_type" : " code" ,
135150 "execution_count" : null ,
136- "id" : " aboriginal-antibody" ,
137- "metadata" : {},
138- "outputs" : [],
139151 "source" : [
140152 " if not COLAB:\n " ,
141153 " os.system(f\" ngrok http {WH_PORT} &\" )"
142- ]
154+ ],
155+ "outputs" : [],
156+ "metadata" : {}
143157 },
144158 {
145159 "cell_type" : " markdown" ,
146- "id" : " fitted-adams" ,
147- "metadata" : {},
148160 "source" : [
149161 " ### Configure server to receive requests"
150- ]
162+ ],
163+ "metadata" : {}
151164 },
152165 {
153166 "cell_type" : " code" ,
154167 "execution_count" : null ,
155- "id" : " stable-group" ,
156- "metadata" : {},
157- "outputs" : [],
158168 "source" : [
159169 " # This can be any secret that matches your webhook config (we will set later)\n " ,
160170 " secret = b\" example_secret\" "
161- ]
171+ ],
172+ "outputs" : [],
173+ "metadata" : {}
162174 },
163175 {
164176 "cell_type" : " code" ,
165177 "execution_count" : null ,
166- "id" : " limiting-variety" ,
167- "metadata" : {},
168- "outputs" : [],
169178 "source" : [
170179 " app = Flask(__name__)\n " ,
171180 " \n " ,
196205 " \n " ,
197206 " thread = threading.Thread(target=lambda: run_simple(\" 0.0.0.0\" , WH_PORT, app))\n " ,
198207 " thread.start()"
199- ]
208+ ],
209+ "outputs" : [],
210+ "metadata" : {}
200211 },
201212 {
202213 "cell_type" : " markdown" ,
203- "id" : " false-burlington" ,
204- "metadata" : {},
205214 "source" : [
206215 " #### Test server"
207- ]
216+ ],
217+ "metadata" : {}
208218 },
209219 {
210220 "cell_type" : " code" ,
211221 "execution_count" : null ,
212- "id" : " delayed-convention" ,
213- "metadata" : {},
214- "outputs" : [],
215222 "source" : [
216223 " print(requests.get(\" http://localhost:3001\" ).text)"
217- ]
224+ ],
225+ "outputs" : [],
226+ "metadata" : {}
218227 },
219228 {
220229 "cell_type" : " markdown" ,
221- "id" : " tribal-folks" ,
222- "metadata" : {},
223230 "source" : [
224231 " ### Create Webhook"
225- ]
232+ ],
233+ "metadata" : {}
226234 },
227235 {
228236 "cell_type" : " markdown" ,
229- "id" : " enabling-yahoo" ,
230- "metadata" : {},
231237 "source" : [
232238 " - Set ip address if your ip is publicly accessible.\n " ,
233239 " - Otherwise use the following to get ngrok public_url"
234- ]
240+ ],
241+ "metadata" : {}
235242 },
236243 {
237244 "cell_type" : " code" ,
238245 "execution_count" : null ,
239- "id" : " biblical-scottish" ,
240- "metadata" : {},
241- "outputs" : [],
242246 "source" : [
243247 " if not COLAB:\n " ,
244248 " res = requests.get(\" http://localhost:4040/api/tunnels\" )\n " ,
253257 " else:\n " ,
254258 " public_url = f\" http://{socket.gethostbyname(socket.getfqdn(socket.gethostname()))}\"\n " ,
255259 " print(public_url)"
256- ]
260+ ],
261+ "outputs" : [],
262+ "metadata" : {}
257263 },
258264 {
259265 "cell_type" : " code" ,
260266 "execution_count" : null ,
261- "id" : " raising-preservation" ,
262- "metadata" : {},
263- "outputs" : [],
264267 "source" : [
265268 " # Set project to limit the scope to a single project\n " ,
266269 " project = client.get_project(PROJECT_ID)\n " ,
270273 " url=public_url,\n " ,
271274 " secret=secret.decode(),\n " ,
272275 " project=project)"
273- ]
276+ ],
277+ "outputs" : [],
278+ "metadata" : {}
274279 },
275280 {
276281 "cell_type" : " code" ,
277282 "execution_count" : null ,
278- "id" : " approximate-gothic" ,
279- "metadata" : {},
280- "outputs" : [],
281283 "source" : [
282284 " # Ok so we should be configured assuming everything is setup correctly.\n " ,
283285 " # Go to the following url and make a new label to see if it works\n " ,
284286 " print(f\" https://app.labelbox.com/projects/{PROJECT_ID}\" )"
285- ]
287+ ],
288+ "outputs" : [],
289+ "metadata" : {}
286290 },
287291 {
288292 "cell_type" : " code" ,
289293 "execution_count" : null ,
290- "id" : " worst-material" ,
291- "metadata" : {},
292- "outputs" : [],
293294 "source" : [
294295 " ## Oops we made a mistake. The url was incorrect. We pointed the url to the hello world endpoint."
295- ]
296+ ],
297+ "outputs" : [],
298+ "metadata" : {}
296299 },
297300 {
298301 "cell_type" : " markdown" ,
299- "id" : " interesting-satellite" ,
300- "metadata" : {},
301302 "source" : [
302303 " ### Update Webhook"
303- ]
304+ ],
305+ "metadata" : {}
304306 },
305307 {
306308 "cell_type" : " code" ,
307309 "execution_count" : null ,
308- "id" : " stopped-steel" ,
309- "metadata" : {},
310- "outputs" : [],
311310 "source" : [
312311 " # url, topics, and status can all be updated\n " ,
313312 " updated_url = f\" {public_url}/webhook-endpoint\"\n " ,
316315 " # Go to the following url and try one last time.\n " ,
317316 " # Any supported action should work (create, delete, update a label, or create, update, or delete a review)\n " ,
318317 " print(f\" https://app.labelbox.com/projects/{PROJECT_ID}\" )"
319- ]
318+ ],
319+ "outputs" : [],
320+ "metadata" : {}
320321 },
321322 {
322323 "cell_type" : " markdown" ,
323- "id" : " streaming-generation" ,
324- "metadata" : {},
325324 "source" : [
326325 " ### List and delete all webhooks"
327- ]
326+ ],
327+ "metadata" : {}
328328 },
329329 {
330330 "cell_type" : " code" ,
331331 "execution_count" : null ,
332- "id" : " distant-commitment" ,
333- "metadata" : {},
334- "outputs" : [],
335332 "source" : [
336333 " # DELETE:\n " ,
337334 " webhook.update(status=Webhook.Status.INACTIVE.value)\n " ,
346343 " # for webhook in webhooks:\n " ,
347344 " # print(webhook)\n " ,
348345 " # webhook.update(status = Webhook.Status.INACTIVE.value)"
349- ]
346+ ],
347+ "outputs" : [],
348+ "metadata" : {}
350349 }
351350 ],
352351 "metadata" : {
370369 },
371370 "nbformat" : 4 ,
372371 "nbformat_minor" : 5
373- }
372+ }
0 commit comments