1
- import re
1
+ from __future__ import annotations
2
+
2
3
import base64
4
+ import datetime
3
5
import hashlib
4
6
import hmac
5
7
import json
6
- import datetime
8
+ import re
9
+ from typing import Any
7
10
from urllib import parse
8
- from typing import Any , Dict , List , Optional , Union
9
- from meilisearch .index import Index
10
- from meilisearch .config import Config
11
- from meilisearch .task import get_task , get_tasks , wait_for_task
11
+
12
12
from meilisearch ._httprequests import HttpRequests
13
+ from meilisearch .config import Config
13
14
from meilisearch .errors import MeiliSearchError
15
+ from meilisearch .index import Index
16
+ from meilisearch .task import get_task , get_tasks , wait_for_task
17
+
14
18
15
19
class Client ():
16
20
"""
@@ -21,7 +25,7 @@ class Client():
21
25
"""
22
26
23
27
def __init__ (
24
- self , url : str , api_key : Optional [ str ] = None , timeout : Optional [ int ] = None
28
+ self , url : str , api_key : str | None = None , timeout : int | None = None
25
29
) -> None :
26
30
"""
27
31
Parameters
@@ -35,7 +39,7 @@ def __init__(
35
39
36
40
self .http = HttpRequests (self .config )
37
41
38
- def create_index (self , uid : str , options : Optional [ Dict [ str , Any ]] = None ) -> Dict [str , Any ]:
42
+ def create_index (self , uid : str , options : dict [ str , Any ] | None = None ) -> dict [str , Any ]:
39
43
"""Create an index.
40
44
41
45
Parameters
@@ -58,7 +62,7 @@ def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> Di
58
62
"""
59
63
return Index .create (self .config , uid , options )
60
64
61
- def delete_index (self , uid : str ) -> Dict [str , Any ]:
65
+ def delete_index (self , uid : str ) -> dict [str , Any ]:
62
66
"""Deletes an index
63
67
64
68
Parameters
@@ -80,7 +84,7 @@ def delete_index(self, uid: str) -> Dict[str, Any]:
80
84
81
85
return self .http .delete (f'{ self .config .paths .index } /{ uid } ' )
82
86
83
- def get_indexes (self , parameters : Optional [ Dict [ str , Any ]] = None ) -> Dict [str , List [Index ]]:
87
+ def get_indexes (self , parameters : dict [ str , Any ] | None = None ) -> dict [str , list [Index ]]:
84
88
"""Get all indexes.
85
89
86
90
Parameters
@@ -115,7 +119,7 @@ def get_indexes(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str,
115
119
]
116
120
return response
117
121
118
- def get_raw_indexes (self , parameters : Optional [ Dict [ str , Any ]] = None ) -> List [ Dict [str , Any ]]:
122
+ def get_raw_indexes (self , parameters : dict [ str , Any ] | None = None ) -> list [ dict [str , Any ]]:
119
123
"""Get all indexes in dictionary format.
120
124
121
125
Parameters
@@ -160,7 +164,7 @@ def get_index(self, uid: str) -> Index:
160
164
"""
161
165
return Index (self .config , uid ).fetch_info ()
162
166
163
- def get_raw_index (self , uid : str ) -> Dict [str , Any ]:
167
+ def get_raw_index (self , uid : str ) -> dict [str , Any ]:
164
168
"""Get the index as a dictionary.
165
169
This index should already exist.
166
170
@@ -199,7 +203,7 @@ def index(self, uid: str) -> Index:
199
203
return Index (self .config , uid = uid )
200
204
raise Exception ('The index UID should not be None' )
201
205
202
- def get_all_stats (self ) -> Dict [str , Any ]:
206
+ def get_all_stats (self ) -> dict [str , Any ]:
203
207
"""Get all stats of Meilisearch
204
208
205
209
Get information about database size and all indexes
@@ -217,7 +221,7 @@ def get_all_stats(self) -> Dict[str, Any]:
217
221
"""
218
222
return self .http .get (self .config .paths .stat )
219
223
220
- def health (self ) -> Dict [str , str ]:
224
+ def health (self ) -> dict [str , str ]:
221
225
"""Get health of the Meilisearch server.
222
226
223
227
Returns
@@ -241,7 +245,7 @@ def is_healthy(self) -> bool:
241
245
return False
242
246
return True
243
247
244
- def get_key (self , key_or_uid : str ) -> Dict [str , Any ]:
248
+ def get_key (self , key_or_uid : str ) -> dict [str , Any ]:
245
249
"""Gets information about a specific API key.
246
250
247
251
Parameters
@@ -262,7 +266,7 @@ def get_key(self, key_or_uid: str) -> Dict[str, Any]:
262
266
"""
263
267
return self .http .get (f'{ self .config .paths .keys } /{ key_or_uid } ' )
264
268
265
- def get_keys (self , parameters : Optional [ Dict [ str , Any ]] = None ) -> Dict [str , Any ]:
269
+ def get_keys (self , parameters : dict [ str , Any ] | None = None ) -> dict [str , Any ]:
266
270
"""Gets the Meilisearch API keys.
267
271
268
272
Parameters
@@ -289,8 +293,8 @@ def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any
289
293
290
294
def create_key (
291
295
self ,
292
- options : Dict [str , Any ]
293
- ) -> Dict [str , Any ]:
296
+ options : dict [str , Any ]
297
+ ) -> dict [str , Any ]:
294
298
"""Creates a new API key.
295
299
296
300
Parameters
@@ -318,8 +322,8 @@ def create_key(
318
322
def update_key (
319
323
self ,
320
324
key_or_uid : str ,
321
- options : Dict [str , Any ]
322
- ) -> Dict [str , Any ]:
325
+ options : dict [str , Any ]
326
+ ) -> dict [str , Any ]:
323
327
"""Update an API key.
324
328
325
329
Parameters
@@ -345,7 +349,7 @@ def update_key(
345
349
url = f'{ self .config .paths .keys } /{ key_or_uid } '
346
350
return self .http .patch (url , options )
347
351
348
- def delete_key (self , key_or_uid : str ) -> Dict [str , int ]:
352
+ def delete_key (self , key_or_uid : str ) -> dict [str , int ]:
349
353
"""Deletes an API key.
350
354
351
355
Parameters
@@ -366,7 +370,7 @@ def delete_key(self, key_or_uid: str) -> Dict[str, int]:
366
370
"""
367
371
return self .http .delete (f'{ self .config .paths .keys } /{ key_or_uid } ' )
368
372
369
- def get_version (self ) -> Dict [str , str ]:
373
+ def get_version (self ) -> dict [str , str ]:
370
374
"""Get version Meilisearch
371
375
372
376
Returns
@@ -381,7 +385,7 @@ def get_version(self) -> Dict[str, str]:
381
385
"""
382
386
return self .http .get (self .config .paths .version )
383
387
384
- def version (self ) -> Dict [str , str ]:
388
+ def version (self ) -> dict [str , str ]:
385
389
"""Alias for get_version
386
390
387
391
Returns
@@ -396,7 +400,7 @@ def version(self) -> Dict[str, str]:
396
400
"""
397
401
return self .get_version ()
398
402
399
- def create_dump (self ) -> Dict [str , str ]:
403
+ def create_dump (self ) -> dict [str , str ]:
400
404
"""Trigger the creation of a Meilisearch dump.
401
405
402
406
Returns
@@ -412,7 +416,7 @@ def create_dump(self) -> Dict[str, str]:
412
416
"""
413
417
return self .http .post (self .config .paths .dumps )
414
418
415
- def get_tasks (self , parameters : Optional [ Dict [ str , Any ]] = None ) -> Dict [str , List [ Dict [str , Any ]]]:
419
+ def get_tasks (self , parameters : dict [ str , Any ] | None = None ) -> dict [str , list [ dict [str , Any ]]]:
416
420
"""Get all tasks.
417
421
418
422
Parameters
@@ -433,7 +437,7 @@ def get_tasks(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Li
433
437
"""
434
438
return get_tasks (self .config , parameters = parameters )
435
439
436
- def get_task (self , uid : int ) -> Dict [str , Any ]:
440
+ def get_task (self , uid : int ) -> dict [str , Any ]:
437
441
"""Get one task.
438
442
439
443
Parameters
@@ -457,7 +461,7 @@ def wait_for_task(
457
461
self , uid : int ,
458
462
timeout_in_ms : int = 5000 ,
459
463
interval_in_ms : int = 50 ,
460
- ) -> Dict [str , Any ]:
464
+ ) -> dict [str , Any ]:
461
465
"""Wait until Meilisearch processes a task until it fails or succeeds.
462
466
463
467
Parameters
@@ -484,10 +488,10 @@ def wait_for_task(
484
488
def generate_tenant_token (
485
489
self ,
486
490
api_key_uid : str ,
487
- search_rules : Union [ Dict [ str , Any ], List [str ] ],
491
+ search_rules : dict [ str , Any ] | list [str ],
488
492
* ,
489
- expires_at : Optional [ datetime .datetime ] = None ,
490
- api_key : Optional [ str ] = None
493
+ expires_at : datetime .datetime | None = None ,
494
+ api_key : str | None = None
491
495
) -> str :
492
496
"""Generate a JWT token for the use of multitenancy.
493
497
0 commit comments