66import hmac
77import json
88import re
9- from typing import Any
9+ from typing import Any , Dict , List , Optional , Union
1010from urllib import parse
1111
1212from meilisearch ._httprequests import HttpRequests
@@ -25,7 +25,9 @@ class Client:
2525 Meilisearch and its permissions.
2626 """
2727
28- def __init__ (self , url : str , api_key : str | None = None , timeout : int | None = None ) -> None :
28+ def __init__ (
29+ self , url : str , api_key : Optional [str ] = None , timeout : Optional [int ] = None
30+ ) -> None :
2931 """
3032 Parameters
3133 ----------
@@ -38,7 +40,7 @@ def __init__(self, url: str, api_key: str | None = None, timeout: int | None = N
3840
3941 self .http = HttpRequests (self .config )
4042
41- def create_index (self , uid : str , options : dict [ str , Any ] | None = None ) -> dict [str , Any ]:
43+ def create_index (self , uid : str , options : Optional [ Dict [ str , Any ]] = None ) -> Dict [str , Any ]:
4244 """Create an index.
4345
4446 Parameters
@@ -61,7 +63,7 @@ def create_index(self, uid: str, options: dict[str, Any] | None = None) -> dict[
6163 """
6264 return Index .create (self .config , uid , options )
6365
64- def delete_index (self , uid : str ) -> dict [str , Any ]:
66+ def delete_index (self , uid : str ) -> Dict [str , Any ]:
6567 """Deletes an index
6668
6769 Parameters
@@ -83,7 +85,7 @@ def delete_index(self, uid: str) -> dict[str, Any]:
8385
8486 return self .http .delete (f"{ self .config .paths .index } /{ uid } " )
8587
86- def get_indexes (self , parameters : dict [ str , Any ] | None = None ) -> dict [str , list [Index ]]:
88+ def get_indexes (self , parameters : Optional [ Dict [ str , Any ]] = None ) -> Dict [str , List [Index ]]:
8789 """Get all indexes.
8890
8991 Parameters
@@ -116,7 +118,7 @@ def get_indexes(self, parameters: dict[str, Any] | None = None) -> dict[str, lis
116118 ]
117119 return response
118120
119- def get_raw_indexes (self , parameters : dict [ str , Any ] | None = None ) -> list [ dict [str , Any ]]:
121+ def get_raw_indexes (self , parameters : Optional [ Dict [ str , Any ]] = None ) -> List [ Dict [str , Any ]]:
120122 """Get all indexes in dictionary format.
121123
122124 Parameters
@@ -159,7 +161,7 @@ def get_index(self, uid: str) -> Index:
159161 """
160162 return Index (self .config , uid ).fetch_info ()
161163
162- def get_raw_index (self , uid : str ) -> dict [str , Any ]:
164+ def get_raw_index (self , uid : str ) -> Dict [str , Any ]:
163165 """Get the index as a dictionary.
164166 This index should already exist.
165167
@@ -198,7 +200,7 @@ def index(self, uid: str) -> Index:
198200 return Index (self .config , uid = uid )
199201 raise Exception ("The index UID should not be None" )
200202
201- def get_all_stats (self ) -> dict [str , Any ]:
203+ def get_all_stats (self ) -> Dict [str , Any ]:
202204 """Get all stats of Meilisearch
203205
204206 Get information about database size and all indexes
@@ -216,7 +218,7 @@ def get_all_stats(self) -> dict[str, Any]:
216218 """
217219 return self .http .get (self .config .paths .stat )
218220
219- def health (self ) -> dict [str , str ]:
221+ def health (self ) -> Dict [str , str ]:
220222 """Get health of the Meilisearch server.
221223
222224 Returns
@@ -239,7 +241,7 @@ def is_healthy(self) -> bool:
239241 return False
240242 return True
241243
242- def get_key (self , key_or_uid : str ) -> dict [str , Any ]:
244+ def get_key (self , key_or_uid : str ) -> Dict [str , Any ]:
243245 """Gets information about a specific API key.
244246
245247 Parameters
@@ -260,7 +262,7 @@ def get_key(self, key_or_uid: str) -> dict[str, Any]:
260262 """
261263 return self .http .get (f"{ self .config .paths .keys } /{ key_or_uid } " )
262264
263- def get_keys (self , parameters : dict [ str , Any ] | None = None ) -> dict [str , Any ]:
265+ def get_keys (self , parameters : Optional [ Dict [ str , Any ]] = None ) -> Dict [str , Any ]:
264266 """Gets the Meilisearch API keys.
265267
266268 Parameters
@@ -283,7 +285,7 @@ def get_keys(self, parameters: dict[str, Any] | None = None) -> dict[str, Any]:
283285 parameters = {}
284286 return self .http .get (f"{ self .config .paths .keys } ?{ parse .urlencode (parameters )} " )
285287
286- def create_key (self , options : dict [str , Any ]) -> dict [str , Any ]:
288+ def create_key (self , options : Dict [str , Any ]) -> Dict [str , Any ]:
287289 """Creates a new API key.
288290
289291 Parameters
@@ -308,7 +310,7 @@ def create_key(self, options: dict[str, Any]) -> dict[str, Any]:
308310 """
309311 return self .http .post (f"{ self .config .paths .keys } " , options )
310312
311- def update_key (self , key_or_uid : str , options : dict [str , Any ]) -> dict [str , Any ]:
313+ def update_key (self , key_or_uid : str , options : Dict [str , Any ]) -> Dict [str , Any ]:
312314 """Update an API key.
313315
314316 Parameters
@@ -333,7 +335,7 @@ def update_key(self, key_or_uid: str, options: dict[str, Any]) -> dict[str, Any]
333335 url = f"{ self .config .paths .keys } /{ key_or_uid } "
334336 return self .http .patch (url , options )
335337
336- def delete_key (self , key_or_uid : str ) -> dict [str , int ]:
338+ def delete_key (self , key_or_uid : str ) -> Dict [str , int ]:
337339 """Deletes an API key.
338340
339341 Parameters
@@ -354,7 +356,7 @@ def delete_key(self, key_or_uid: str) -> dict[str, int]:
354356 """
355357 return self .http .delete (f"{ self .config .paths .keys } /{ key_or_uid } " )
356358
357- def get_version (self ) -> dict [str , str ]:
359+ def get_version (self ) -> Dict [str , str ]:
358360 """Get version Meilisearch
359361
360362 Returns
@@ -369,7 +371,7 @@ def get_version(self) -> dict[str, str]:
369371 """
370372 return self .http .get (self .config .paths .version )
371373
372- def version (self ) -> dict [str , str ]:
374+ def version (self ) -> Dict [str , str ]:
373375 """Alias for get_version
374376
375377 Returns
@@ -384,7 +386,7 @@ def version(self) -> dict[str, str]:
384386 """
385387 return self .get_version ()
386388
387- def create_dump (self ) -> dict [str , str ]:
389+ def create_dump (self ) -> Dict [str , str ]:
388390 """Trigger the creation of a Meilisearch dump.
389391
390392 Returns
@@ -400,7 +402,7 @@ def create_dump(self) -> dict[str, str]:
400402 """
401403 return self .http .post (self .config .paths .dumps )
402404
403- def swap_indexes (self , parameters : list [ dict [str , list [str ]]]) -> TaskInfo :
405+ def swap_indexes (self , parameters : List [ Dict [str , List [str ]]]) -> TaskInfo :
404406 """Swap two indexes.
405407
406408 Parameters
@@ -422,8 +424,8 @@ def swap_indexes(self, parameters: list[dict[str, list[str]]]) -> TaskInfo:
422424 return TaskInfo (** self .http .post (self .config .paths .swap , parameters ))
423425
424426 def get_tasks (
425- self , parameters : dict [ str , Any ] | None = None
426- ) -> dict [str , list [ dict [str , Any ]]]:
427+ self , parameters : Optional [ Dict [ str , Any ]] = None
428+ ) -> Dict [str , List [ Dict [str , Any ]]]:
427429 """Get all tasks.
428430
429431 Parameters
@@ -443,7 +445,7 @@ def get_tasks(
443445 """
444446 return get_tasks (self .config , parameters = parameters )
445447
446- def get_task (self , uid : int ) -> dict [str , Any ]:
448+ def get_task (self , uid : int ) -> Dict [str , Any ]:
447449 """Get one task.
448450
449451 Parameters
@@ -463,7 +465,7 @@ def get_task(self, uid: int) -> dict[str, Any]:
463465 """
464466 return get_task (self .config , uid )
465467
466- def cancel_tasks (self , parameters : dict [str , Any ]) -> TaskInfo :
468+ def cancel_tasks (self , parameters : Dict [str , Any ]) -> TaskInfo :
467469 """Cancel a list of enqueued or processing tasks.
468470
469471 Parameters
@@ -484,7 +486,7 @@ def cancel_tasks(self, parameters: dict[str, Any]) -> TaskInfo:
484486 """
485487 return cancel_tasks (self .config , parameters = parameters )
486488
487- def delete_tasks (self , parameters : dict [str , Any ]) -> TaskInfo :
489+ def delete_tasks (self , parameters : Dict [str , Any ]) -> TaskInfo :
488490 """Delete a list of finished tasks.
489491
490492 Parameters
@@ -508,7 +510,7 @@ def wait_for_task(
508510 uid : int ,
509511 timeout_in_ms : int = 5000 ,
510512 interval_in_ms : int = 50 ,
511- ) -> dict [str , Any ]:
513+ ) -> Dict [str , Any ]:
512514 """Wait until Meilisearch processes a task until it fails or succeeds.
513515
514516 Parameters
@@ -535,10 +537,10 @@ def wait_for_task(
535537 def generate_tenant_token (
536538 self ,
537539 api_key_uid : str ,
538- search_rules : dict [ str , Any ] | list [str ],
540+ search_rules : Union [ Dict [ str , Any ], List [str ] ],
539541 * ,
540- expires_at : datetime .datetime | None = None ,
541- api_key : str | None = None ,
542+ expires_at : Optional [ datetime .datetime ] = None ,
543+ api_key : Optional [ str ] = None ,
542544 ) -> str :
543545 """Generate a JWT token for the use of multitenancy.
544546
0 commit comments