11from __future__ import annotations
22
3- from asyncio import get_running_loop
4- from functools import partial
53from types import TracebackType
64from typing import Optional , Type
75
119from async_search_client .errors import MeiliSearchApiError
1210from async_search_client .index import Index
1311from async_search_client .models import ClientStats , DumpInfo , Health , IndexInfo , Keys , Version
14- from async_search_client .paths import Paths , build_url
1512
1613
1714class Client :
@@ -40,18 +37,15 @@ async def aclose(self) -> None:
4037 await self ._http_client .aclose ()
4138
4239 async def create_dump (self ) -> DumpInfo :
43- response = await self ._http_requests .post (build_url ( Paths . DUMPS ) )
40+ response = await self ._http_requests .post ("dumps" )
4441 return DumpInfo (** response .json ())
4542
4643 async def create_index (self , uid : str , primary_key : Optional [str ] = None ) -> Index :
4744 return await Index .create (self ._http_client , uid , primary_key )
4845
4946 async def delete_index_if_exists (self , uid : str ) -> bool :
5047 try :
51- loop = get_running_loop ()
52- url = await loop .run_in_executor (
53- None , partial (build_url , section = Paths .INDEXES , uid = uid )
54- )
48+ url = f"indexes/{ uid } "
5549 await self ._http_requests .delete (url )
5650 return True
5751 except MeiliSearchApiError as error :
@@ -60,7 +54,7 @@ async def delete_index_if_exists(self, uid: str) -> bool:
6054 return False
6155
6256 async def get_indexes (self ) -> Optional [list [Index ]]:
63- response = await self ._http_requests .get (build_url ( Paths . INDEXES ) )
57+ response = await self ._http_requests .get ("indexes" )
6458
6559 if not response .json ():
6660 return None
@@ -87,11 +81,11 @@ def index(self, uid: str) -> Index:
8781 return Index (self ._http_client , uid = uid )
8882
8983 async def get_all_stats (self ) -> ClientStats :
90- response = await self ._http_requests .get (build_url ( Paths . STATS ) )
84+ response = await self ._http_requests .get ("stats" )
9185 return ClientStats (** response .json ())
9286
9387 async def get_dump_status (self , uid : str ) -> DumpInfo :
94- url = build_url ( Paths . DUMPS , uid , " status")
88+ url = f"dumps/ { uid } / status"
9589 response = await self ._http_requests .get (url )
9690 return DumpInfo (** response .json ())
9791
@@ -105,19 +99,19 @@ async def get_or_create_index(self, uid: str, primary_key: Optional[str] = None)
10599 return index_instance
106100
107101 async def get_keys (self ) -> Keys :
108- response = await self ._http_requests .get (build_url ( Paths . KEYS ) )
102+ response = await self ._http_requests .get ("keys" )
109103 return Keys (** response .json ())
110104
111105 async def get_raw_index (self , uid : str ) -> Optional [IndexInfo ]:
112- response = await self ._http_client .get (build_url ( Paths . INDEXES , uid ) )
106+ response = await self ._http_client .get (f"indexes/ { uid } " )
113107
114108 if response .status_code == 404 :
115109 return None
116110
117111 return IndexInfo (** response .json ())
118112
119113 async def get_raw_indexes (self ) -> Optional [list [IndexInfo ]]:
120- response = await self ._http_requests .get (build_url ( Paths . INDEXES ) )
114+ response = await self ._http_requests .get ("indexes" )
121115
122116 if not response .json ():
123117 return None
@@ -127,13 +121,13 @@ async def get_raw_indexes(self) -> Optional[list[IndexInfo]]:
127121 async def get_version (self ) -> Version :
128122 """Get version MeiliSearch that is running"""
129123
130- response = await self ._http_requests .get (build_url ( Paths . VERSION ) )
124+ response = await self ._http_requests .get ("version" )
131125 return Version (** response .json ())
132126
133127 async def health (self ) -> Health :
134128 """Get health of the MeiliSearch server"""
135129
136- response = await self ._http_requests .get (build_url ( Paths . HEALTH ) )
130+ response = await self ._http_requests .get ("health" )
137131 return Health (** response .json ())
138132
139133 def _set_headers (self , api_key : str = None ) -> dict [str , str ]:
0 commit comments