meilisearch-python-sdk 2.12.0__py3-none-any.whl → 3.0.0__py3-none-any.whl

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.

@@ -0,0 +1,77 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from abc import ABC, abstractmethod
5
+ from typing import TYPE_CHECKING, Any
6
+
7
+ if TYPE_CHECKING: # pragma: no cover
8
+ pass
9
+
10
+ try:
11
+ import orjson
12
+ except ImportError: # pragma: nocover
13
+ orjson = None # type: ignore
14
+
15
+ try:
16
+ import ujson
17
+ except ImportError: # pragma: nocover
18
+ ujson = None # type: ignore
19
+
20
+
21
+ class _JsonHandler(ABC):
22
+ @staticmethod
23
+ @abstractmethod
24
+ def dumps(obj: Any) -> str: ...
25
+
26
+ @staticmethod
27
+ @abstractmethod
28
+ def loads(json_string: str | bytes | bytearray) -> Any: ...
29
+
30
+
31
+ class BuiltinHandler(_JsonHandler):
32
+ serializer: type[json.JSONEncoder] | None = None
33
+
34
+ def __init__(self, serializer: type[json.JSONEncoder] | None = None) -> None:
35
+ """Uses the json module from the Python standard library.
36
+
37
+ Args:
38
+ serializer: A custom JSONEncode to handle serializing fields that the build in
39
+ json.dumps cannot handle, for example UUID and datetime. Defaults to None.
40
+ """
41
+ BuiltinHandler.serializer = serializer
42
+
43
+ @staticmethod
44
+ def dumps(obj: Any) -> str:
45
+ return json.dumps(obj, cls=BuiltinHandler.serializer)
46
+
47
+ @staticmethod
48
+ def loads(json_string: str | bytes | bytearray) -> Any:
49
+ return json.loads(json_string)
50
+
51
+
52
+ class OrjsonHandler(_JsonHandler):
53
+ def __init__(self) -> None:
54
+ if orjson is None: # pragma: no cover
55
+ raise ValueError("orjson must be installed to use the OrjsonHandler")
56
+
57
+ @staticmethod
58
+ def dumps(obj: Any) -> str:
59
+ return orjson.dumps(obj).decode("utf-8")
60
+
61
+ @staticmethod
62
+ def loads(json_string: str | bytes | bytearray) -> Any:
63
+ return orjson.loads(json_string)
64
+
65
+
66
+ class UjsonHandler(_JsonHandler):
67
+ def __init__(self) -> None:
68
+ if ujson is None: # pragma: no cover
69
+ raise ValueError("ujson must be installed to use the UjsonHandler")
70
+
71
+ @staticmethod
72
+ def dumps(obj: Any) -> str:
73
+ return ujson.dumps(obj)
74
+
75
+ @staticmethod
76
+ def loads(json_string: str | bytes | bytearray) -> Any:
77
+ return ujson.loads(json_string)
@@ -1,185 +1,85 @@
1
+ from __future__ import annotations
2
+
1
3
  from datetime import datetime
2
- from typing import Dict, List, Optional, Union
3
- from warnings import warn
4
4
 
5
5
  import pydantic
6
6
  from camel_converter.pydantic_base import CamelBase
7
7
 
8
- from meilisearch_python_sdk._utils import is_pydantic_2, iso_to_date_time
8
+ from meilisearch_python_sdk._utils import iso_to_date_time
9
9
  from meilisearch_python_sdk.models.index import IndexStats
10
10
 
11
11
 
12
12
  class ClientStats(CamelBase):
13
13
  database_size: int
14
- last_update: Optional[datetime] = None
15
- indexes: Optional[Dict[str, IndexStats]] = None
16
-
17
- if is_pydantic_2():
18
-
19
- @pydantic.field_validator("last_update", mode="before") # type: ignore[attr-defined]
20
- @classmethod
21
- def validate_last_update(cls, v: str) -> Union[datetime, None]:
22
- return iso_to_date_time(v)
23
-
24
- else: # pragma: no cover
25
- warn(
26
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
27
- DeprecationWarning,
28
- stacklevel=2,
29
- )
14
+ last_update: datetime | None = None
15
+ indexes: dict[str, IndexStats] | None = None
30
16
 
