meilisearch-python-sdk 2.2.2__tar.gz → 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of meilisearch-python-sdk might be problematic. Click here for more details.

Files changed (26) hide show
  1. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/PKG-INFO +1 -1
  2. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/_client.py +31 -8
  3. meilisearch_python_sdk-2.3.0/meilisearch_python_sdk/_version.py +1 -0
  4. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/decorators.py +2 -2
  5. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/index.py +57 -18
  6. meilisearch_python_sdk-2.3.0/meilisearch_python_sdk/types.py +5 -0
  7. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/pyproject.toml +1 -1
  8. meilisearch_python_sdk-2.2.2/meilisearch_python_sdk/_version.py +0 -1
  9. meilisearch_python_sdk-2.2.2/meilisearch_python_sdk/types.py +0 -4
  10. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/LICENSE +0 -0
  11. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/README.md +0 -0
  12. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/__init__.py +0 -0
  13. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/_http_requests.py +0 -0
  14. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/_task.py +0 -0
  15. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/_utils.py +0 -0
  16. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/errors.py +0 -0
  17. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/models/__init__.py +0 -0
  18. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/models/client.py +0 -0
  19. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/models/documents.py +0 -0
  20. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/models/health.py +0 -0
  21. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/models/index.py +0 -0
  22. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/models/search.py +0 -0
  23. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/models/settings.py +0 -0
  24. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/models/task.py +0 -0
  25. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/models/version.py +0 -0
  26. {meilisearch_python_sdk-2.2.2 → meilisearch_python_sdk-2.3.0}/meilisearch_python_sdk/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: meilisearch-python-sdk
3
- Version: 2.2.2
3
+ Version: 2.3.0
4
4
  Summary: A Python async client for the Meilisearch API
5
5
  Home-page: https://github.com/sanders41/meilisearch-python-sdk
6
6
  License: MIT
