1
1
from meilisearch .index import Index
2
- from meilisearch .health import Health
3
- from meilisearch .key import Key
4
2
from 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
8
4
9
- class Client (Health , Key , SysInfo , Version ):
5
+ class Client ():
10
6
"""
11
7
A client for the MeiliSearch API
12
8
13
9
A client instance is needed for every MeiliSearch API method to know the location of
14
10
MeiliSearch and its permissions.
15
11
"""
16
12
13
+ config = None
14
+ http = None
15
+
17
16
def __init__ (self , url , apiKey = None ):
18
17
"""
19
18
Parameters
@@ -23,12 +22,8 @@ def __init__(self, url, apiKey=None):
23
22
apiKey : str
24
23
The optional API key for MeiliSearch
25
24
"""
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 )
32
27
33
28
def create_index (self , uid , primary_key = None , name = None ):
34
29
"""Create an index.
@@ -53,8 +48,9 @@ def create_index(self, uid, primary_key=None, name=None):
53
48
HTTPError
54
49
In case of any other error found here https://docs.meilisearch.com/references/#errors-status-code
55
50
"""
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
58
54
59
55
def get_indexes (self ):
60
56
"""Get all indexes.
@@ -86,11 +82,82 @@ def get_index(self, uid):
86
82
return Index .get_index (self .config , uid = uid )
87
83
88
84
def get_all_stats (self ):
89
- """Get statistics about indexes, database size and update date.
85
+ """Get all stats of MeiliSearch
90
86
87
+ Get information about database size and all indexes
88
+ https://docs.meilisearch.com/references/stats.html
91
89
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.
95
162
"""
96
- return Stat . get_all_stats ( self .config )
163
+ return self .get_version ( )
0 commit comments