31
- @pydantic.validator("last_update", pre=True)
32
- @classmethod
33
- def validate_last_update(cls, v: str) -> Union[datetime, None]:
34
- return iso_to_date_time(v)
17
+ @pydantic.field_validator("last_update", mode="before") # type: ignore[attr-defined]
18
+ @classmethod
19
+ def validate_last_update(cls, v: str) -> datetime | None:
20
+ return iso_to_date_time(v)
35
21
 
36
22
 
37
23
  class _KeyBase(CamelBase):
38
24
  uid: str
39
- name: Optional[str] = None
25
+ name: str | None = None
40
26
  description: str
41
- actions: List[str]
42
- indexes: List[str]
43
- expires_at: Optional[datetime] = None
44
-
45
- if is_pydantic_2():
46
- model_config = pydantic.ConfigDict(ser_json_timedelta="iso8601") # type: ignore[typeddict-unknown-key]
47
-
48
- @pydantic.field_validator("expires_at", mode="before") # type: ignore[attr-defined]
49
- @classmethod
50
- def validate_expires_at(cls, v: str) -> Union[datetime, None]:
51
- return iso_to_date_time(v)
52
-
53
- else: # pragma: no cover
54
- warn(
55
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
56
- DeprecationWarning,
57
- stacklevel=2,
58
- )
59
-
60
- @pydantic.validator("expires_at", pre=True)
61
- @classmethod
62
- def validate_expires_at(cls, v: str) -> Union[datetime, None]:
63
- return iso_to_date_time(v)
64
-
65
- class Config:
66
- json_encoders = {
67
- datetime: lambda v: None
68
- if not v
69
- else (
70
- f"{str(v).split('+')[0].replace(' ', 'T')}Z"
71
- if "+" in str(v)
72
- else f"{str(v).replace(' ', 'T')}Z"
73
- )
74
- }
27
+ actions: list[str]
28
+ indexes: list[str]
29
+ expires_at: datetime | None = None
30
+
31
+ model_config = pydantic.ConfigDict(ser_json_timedelta="iso8601") # type: ignore[typeddict-unknown-key]
32
+
33
+ @pydantic.field_validator("expires_at", mode="before") # type: ignore[attr-defined]
34
+ @classmethod
35
+ def validate_expires_at(cls, v: str) -> datetime | None:
36
+ return iso_to_date_time(v)
75
37
 
76
38
 
77
39
  class Key(_KeyBase):
78
40
  key: str
79
41
  created_at: datetime
80
- updated_at: Optional[datetime] = None
81
-
82
- if is_pydantic_2():
42
+ updated_at: datetime | None = None
83
43
 
84
- @pydantic.field_validator("created_at", mode="before") # type: ignore[attr-defined]
85
- @classmethod
86
- def validate_created_at(cls, v: str) -> datetime:
87
- converted = iso_to_date_time(v)
44
+ @pydantic.field_validator("created_at", mode="before") # type: ignore[attr-defined]
45
+ @classmethod
46
+ def validate_created_at(cls, v: str) -> datetime:
47
+ converted = iso_to_date_time(v)
88
48
 
89
- if not converted: # pragma: no cover
90
- raise ValueError("created_at is required")
49
+ if not converted: # pragma: no cover
50
+ raise ValueError("created_at is required")
91
51
 
92
- return converted
52
+ return converted
93
53
 
94
- @pydantic.field_validator("updated_at", mode="before") # type: ignore[attr-defined]
95
- @classmethod
96
- def validate_updated_at(cls, v: str) -> Union[datetime, None]:
97
- return iso_to_date_time(v)
98
-
99
- else: # pragma: no cover
100
- warn(
101
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
102
- DeprecationWarning,
103
- stacklevel=2,
104
- )
105
-
106
- @pydantic.validator("created_at", pre=True)
107
- @classmethod
108
- def validate_created_at(cls, v: str) -> datetime:
109
- converted = iso_to_date_time(v)
110
-
111
- if not converted:
112
- raise ValueError("created_at is required")
113
-
114
- return converted
115
-
116
- @pydantic.validator("updated_at", pre=True)
117
- @classmethod
118
- def validate_updated_at(cls, v: str) -> Union[datetime, None]:
119
- return iso_to_date_time(v)
54
+ @pydantic.field_validator("updated_at", mode="before") # type: ignore[attr-defined]
55
+ @classmethod
56
+ def validate_updated_at(cls, v: str) -> datetime | None:
57
+ return iso_to_date_time(v)
120
58
 
