11from meilisearch .index import Index
2- from meilisearch .health import Health
3- from meilisearch .key import Key
42from meilisearch .config import Config
5- from meilisearch .sys_info import SysInfo
6- from meilisearch .stat import Stat
7- from meilisearch .version import Version
3+ from meilisearch ._httprequests import HttpRequests
84
9- class Client (Health , Key , SysInfo , Version ):
5+ class Client ():
106 """
117 A client for the MeiliSearch API
128
139 A client instance is needed for every MeiliSearch API method to know the location of
1410 MeiliSearch and its permissions.
1511 """
1612
13+ config = None
14+ http = None
15+
1716 def __init__ (self , url , apiKey = None ):
1817 """
1918 Parameters
@@ -23,12 +22,8 @@ def __init__(self, url, apiKey=None):
2322 apiKey : str
2423 The optional API key for MeiliSearch
2524 """
26- config = Config (url , apiKey )
27- Health .__init__ (self , config )
28- Key .__init__ (self , config )
29- SysInfo .__init__ (self , config )
30- Version .__init__ (self , config )
31- self .config = config
25+ self .config = Config (url , apiKey )
26+ self .http = HttpRequests (self .config )
3227
3328 def create_index (self , uid , primary_key = None , name = None ):
3429 """Create an index.
@@ -53,8 +48,9 @@ def create_index(self, uid, primary_key=None, name=None):
5348 HTTPError
5449 In case of any other error found here https://docs.meilisearch.com/references/#errors-status-code
5550 """
56- index = Index .create (self .config , uid = uid , primary_key = primary_key , name = name )
57- return Index (self .config , uid = index ['uid' ])
51+ index = Index (self .config , uid = uid )
52+ index .create (self .config , uid = uid , primary_key = primary_key , name = name )
53+ return index
5854
5955 def get_indexes (self ):
6056 """Get all indexes.
@@ -86,11 +82,82 @@ def get_index(self, uid):
8682 return Index .get_index (self .config , uid = uid )
8783
8884 def get_all_stats (self ):
89- """Get statistics about indexes, database size and update date.
85+ """Get all stats of MeiliSearch
9086
87+ Get information about database size and all indexes
88+ https://docs.meilisearch.com/references/stats.html
9189 Returns
92- -------
93- stats : dict
94- Dictionnary with information about indexes, database size and update date.
90+ ----------
91+ stats: `dict`
92+ Dictionnary containing stats about your MeiliSearch instance
93+ """
94+ return self .http .get (self .config .paths .stat )
95+
96+ def health (self ):
97+ """Get health of MeiliSearch
98+
99+ `204` HTTP status response when MeiliSearch is healthy.
100+
101+ Raises
102+ ----------
103+ HTTPError
104+ If MeiliSearch is not healthy
105+ """
106+ return self .http .get (self .config .paths .health )
107+
108+ def update_health (self , health ):
109+ """Update health of meilisearch
110+
111+ Update health of MeiliSearch to true or false.
112+
113+ Parameters
114+ ----------
115+ health: bool
116+ Boolean representing the health status of MeiliSearch. True for healthy.
117+ """
118+ return self .http .put (self .config .paths .health , {'health' : health })
119+
120+ def get_keys (self ):
121+ """Get all keys created
122+
123+ Get list of all the keys that were created and all their related information.
124+
125+ Returns
126+ ----------
127+ keys: list
128+ List of keys and their information.
129+ https://docs.meilisearch.com/references/keys.html#get-keys
130+ """
131+ return self .http .get (self .config .paths .keys )
132+
133+ def get_sys_info (self ):
134+ """Get system information of MeiliSearch
135+
136+ Get information about memory usage and processor usage.
137+
138+ Returns
139+ ----------
140+ sys_info: dict
141+ Information about memory and processor usage.
142+ """
143+ return self .http .get (self .config .paths .sys_info )
144+
145+ def get_version (self ):
146+ """Get version MeiliSearch
147+
148+ Returns
149+ ----------
150+ version: dict
151+ Information about the version of MeiliSearch.
152+ """
153+ return self .http .get (self .config .paths .version )
154+
155+ def version (self ):
156+ """Alias for get_version
157+
158+ Returns
159+ ----------
160+ version: dict
161+ Information about the version of MeiliSearch.
95162 """
96- return Stat . get_all_stats ( self .config )
163+ return self .get_version ( )
0 commit comments