Skip to content

Commit d67bd31

Browse files
authored
Merge branch 'main' into enable-multi-modal
2 parents c72f12d + bdedfcf commit d67bd31

File tree

11 files changed

+342
-2
lines changed

11 files changed

+342
-2
lines changed

.code-samples.meilisearch.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,3 +781,20 @@ search_parameter_reference_media_1: |-
781781
"limit": 3
782782
}
783783
)
784+
webhooks_get_1: |-
785+
client.get_webhooks()
786+
webhooks_get_single_1: |-
787+
client.get_webhook('WEBHOOK_UID')
788+
webhooks_post_1: |-
789+
client.create_webhook({
790+
'url': 'https://example.com/webhook',
791+
'headers': {"Authorization":"", "X-Custom-Header":"test"},
792+
})
793+
webhooks_patch_1: |-
794+
client.update_webhook('WEBHOOK_UID', {
795+
'url': 'https://example.com/new-webhook',
796+
'headers': {"Authorization":"", "X-Custom-Header":"test"},
797+
})
798+
webhooks_delete_1: |-
799+
client.delete_webhook('WEBHOOK_UID')
800+

meilisearch/client.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from meilisearch.index import Index
3333
from meilisearch.models.key import Key, KeysResults
3434
from meilisearch.models.task import Batch, BatchResults, Task, TaskInfo, TaskResults
35+
from meilisearch.models.webhook import Webhook, WebhooksResults
3536
from meilisearch.task import TaskHandler
3637

3738

@@ -465,6 +466,119 @@ def delete_key(self, key_or_uid: str) -> int:
465466

466467
return response.status_code
467468