121
59
 
122
60
  class KeyCreate(CamelBase):
123
- name: Optional[str] = None
61
+ name: str | None = None
124
62
  description: str
125
- actions: List[str]
126
- indexes: List[str]
127
- expires_at: Optional[datetime] = None
128
-
129
- if is_pydantic_2():
130
- model_config = pydantic.ConfigDict(ser_json_timedelta="iso8601") # type: ignore[typeddict-unknown-key]
131
-
132
- else: # pragma: no cover
133
- warn(
134
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
135
- DeprecationWarning,
136
- stacklevel=2,
137
- )
138
-
139
- class Config:
140
- json_encoders = {
141
- datetime: lambda v: None
142
- if not v
143
- else (
144
- f"{str(v).split('+')[0].replace(' ', 'T')}Z"
145
- if "+" in str(v)
146
- else f"{str(v).replace(' ', 'T')}Z"
147
- )
148
- }
63
+ actions: list[str]
64
+ indexes: list[str]
65
+ expires_at: datetime | None = None
66
+
67
+ model_config = pydantic.ConfigDict(ser_json_timedelta="iso8601") # type: ignore[typeddict-unknown-key]
149
68
 
150
69
 
151
70
  class KeyUpdate(CamelBase):
152
71
  key: str
153
- name: Optional[str] = None
154
- description: Optional[str] = None
155
- actions: Optional[List[str]] = None
156
- indexes: Optional[List[str]] = None
157
- expires_at: Optional[datetime] = None
158
-
159
- if is_pydantic_2():
160
- model_config = pydantic.ConfigDict(ser_json_timedelta="iso8601") # type: ignore[typeddict-unknown-key]
161
-
162
- else: # pragma: no cover
163
- warn(
164
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
165
- DeprecationWarning,
166
- stacklevel=2,
167
- )
168
-
169
- class Config:
170
- json_encoders = {
171
- datetime: lambda v: None
172
- if not v
173
- else (
174
- f"{str(v).split('+')[0].replace(' ', 'T')}Z"
175
- if "+" in str(v)
176
- else f"{str(v).replace(' ', 'T')}Z"
177
- )
178
- }
72
+ name: str | None = None
73
+ description: str | None = None
74
+ actions: list[str] | None = None
75
+ indexes: list[str] | None = None
76
+ expires_at: datetime | None = None
77
+
78
+ model_config = pydantic.ConfigDict(ser_json_timedelta="iso8601") # type: ignore[typeddict-unknown-key]
179
79
 
180
80
 
181
81
  class KeySearch(CamelBase):
182
- results: List[Key]
82
+ results: list[Key]
183
83
  offset: int
184
84
  limit: int
185
85
  total: int
@@ -1,4 +1,4 @@
1
- from typing import List
1
+ from __future__ import annotations
2
2
 
3
3
  from camel_converter.pydantic_base import CamelBase
4
4
 
@@ -6,7 +6,7 @@ from meilisearch_python_sdk.types import JsonDict
6
6
 
7
7
 
8
8
  class DocumentsInfo(CamelBase):
9
- results: List[JsonDict]
9
+ results: list[JsonDict]
10
10
  offset: int
11
11
  limit: int
12
12
  total: int
@@ -1,73 +1,44 @@
1
+ from __future__ import annotations
2
+
1
3
  from datetime import datetime
2
- from typing import Dict, Optional
3
- from warnings import warn
4
4
 
5
5
  import pydantic
6
6
  from camel_converter.pydantic_base import CamelBase
7
7
 
8
- from meilisearch_python_sdk._utils import is_pydantic_2, iso_to_date_time
8
+ from meilisearch_python_sdk._utils import iso_to_date_time
9
9
 
10
10
 
11
11
  class IndexBase(CamelBase):
12
12
  uid: str
13
- primary_key: Optional[str] = None
13
+ primary_key: str | None = None
14
14
 
15
15
 
16
16
  class IndexInfo(IndexBase):
17
17
  created_at: datetime
18
18
  updated_at: datetime