@@ -25,9 +25,10 @@ from meilisearch_python_sdk.models.client import (
25
25
  from meilisearch_python_sdk.models.health import Health
26
26
  from meilisearch_python_sdk.models.index import IndexInfo
27
27
  from meilisearch_python_sdk.models.search import SearchParams, SearchResultsWithUID
28
+ from meilisearch_python_sdk.models.settings import MeilisearchSettings
28
29
  from meilisearch_python_sdk.models.task import TaskInfo, TaskResult, TaskStatus
29
30
  from meilisearch_python_sdk.models.version import Version
30
- from meilisearch_python_sdk.types import JsonDict
31
+ from meilisearch_python_sdk.types import JsonDict, JsonMapping
31
32
 
32
33
 
33
34
  class BaseClient:
@@ -43,7 +44,7 @@ class BaseClient:
43
44
 
44
45
  def generate_tenant_token(
45
46
  self,
46
- search_rules: JsonDict | list[str],
47
+ search_rules: JsonMapping | list[str],
47
48
  *,
48
49
  api_key: Key,
49
50
  expires_at: datetime | None = None,
@@ -185,13 +186,24 @@ class AsyncClient(BaseClient):
185
186
 
186
187
  return TaskInfo(**response.json())
187
188
 
188
- async def create_index(self, uid: str, primary_key: str | None = None) -> AsyncIndex:
189
+ async def create_index(
190
+ self,
191
+ uid: str,
192
+ primary_key: str | None = None,
193
+ *,
194
+ settings: MeilisearchSettings | None = None,
195
+ ) -> AsyncIndex:
189
196
  """Creates a new index.
190
197
 
191
198
  Args:
192
199
 
193
200
  uid: The index's unique identifier.
194
201
  primary_key: The primary key of the documents. Defaults to None.
202
+ settings: Settings for the index. The settings can also be updated independently of
203
+ creating the index. The advantage to updating them here is updating the settings after
204
+ adding documents will cause the documents to be re-indexed. Because of this it will be
205
+ faster to update them before adding documents. Defaults to None (i.e. default
206
+ Meilisearch index settings).
195
207
 
196
208
  Returns:
197
209
 
@@ -208,7 +220,7 @@ class AsyncClient(BaseClient):
208
220
  >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
209
221
  >>> index = await client.create_index("movies")
210
222
  """
211
- return await AsyncIndex.create(self.http_client, uid, primary_key)
223
+ return await AsyncIndex.create(self.http_client, uid, primary_key, settings=settings)
212
224
 
213
225
  async def create_snapshot(self) -> TaskInfo:
214
226
  """Trigger the creation of a Meilisearch snapshot.
@@ -711,7 +723,7 @@ class AsyncClient(BaseClient):
711
723
 
712
724
  >>> from meilisearch_python_sdk import AsyncClient
713
725
  >>> async with AsyncClient("http://localhost.com", "masterKey") as client:
714
- >>> health = await client.get_healths()
726
+ >>> health = await client.get_health()
715
727
  """
716
728
  response = await self._http_requests.get("health")
717
729
 
@@ -1021,13 +1033,24 @@ class Client(BaseClient):
1021
1033
 
1022
1034
  return TaskInfo(**response.json())
1023
1035
 
1024
- def create_index(self, uid: str, primary_key: str | None = None) -> Index:
1036
+ def create_index(
1037
+ self,
1038
+ uid: str,
1039
+ primary_key: str | None = None,
1040
+ *,
1041
+ settings: MeilisearchSettings | None = None,
1042
+ ) -> Index:
1025
1043
  """Creates a new index.
1026
1044
 
1027
1045
  Args:
1028
1046
 
1029
1047
  uid: The index's unique identifier.
1030
1048
  primary_key: The primary key of the documents. Defaults to None.
1049
+ settings: Settings for the index. The settings can also be updated independently of
1050
+ creating the index. The advantage to updating them here is updating the settings after
1051
+ adding documents will cause the documents to be re-indexed. Because of this it will be
1052
+ faster to update them before adding documents. Defaults to None (i.e. default
1053
+ Meilisearch index settings).
1031
1054
 
1032
1055
  Returns:
1033
1056
 
@@ -1044,7 +1067,7 @@ class Client(BaseClient):
1044
1067
  >>> client = Client("http://localhost.com", "masterKey")
1045
1068
  >>> index = client.create_index("movies")
1046
1069
  """
1047
- return Index.create(self.http_client, uid, primary_key)
1070
+ return Index.create(self.http_client, uid, primary_key, settings=settings)
1048
1071
 
1049
1072
  def create_snapshot(self) -> TaskInfo:
1050
1073
  """Trigger the creation of a Meilisearch snapshot.
@@ -1545,7 +1568,7 @@ class Client(BaseClient):
1545
1568
 
1546
1569
  >>> from meilisearch_python_sdk import Client
1547
1570
  >>> client = Client("http://localhost.com", "masterKey")
1548
- >>> health = client.get_healths()
1571
+ >>> health = client.get_health()
1549
1572
  """
1550
1573
  response = self._http_requests.get("health")
1551
1574
 
@@ -0,0 +1 @@
1
+ VERSION = "2.3.0"
@@ -19,7 +19,7 @@ class ConnectionInfo(NamedTuple):
19
19
  api_key: str
20
20
 
21
21
 
22
- def async_add_documments(
22
+ def async_add_documents(
23
23
  *,
24
24
  index_name: str,
25
25
  connection_info: AsyncClient | ConnectionInfo,
@@ -101,7 +101,7 @@ def async_add_documments(
101
101
  return decorator
102
102
 
103
103
 
104
- def add_documments(
104
+ def add_documents(
105
105
  *,
106
106
  index_name: str,
107
107
  connection_info: Client | ConnectionInfo,
@@ -6,7 +6,7 @@ from csv import DictReader
6
6
  from datetime import datetime
7
7
  from functools import partial
8
8
  from pathlib import Path
9
- from typing import Any, Generator
9
+ from typing import Any, Generator, Mapping, Sequence
10
10
  from urllib.parse import urlencode
11
11
  from warnings import warn
12
12
 
@@ -27,7 +27,7 @@ from meilisearch_python_sdk.models.settings import (
27
27
  TypoTolerance,
28
28
  )
29
29
  from meilisearch_python_sdk.models.task import TaskInfo
30
- from meilisearch_python_sdk.types import Filter, JsonDict
30
+ from meilisearch_python_sdk.types import Filter, JsonDict, JsonMapping
31
31
 
32
32
 
33
33
  class BaseIndex:
@@ -223,7 +223,12 @@ class AsyncIndex(BaseIndex):
223
223
 
224
224
  @classmethod
225
225
  async def create(
226
- cls, http_client: AsyncClient, uid: str, primary_key: str | None = None
226
+ cls,
227
+ http_client: AsyncClient,
228
+ uid: str,
229
+ primary_key: str | None = None,
230
+ *,
231
+ settings: MeilisearchSettings | None = None,
227
232
  ) -> AsyncIndex:
228
233
  """Creates a new index.
229
234
 
@@ -233,9 +238,14 @@ class AsyncIndex(BaseIndex):
233
238
  Args:
234
239
 
235
240
  http_client: An instance of the AsyncClient. This automatically gets passed by the
236
- Client when creating and AsyncIndex instance.
241
+ Client when creating an AsyncIndex instance.
237
242
  uid: The index's unique identifier.
238
243
  primary_key: The primary key of the documents. Defaults to None.
244
+ settings: Settings for the index. The settings can also be updated independently of
245
+ creating the index. The advantage to updating them here is updating the settings after
246
+ adding documents will cause the documents to be re-indexed. Because of this it will be
247
+ faster to update them before adding documents. Defaults to None (i.e. default
248
+ Meilisearch index settings).
239
249
 
240
250
  Returns:
241
251
 
@@ -261,9 +271,10 @@ class AsyncIndex(BaseIndex):
261
271
  http_request = AsyncHttpRequests(http_client)
262
272
  response = await http_request.post(url, payload)
263
273
  await async_wait_for_task(http_client, response.json()["taskUid"], timeout_in_ms=100000)
274
+
264
275
  index_response = await http_request.get(f"{url}/{uid}")
265
276
  index_dict = index_response.json()
266
- return cls(
277
+ index = cls(
267
278
  http_client=http_client,
268
279
  uid=index_dict["uid"],
269
280
  primary_key=index_dict["primaryKey"],
@@ -271,6 +282,12 @@ class AsyncIndex(BaseIndex):
271
282
  updated_at=index_dict["updatedAt"],
272
283
  )
273
284
 
285
+ if settings:
286
+ settings_task = await index.update_settings(settings)
287
+ await async_wait_for_task(http_client, settings_task.task_uid, timeout_in_ms=100000)
288
+
289
+ return index
290
+
274
291
  async def get_stats(self) -> IndexStats:
275
292
  """Get stats of the index.
276
293
 
@@ -619,7 +636,7 @@ class AsyncIndex(BaseIndex):
619
636
  return DocumentsInfo(**response.json())
620
637
 
621
638
  async def add_documents(
622
- self, documents: list[JsonDict], primary_key: str | None = None
639
+ self, documents: Sequence[JsonMapping], primary_key: str | None = None
623
640
  ) -> TaskInfo:
624
641
  """Add documents to the index.
625
642
 
@@ -660,7 +677,7 @@ class AsyncIndex(BaseIndex):
660
677
 
661
678
  async def add_documents_in_batches(
662
679
  self,
663
- documents: list[JsonDict],
680
+ documents: Sequence[JsonMapping],
664
681
  *,
665
682
  batch_size: int = 1000,
666
683
  primary_key: str | None = None,
@@ -1060,7 +1077,7 @@ class AsyncIndex(BaseIndex):
1060
1077
  return TaskInfo(**response.json())
1061
1078
 
1062
1079
  async def update_documents(
1063
- self, documents: list[JsonDict], primary_key: str | None = None
1080
+ self, documents: Sequence[JsonMapping], primary_key: str | None = None
1064
1081
  ) -> TaskInfo:
1065
1082
  """Update documents in the index.
1066
1083
 
@@ -1101,7 +1118,7 @@ class AsyncIndex(BaseIndex):
1101
1118
 
1102
1119
  async def update_documents_in_batches(
1103
1120
  self,
1104
- documents: list[JsonDict],
1121
+ documents: Sequence[JsonMapping],
1105
1122
  *,
1106
1123
  batch_size: int = 1000,
1107
1124
  primary_key: str | None = None,
@@ -3015,7 +3032,14 @@ class Index(BaseIndex):
3015
3032
  return info.primary_key
3016
3033
 
3017
3034
  @classmethod
3018
- def create(cls, http_client: Client, uid: str, primary_key: str | None = None) -> Index:
3035
+ def create(
3036
+ cls,
3037
+ http_client: Client,
3038
+ uid: str,
3039
+ primary_key: str | None = None,
3040
+ *,
3041
+ settings: MeilisearchSettings | None = None,
3042
+ ) -> Index:
3019
3043
  """Creates a new index.
3020
3044
 
3021
3045
  In general this method should not be used directly and instead the index should be created
@@ -3024,9 +3048,14 @@ class Index(BaseIndex):
3024
3048
  Args:
3025
3049
 
3026
3050
  http_client: An instance of the Client. This automatically gets passed by the Client
3027
- when creating and Index instance.
3051
+ when creating an Index instance.
3028
3052
  uid: The index's unique identifier.
3029
3053
  primary_key: The primary key of the documents. Defaults to None.
3054
+ settings: Settings for the index. The settings can also be updated independently of
3055
+ creating the index. The advantage to updating them here is updating the settings after
3056
+ adding documents will cause the documents to be re-indexed. Because of this it will be
3057
+ faster to update them before adding documents. Defaults to None (i.e. default
3058
+ Meilisearch index settings).
3030
3059
 
3031
3060
  Returns:
3032
3061
 
@@ -3054,7 +3083,7 @@ class Index(BaseIndex):
3054
3083
  wait_for_task(http_client, response.json()["taskUid"], timeout_in_ms=100000)
3055
3084
  index_response = http_request.get(f"{url}/{uid}")
3056
3085
  index_dict = index_response.json()
3057
- return cls(
3086
+ index = cls(
3058
3087
  http_client=http_client,
3059
3088
  uid=index_dict["uid"],
3060
3089
  primary_key=index_dict["primaryKey"],
@@ -3062,6 +3091,12 @@ class Index(BaseIndex):
3062
3091
  updated_at=index_dict["updatedAt"],
3063
3092
  )
3064
3093
 
3094
+ if settings:
3095
+ settings_task = index.update_settings(settings)
3096
+ wait_for_task(http_client, settings_task.task_uid, timeout_in_ms=10000)
3097
+
3098
+ return index
3099
+
3065
3100
  def get_stats(self) -> IndexStats:
3066
3101
  """Get stats of the index.
3067
3102
 
@@ -3406,7 +3441,9 @@ class Index(BaseIndex):
3406
3441
 
3407
3442
  return DocumentsInfo(**response.json())
3408
3443
 
3409
- def add_documents(self, documents: list[JsonDict], primary_key: str | None = None) -> TaskInfo:
3444
+ def add_documents(
3445
+ self, documents: Sequence[JsonMapping], primary_key: str | None = None
3446
+ ) -> TaskInfo:
3410
3447
  """Add documents to the index.
3411
3448
 
3412
3449
  Args:
@@ -3446,7 +3483,7 @@ class Index(BaseIndex):
3446
3483
 
3447
3484
  def add_documents_in_batches(
3448
3485
  self,
3449
- documents: list[JsonDict],
3486
+ documents: Sequence[JsonMapping],
3450
3487
  *,
3451
3488
  batch_size: int = 1000,
3452
3489
  primary_key: str | None = None,
@@ -3794,7 +3831,7 @@ class Index(BaseIndex):
3794
3831
  return TaskInfo(**response.json())
3795
3832
 
3796
3833
  def update_documents(
3797
- self, documents: list[JsonDict], primary_key: str | None = None
3834
+ self, documents: Sequence[JsonMapping], primary_key: str | None = None
3798
3835
  ) -> TaskInfo:
3799
3836
  """Update documents in the index.
3800
3837
 
@@ -3835,7 +3872,7 @@ class Index(BaseIndex):
3835
3872
 
3836
3873
  def update_documents_in_batches(
3837
3874
  self,
3838
- documents: list[JsonDict],
3875
+ documents: Sequence[JsonMapping],
3839
3876
  *,
3840
3877
  batch_size: int = 1000,
3841
3878
  primary_key: str | None = None,
@@ -5549,7 +5586,9 @@ async def _async_load_documents_from_file(
5549
5586
  return documents
5550
5587
 
5551
5588
 
5552
- def _batch(documents: list[dict], batch_size: int) -> Generator[list[dict], None, None]:
5589
+ def _batch(
5590
+ documents: Sequence[Mapping], batch_size: int
5591
+ ) -> Generator[Sequence[Mapping], None, None]:
5553
5592
  total_len = len(documents)
5554
5593
  for i in range(0, total_len, batch_size):
5555
5594
  yield documents[i : i + batch_size]
@@ -5667,7 +5706,7 @@ def _process_search_parameters(
5667
5706
  return body
5668
5707
 
5669
5708
 
5670
- def _build_encoded_url(base_url: str, params: JsonDict) -> str:
5709
+ def _build_encoded_url(base_url: str, params: JsonMapping) -> str:
5671
5710
  return f"{base_url}?{urlencode(params)}"
5672
5711
 
5673
5712
 
@@ -0,0 +1,5 @@
1
+ from typing import Any, Dict, List, Mapping, Union
2
+
3
+ Filter = Union[str, List[Union[str, List[str]]]]
4
+ JsonDict = Dict[str, Any]
5
+ JsonMapping = Mapping[str, Any]
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "meilisearch-python-sdk"
3
- version = "2.2.2"
3
+ version = "2.3.0"
4
4
  description = "A Python async client for the Meilisearch API"
5
5
  authors = ["Paul Sanders <psanders1@gmail.com>"]
6
6
  license = "MIT"
@@ -1 +0,0 @@
1
- VERSION = "2.2.2"
@@ -1,4 +0,0 @@
1
- from typing import Any, Dict, List, Union
2
-
3
- Filter = Union[str, List[Union[str, List[str]]]]
4
- JsonDict = Dict[str, Any]