469+
# WEBHOOKS ROUTES
470+
471+
def get_webhooks(self) -> WebhooksResults:
472+
"""Get all webhooks.
473+
474+
Returns
475+
-------
476+
webhooks:
477+
WebhooksResults instance containing list of webhooks and pagination info.
478+
https://www.meilisearch.com/docs/reference/api/webhooks
479+
480+
Raises
481+
------
482+
MeilisearchApiError
483+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
484+
"""
485+
webhooks = self.http.get(f"{self.config.paths.webhooks}")
486+
return WebhooksResults(**webhooks)
487+
488+
def get_webhook(self, webhook_uuid: str) -> Webhook:
489+
"""Get information about a specific webhook.
490+
491+
Parameters
492+
----------
493+
webhook_uuid:
494+
The uuid of the webhook to retrieve.
495+
496+
Returns
497+
-------
498+
webhook:
499+
The webhook information.
500+
https://www.meilisearch.com/docs/reference/api/webhooks#get-one-webhook
501+
502+
Raises
503+
------
504+
MeilisearchApiError
505+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
506+
"""
507+
webhook = self.http.get(f"{self.config.paths.webhooks}/{webhook_uuid}")
508+
return Webhook(**webhook)
509+
510+
def create_webhook(self, options: Mapping[str, Any]) -> Webhook:
511+
"""Create a new webhook.
512+
513+
Parameters
514+
----------
515+
options:
516+
The webhook configuration. Can include:
517+
- url: The URL to send the webhook to
518+
- headers: Dictionary of HTTP headers to include in webhook requests
519+
520+
Returns
521+
-------
522+
webhook:
523+
The newly created webhook.
524+
https://www.meilisearch.com/docs/reference/api/webhooks#create-a-webhook
525+
526+
Raises
527+
------
528+
MeilisearchApiError
529+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
530+
"""
531+
webhook = self.http.post(self.config.paths.webhooks, options)
532+
return Webhook(**webhook)
533+
534+
def update_webhook(self, webhook_uuid: str, options: Mapping[str, Any]) -> Webhook:
535+
"""Update an existing webhook.
536+
537+
Parameters
538+
----------
539+
webhook_uuid:
540+
The uuid of the webhook to update.
541+
options:
542+
The webhook fields to update. Can include:
543+
- url: The URL to send the webhook to
544+
- headers: Dictionary of HTTP headers to include in webhook requests
545+
546+
Returns
547+
-------
548+
webhook:
549+
The updated webhook.
550+
https://www.meilisearch.com/docs/reference/api/webhooks#update-a-webhook
551+
552+
Raises
553+
------
554+
MeilisearchApiError
555+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
556+
"""
557+
webhook = self.http.patch(f"{self.config.paths.webhooks}/{webhook_uuid}", options)
558+
return Webhook(**webhook)
559+
560+
def delete_webhook(self, webhook_uuid: str) -> int:
561+
"""Delete a webhook.
562+
563+
Parameters
564+
----------
565+
webhook_uuid:
566+
The uuid of the webhook to delete.
567+
568+
Returns
569+
-------
570+
status_code:
571+
The Response status code. 204 signifies a successful delete.
572+
https://www.meilisearch.com/docs/reference/api/webhooks#delete-a-webhook
573+
574+
Raises
575+
------
576+
MeilisearchApiError
577+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
578+
"""
579+
response = self.http.delete(f"{self.config.paths.webhooks}/{webhook_uuid}")
580+
return response.status_code
581+
468582
def get_version(self) -> Dict[str, str]:
469583
"""Get version Meilisearch
470584

meilisearch/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class Paths:
4848
edit = "edit"
4949
network = "network"
5050
experimental_features = "experimental-features"
51+
webhooks = "webhooks"
5152

5253
def __init__(
5354
self,

meilisearch/models/task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Task(CamelBase):
2121
enqueued_at: datetime
2222
started_at: Optional[datetime] = None
2323
finished_at: Optional[datetime] = None
24+
network: Optional[Dict[str, Any]] = None
2425

2526
if is_pydantic_2():
2627

meilisearch/models/webhook.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import Any, Dict, List, Optional
2+
3+
from camel_converter.pydantic_base import CamelBase
4+
from pydantic import ConfigDict
5+
6+
7+
class Webhook(CamelBase):
8+
"""Model for a Meilisearch webhook."""
9+
10+
model_config = ConfigDict(arbitrary_types_allowed=True)
11+
12+
uuid: str
13+
url: str
14+
headers: Optional[Dict[str, Any]] = None
15+
isEditable: bool
16+
17+
18+
class WebhooksResults(CamelBase):
19+
"""Model for webhooks list results."""
20+
21+
model_config = ConfigDict(arbitrary_types_allowed=True)
22+
results: List[Webhook]

tests/client/test_client_multi_search_meilisearch.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from meilisearch.errors import MeilisearchApiError
44
from tests.common import INDEX_UID, REMOTE_MS_1, REMOTE_MS_2
5+
from tests.test_utils import disable_sharding
56

67

78
def test_basic_multi_search(client, empty_index):
@@ -84,14 +85,17 @@ def test_multi_search_with_network(client, index_with_documents):
8485
resp = client.add_or_update_networks(
8586
{
8687
"self": REMOTE_MS_1,
88+
"sharding": True,
8789
"remotes": {
8890
REMOTE_MS_1: {
8991
"url": "http://ms-1235.example.meilisearch.io",
9092
"searchApiKey": "xxxxxxxx",
93+
"writeApiKey": "xxxxxxxx",
9194
},
9295
REMOTE_MS_2: {
9396
"url": "http://ms-1255.example.meilisearch.io",
9497
"searchApiKey": "xxxxxxxx",
98+
"writeApiKey": "xxxxxxxx",
9599
},
96100
},
97101
}
@@ -108,3 +112,4 @@ def test_multi_search_with_network(client, index_with_documents):
108112
assert response["hits"][0]["_federation"]["indexUid"] == INDEX_UID
109113
assert response["hits"][0]["_federation"]["remote"] == REMOTE_MS_1
110114
assert response["remoteErrors"] == {}
115+
disable_sharding(client)

tests/client/test_client_network.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from tests.common import REMOTE_MS_1, REMOTE_MS_2
4+
from tests.test_utils import disable_sharding
45

56

67
@pytest.mark.usefixtures("enable_network_options")
@@ -16,15 +17,27 @@ def test_add_or_update_networks(client):
1617
"""Tests upsert network remote instance."""
1718
body = {
1819
"self": REMOTE_MS_1,
20+
"sharding": True,
1921
"remotes": {
20-
REMOTE_MS_1: {"url": "http://localhost:7700", "searchApiKey": "xxxxxxxxxxxxxx"},
21-
REMOTE_MS_2: {"url": "http://localhost:7720", "searchApiKey": "xxxxxxxxxxxxxxx"},
22+
REMOTE_MS_1: {
23+
"url": "http://localhost:7700",
24+
"searchApiKey": "xxxxxxxxxxxxxx",
25+
"writeApiKey": "xxxxxxxxx",
26+
},
27+
REMOTE_MS_2: {
28+
"url": "http://localhost:7720",
29+
"searchApiKey": "xxxxxxxxxxxxxxx",
30+
"writeApiKey": "xxxxxxxx",
31+
},
2232
},
2333
}
2434
response = client.add_or_update_networks(body=body)
2535

2636
assert isinstance(response, dict)
2737
assert response["self"] == REMOTE_MS_1
38+
assert response["sharding"] is True
2839
assert len(response["remotes"]) >= 2
2940
assert REMOTE_MS_2 in response["remotes"]
3041
assert REMOTE_MS_1 in response["remotes"]
42+
43+
disable_sharding(client)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
3+
from tests.common import BASE_URL, REMOTE_MS_1
4+
from tests.test_utils import disable_sharding
5+
6+
7+
@pytest.mark.usefixtures("enable_network_options")
8+
def test_update_and_get_network_settings(client):
9+
"""Test updating and getting network settings."""
10+
instance_name = REMOTE_MS_1
11+
options = {
12+
"self": instance_name,
13+
"remotes": {
14+
instance_name: {
15+
"url": BASE_URL,
16+
"searchApiKey": "search-key-1",
17+
"writeApiKey": "write-key-1",
18+
}
19+
},
20+
"sharding": True,
21+
}
22+
23+
client.add_or_update_networks(options)
24+
response = client.get_all_networks()
25+
26+
assert response["self"] == options["self"]
27+
assert response["remotes"][instance_name]["url"] == options["remotes"][instance_name]["url"]
28+
assert (
29+
response["remotes"][instance_name]["searchApiKey"]
30+
== options["remotes"][instance_name]["searchApiKey"]
31+
)
32+
assert (
33+
response["remotes"][instance_name]["writeApiKey"]
34+
== options["remotes"][instance_name]["writeApiKey"]
35+
)
36+
assert response["sharding"] == options["sharding"]
37+
disable_sharding(client)

0 commit comments

Comments
 (0)