19
19
 
20
- if is_pydantic_2():
21
-
22
- @pydantic.field_validator("created_at", mode="before") # type: ignore[attr-defined]
23
- @classmethod
24
- def validate_created_at(cls, v: str) -> datetime:
25
- converted = iso_to_date_time(v)
26
-
27
- if not converted: # pragma: no cover
28
- raise ValueError("created_at is required")
29
-
30
- return converted
31
-
32
- @pydantic.field_validator("updated_at", mode="before") # type: ignore[attr-defined]
33
- @classmethod
34
- def validate_updated_at(cls, v: str) -> datetime:
35
- converted = iso_to_date_time(v)
36
-
37
- if not converted: # pragma: no cover
38
- raise ValueError("updated_at is required")
39
-
40
- return converted
41
-
42
- else: # pragma: no cover
43
- warn(
44
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
45
- DeprecationWarning,
46
- stacklevel=2,
47
- )
48
-
49
- @pydantic.validator("created_at", pre=True)
50
- @classmethod
51
- def validate_created_at(cls, v: str) -> datetime:
52
- converted = iso_to_date_time(v)
20
+ @pydantic.field_validator("created_at", mode="before") # type: ignore[attr-defined]
21
+ @classmethod
22
+ def validate_created_at(cls, v: str) -> datetime:
23
+ converted = iso_to_date_time(v)
53
24
 
54
- if not converted:
55
- raise ValueError("created_at is required")
25
+ if not converted: # pragma: no cover
26
+ raise ValueError("created_at is required")
56
27
 
57
- return converted
28
+ return converted
58
29
 
59
- @pydantic.validator("updated_at", pre=True)
60
- @classmethod
61
- def validate_updated_at(cls, v: str) -> datetime:
62
- converted = iso_to_date_time(v)
30
+ @pydantic.field_validator("updated_at", mode="before") # type: ignore[attr-defined]
31
+ @classmethod
32
+ def validate_updated_at(cls, v: str) -> datetime:
33
+ converted = iso_to_date_time(v)
63
34
 
64
- if not converted:
65
- raise ValueError("updated_at is required")
35
+ if not converted: # pragma: no cover
36
+ raise ValueError("updated_at is required")
66
37
 
67
- return converted
38
+ return converted
68
39
 
69
40
 
70
41
  class IndexStats(CamelBase):
71
42
  number_of_documents: int
72
43
  is_indexing: bool
73
- field_distribution: Dict[str, int]
44
+ field_distribution: dict[str, int]
@@ -1,10 +1,8 @@
1
- from typing import List, Optional
2
- from warnings import warn
1
+ from __future__ import annotations
3
2
 
4
3
  import pydantic
5
4
  from camel_converter.pydantic_base import CamelBase
6
5
 
7
- from meilisearch_python_sdk._utils import is_pydantic_2
8
6
  from meilisearch_python_sdk.errors import MeilisearchError
9
7
  from meilisearch_python_sdk.types import Filter, JsonDict
10
8
 
@@ -15,81 +13,64 @@ class FacetHits(CamelBase):
15
13
 
16
14
 
17
15
  class FacetSearchResults(CamelBase):
18
- facet_hits: List[FacetHits]
16
+ facet_hits: list[FacetHits]
19
17
  facet_query: str
20
18
  processing_time_ms: int
21
19
 
22
20
 
23
21
  class Hybrid(CamelBase):
24
22
  semantic_ratio: float
25
- embedder: Optional[str] = None
23
+ embedder: str | None = None
26
24
 
27
25
 
28
26
  class SearchParams(CamelBase):
29
27
  index_uid: str
30
- query: Optional[str] = pydantic.Field(None, alias="q")
28
+ query: str | None = pydantic.Field(None, alias="q")
31
29
  offset: int = 0
32
30
  limit: int = 20
33
- filter: Optional[Filter] = None
34
- facets: Optional[List[str]] = None
35
- attributes_to_retrieve: List[str] = ["*"]
36
- attributes_to_crop: Optional[List[str]] = None
31
+ filter: Filter | None = None
32
+ facets: list[str] | None = None
33
+ attributes_to_retrieve: list[str] = ["*"]
34
+ attributes_to_crop: list[str] | None = None
37
35
  crop_length: int = 200
