1- import re
1+ from __future__ import annotations
2+
23import base64
4+ import datetime
35import hashlib
46import hmac
57import json
6- import datetime
8+ import re
9+ from typing import Any
710from 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+
1212from meilisearch ._httprequests import HttpRequests
13+ from meilisearch .config import Config
1314from meilisearch .errors import MeiliSearchError
15+ from meilisearch .index import Index
16+ from meilisearch .task import get_task , get_tasks , wait_for_task
17+
1418
1519class Client ():
1620 """
@@ -21,7 +25,7 @@ class Client():
2125 """
2226
2327 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
2529 ) -> None :
2630 """
2731 Parameters
@@ -35,7 +39,7 @@ def __init__(
3539
3640 self .http = HttpRequests (self .config )
3741
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 ]:
3943 """Create an index.
4044
4145 Parameters
@@ -58,7 +62,7 @@ def create_index(self, uid: str, options: Optional[Dict[str, Any]] = None) -> Di
5862 """
5963 return Index .create (self .config , uid , options )
6064
61- def delete_index (self , uid : str ) -> Dict [str , Any ]:
65+ def delete_index (self , uid : str ) -> dict [str , Any ]:
6266 """Deletes an index
6367
6468 Parameters
@@ -80,7 +84,7 @@ def delete_index(self, uid: str) -> Dict[str, Any]:
8084
8185 return self .http .delete (f'{ self .config .paths .index } /{ uid } ' )
8286
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 ]]:
8488 """Get all indexes.
8589
8690 Parameters
@@ -115,7 +119,7 @@ def get_indexes(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str,
115119 ]
116120 return response
117121
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 ]]:
119123 """Get all indexes in dictionary format.
120124
121125 Parameters
@@ -160,7 +164,7 @@ def get_index(self, uid: str) -> Index:
160164 """
161165 return Index (self .config , uid ).fetch_info ()
162166
163- def get_raw_index (self , uid : str ) -> Dict [str , Any ]:
167+ def get_raw_index (self , uid : str ) -> dict [str , Any ]:
164168 """Get the index as a dictionary.
165169 This index should already exist.
166170
@@ -199,7 +203,7 @@ def index(self, uid: str) -> Index:
199203 return Index (self .config , uid = uid )
200204 raise Exception ('The index UID should not be None' )
201205
202- def get_all_stats (self ) -> Dict [str , Any ]:
206+ def get_all_stats (self ) -> dict [str , Any ]:
203207 """Get all stats of Meilisearch
204208
205209 Get information about database size and all indexes
@@ -217,7 +221,7 @@ def get_all_stats(self) -> Dict[str, Any]:
217221 """
218222 return self .http .get (self .config .paths .stat )
219223
220- def health (self ) -> Dict [str , str ]:
224+ def health (self ) -> dict [str , str ]:
221225 """Get health of the Meilisearch server.
222226
223227 Returns
@@ -241,7 +245,7 @@ def is_healthy(self) -> bool:
241245 return False
242246 return True
243247
244- def get_key (self , key_or_uid : str ) -> Dict [str , Any ]:
248+ def get_key (self , key_or_uid : str ) -> dict [str , Any ]:
245249 """Gets information about a specific API key.
246250
247251 Parameters
@@ -262,7 +266,7 @@ def get_key(self, key_or_uid: str) -> Dict[str, Any]:
262266 """
263267 return self .http .get (f'{ self .config .paths .keys } /{ key_or_uid } ' )
264268
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 ]:
266270 """Gets the Meilisearch API keys.
267271
268272 Parameters
@@ -289,8 +293,8 @@ def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any
289293
290294 def create_key (
291295 self ,
292- options : Dict [str , Any ]
293- ) -> Dict [str , Any ]:
296+ options : dict [str , Any ]
297+ ) -> dict [str , Any ]:
294298 """Creates a new API key.
295299
296300 Parameters
@@ -318,8 +322,8 @@ def create_key(
318322 def update_key (
319323 self ,
320324 key_or_uid : str ,
321- options : Dict [str , Any ]
322- ) -> Dict [str , Any ]:
325+ options : dict [str , Any ]
326+ ) -> dict [str , Any ]:
323327 """Update an API key.
324328
325329 Parameters
@@ -345,7 +349,7 @@ def update_key(
345349 url = f'{ self .config .paths .keys } /{ key_or_uid } '
346350 return self .http .patch (url , options )
347351
348- def delete_key (self , key_or_uid : str ) -> Dict [str , int ]:
352+ def delete_key (self , key_or_uid : str ) -> dict [str , int ]:
349353 """Deletes an API key.
350354
351355 Parameters
@@ -366,7 +370,7 @@ def delete_key(self, key_or_uid: str) -> Dict[str, int]:
366370 """
367371 return self .http .delete (f'{ self .config .paths .keys } /{ key_or_uid } ' )
368372
369- def get_version (self ) -> Dict [str , str ]:
373+ def get_version (self ) -> dict [str , str ]:
370374 """Get version Meilisearch
371375
372376 Returns
@@ -381,7 +385,7 @@ def get_version(self) -> Dict[str, str]:
381385 """
382386 return self .http .get (self .config .paths .version )
383387
384- def version (self ) -> Dict [str , str ]:
388+ def version (self ) -> dict [str , str ]:
385389 """Alias for get_version
386390
387391 Returns
@@ -396,7 +400,7 @@ def version(self) -> Dict[str, str]:
396400 """
397401 return self .get_version ()
398402
399- def create_dump (self ) -> Dict [str , str ]:
403+ def create_dump (self ) -> dict [str , str ]:
400404 """Trigger the creation of a Meilisearch dump.
401405
402406 Returns
@@ -412,7 +416,7 @@ def create_dump(self) -> Dict[str, str]:
412416 """
413417 return self .http .post (self .config .paths .dumps )
414418
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 ]]]:
416420 """Get all tasks.
417421
418422 Parameters
@@ -433,7 +437,7 @@ def get_tasks(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Li
433437 """
434438 return get_tasks (self .config , parameters = parameters )
435439
436- def get_task (self , uid : int ) -> Dict [str , Any ]:
440+ def get_task (self , uid : int ) -> dict [str , Any ]:
437441 """Get one task.
438442
439443 Parameters
@@ -457,7 +461,7 @@ def wait_for_task(
457461 self , uid : int ,
458462 timeout_in_ms : int = 5000 ,
459463 interval_in_ms : int = 50 ,
460- ) -> Dict [str , Any ]:
464+ ) -> dict [str , Any ]:
461465 """Wait until Meilisearch processes a task until it fails or succeeds.
462466
463467 Parameters
@@ -484,10 +488,10 @@ def wait_for_task(
484488 def generate_tenant_token (
485489 self ,
486490 api_key_uid : str ,
487- search_rules : Union [ Dict [ str , Any ], List [str ] ],
491+ search_rules : dict [ str , Any ] | list [str ],
488492 * ,
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
491495 ) -> str :
492496 """Generate a JWT token for the use of multitenancy.
493497
0 commit comments