38
- attributes_to_highlight: Optional[List[str]] = None
39
- sort: Optional[List[str]] = None
36
+ attributes_to_highlight: list[str] | None = None
37
+ sort: list[str] | None = None
40
38
  show_matches_position: bool = False
41
39
  highlight_pre_tag: str = "<em>"
42
40
  highlight_post_tag: str = "</em>"
43
41
  crop_marker: str = "..."
44
42
  matching_strategy: str = "all"
45
- hits_per_page: Optional[int] = None
46
- page: Optional[int] = None
47
- attributes_to_search_on: Optional[List[str]] = None
43
+ hits_per_page: int | None = None
44
+ page: int | None = None
45
+ attributes_to_search_on: list[str] | None = None
48
46
  show_ranking_score: bool = False
49
47
  show_ranking_score_details: bool = False
50
- ranking_score_threshold: Optional[float] = None
51
- vector: Optional[List[float]] = None
52
- hybrid: Optional[Hybrid] = None
48
+ ranking_score_threshold: float | None = None
49
+ vector: list[float] | None = None
50
+ hybrid: Hybrid | None = None
53
51
 
54
- if is_pydantic_2():
52
+ @pydantic.field_validator("ranking_score_threshold", mode="before") # type: ignore[attr-defined]
53
+ @classmethod
54
+ def validate_ranking_score_threshold(cls, v: float | None) -> float | None:
55
+ if v and not 0.0 <= v <= 1.0:
56
+ raise MeilisearchError("ranking_score_threshold must be between 0.0 and 1.0")
55
57
 
56
- @pydantic.field_validator("ranking_score_threshold", mode="before") # type: ignore[attr-defined]
57
- @classmethod
58
- def validate_ranking_score_threshold(cls, v: Optional[float]) -> Optional[float]:
59
- if v and not 0.0 <= v <= 1.0:
60
- raise MeilisearchError("ranking_score_threshold must be between 0.0 and 1.0")
61
-
62
- return v
63
-
64
- else: # pragma: no cover
65
- warn(
66
- "The use of Pydantic less than version 2 is depreciated and will be removed in a future release",
67
- DeprecationWarning,
68
- stacklevel=2,
69
- )
70
-
71
- @pydantic.validator("ranking_score_threshold", pre=True)
72
- @classmethod
73
- def validate_expires_at(cls, v: Optional[float]) -> Optional[float]:
74
- if v and not 0.0 <= v <= 1.0:
75
- raise MeilisearchError("ranking_score_threshold must be between 0.0 and 1.0")
76
-
77
- return v
58
+ return v
78
59
 
79
60
 
80
61
  class SearchResults(CamelBase):
81
- hits: List[JsonDict]
82
- offset: Optional[int] = None
83
- limit: Optional[int] = None
84
- estimated_total_hits: Optional[int] = None
62
+ hits: list[JsonDict]
63
+ offset: int | None = None
64
+ limit: int | None = None
65
+ estimated_total_hits: int | None = None
85
66
  processing_time_ms: int
86
67
  query: str
87
- facet_distribution: Optional[JsonDict] = None
88
- total_pages: Optional[int] = None
89
- total_hits: Optional[int] = None
90
- page: Optional[int] = None
91
- hits_per_page: Optional[int] = None
92
- semantic_hit_count: Optional[int] = None
68
+ facet_distribution: JsonDict | None = None
69
+ total_pages: int | None = None
70
+ total_hits: int | None = None
71
+ page: int | None = None
72
+ hits_per_page: int | None = None
73
+ semantic_hit_count: int | None = None
93
74
 
94
75
 
95
76
  class SearchResultsWithUID(SearchResults):
@@ -97,9 +78,9 @@ class SearchResultsWithUID(SearchResults):
97
78
 
98
79
 
99
80
  class SimilarSearchResults(CamelBase):
100
- hits: List[JsonDict]
81
+ hits: list[JsonDict]
101
82
  id: str
102
83
  processing_time_ms: int
103
- limit: Optional[int] = None
104
- offset: Optional[int] = None
105
- estimated_total_hits: Optional[int] = None
84
+ limit: int | None = None
85
+ offset: int | None = None
86
+ estimated_total_hits: int | None = None