@@ -7,7 +7,8 @@ Version](https://img.shields.io/pypi/pyversions/python-glinet)](https://pypi.org
7
7
[ ![ Code
8
8
Cov] ( https://codecov.io/gh/tomtana/python-glinet/branch/main/graph/badge.svg?token=976L8ESH8K )] ( https://codecov.io/gh/tomtana/python-glinet )
9
9
10
- # python-glinet - A Python3 Client for GL.Inet Router
10
+ python-glinet - A Python3 Client for GL.Inet Router
11
+ ===================================================
11
12
12
13
- ** Python3 client providing full access to the GL.Inet Luci API.**
13
14
- ** Supported firmware versions: 4.0 onwards**
@@ -20,10 +21,7 @@ Cov](https://codecov.io/gh/tomtana/python-glinet/branch/main/graph/badge.svg?tok
20
21
21
22
![ image] ( https://github.com/tomtana/python-glinet/raw/main/ressources/python_glinet_demo.gif )
22
23
23
- ::: note
24
- ::: title
25
- Note
26
- :::
24
+ ** Note:**
27
25
28
26
- GL.Inet changed the api mechanism from REST to JSON-RPC with the
29
27
introduction of the firmware 4.0. Therefore, older versions are not
35
33
updated.
36
34
- The best way to navigate and explore the api is within an ipython
37
35
shell. A wrapper for ipython and terminal is on the roadmap.
38
- :::
39
36
40
- ## Installation
37
+ Installation
38
+ ------------
41
39
42
40
### PIP
43
41
44
- ``` sh
42
+ ``` {.sourceCode .sh}
45
43
pip install python-glinet
46
44
```
47
45
48
46
### From Repo
49
47
50
- ``` sh
48
+ ``` {.sourceCode .sh}
51
49
#clone repository
52
50
git clone https://github.com/tomtana/python-glinet.git
53
51
cd python-glinet
@@ -59,13 +57,14 @@ virtual environment (see
59
57
The pip parameter ` -e ` is optional, and gives you the possibility to
60
58
edit the ` python-glinet ` module in the cloned folder.
61
59
62
- ``` sh
60
+ ``` {.sourceCode .sh}
63
61
python3 -m venv venv
64
62
source venv/bin/activate
65
63
pip install -e .
66
64
```
67
65
68
- ## Getting Started
66
+ Getting Started
67
+ ---------------
69
68
70
69
The heart piece of ` python-glinet ` is the ` GlInet ` class. It is manages
71
70
authentication, session and communication with the api. In case you
@@ -74,66 +73,54 @@ need to pass them as parameter (see the documentation of the
74
73
[ GlInet] ( https://tomtana.github.io/python-glinet/glinet.html ) class for
75
74
more details).
76
75
77
- For browsing the api using the dynamically created api_client , it is
76
+ For browsing the api using the dynamically created api \_ client , it is
78
77
assumed that the commands are executed in an ipython shell.
79
78
80
- ::: warning
81
- ::: title
82
- Warning
83
- :::
79
+ ** Warning:**
84
80
85
81
Even though possible, it is strongly discouraged to pass the password as
86
82
a parameter.
87
- :::
88
83
89
- ::: note
90
- ::: title
91
- Note
92
- :::
84
+ ** Note:**
93
85
94
86
- The constructor is checking if a api description is already in the
95
87
cache and will load it from the gl.inet online documentation if not.
96
88
- Make sure you check and understand the default settings
97
- :::
98
89
99
- ``` python
90
+ ``` {.sourceCode . python}
100
91
from pyglinet import GlInet
101
92
glinet = GlInet()
102
93
```
103
94
104
95
### Login
105
96
106
- ``` python
97
+ ``` {.sourceCode . python}
107
98
glinet.login()
108
99
```
109
100
110
- ::: note
111
- ::: title
112
- Note
113
- :::
101
+ ** Note:**
114
102
115
103
- if no password is passed as parameter in the constructor, ` login() `
116
104
will try to load login data from persistence
117
105
- if no success ask via prompt and persist settings
118
106
- start background thread to keep connection alive
119
- :::
120
107
121
108
### API Access Via Dynamically Created Client
122
109
123
110
Make sure you are in an ipython shell and logged in. Then, generate the
124
111
` api_client ` .
125
112
126
- ``` python
113
+ ``` {.sourceCode . python}
127
114
api_client = glinet.get_api_client()
128
115
```
129
116
130
117
#### General
131
118
132
119
- The api structure is as follow:
133
- ** client.\< functionial_group \> .\< method\> **
120
+ ** client.\< functionial \_ group \> .\< method\> **
134
121
- Due to python naming rules for variables, all \" -\" are replaced
135
122
with \"\_\" for the api method construction. ** e.g. wg-client
136
- becomes wg_client .**
123
+ becomes wg \_ client .**
137
124
- Use code completion and docstring to intuitively navigate the api
138
125
139
126
#### Functional Groups
@@ -142,10 +129,7 @@ Just call your client to see all available api function groups.
142
129
143
130
api_client
144
131
145
- ::: collapse
146
- Output
147
-
148
- ``` bash
132
+ ``` {.sourceCode .bash}
149
133
Out[11]:
150
134
Function
151
135
------------------
@@ -193,21 +177,17 @@ wifi
193
177
cloud
194
178
cloud_batch_manage
195
179
```
196
- :::
197
180
198
181
#### Methods
199
182
200
183
To explore the methods of a function group, just select it and hit
201
184
enter.
202
185
203
- ``` python
186
+ ``` {.sourceCode . python}
204
187
api_client.wg_client
205
188
```
206
189
207
- ::: collapse
208
- Output
209
-
210
- ``` bash
190
+ ``` {.sourceCode .bash}
211
191
Out[6]:
212
192
Function
213
193
--------------------
@@ -234,22 +214,18 @@ set_route
234
214
get_route_list
235
215
remove_route
236
216
```
237
- :::
238
217
239
218
#### Parameters
240
219
241
220
Select your method and press enter. A list for all possible parameters
242
221
are printed. If a parameter is prepended with ` ? ` , it means it is
243
222
optional.
244
223
245
- ``` python
224
+ ``` {.sourceCode . python}
246
225
api_client.wg_client.set_config
247
226
```
248
227
249
- ::: collapse
250
- Output
251
-
252
- ``` bash
228
+ ``` {.sourceCode .bash}
253
229
Out[8]:
254
230
Parameter Type Description
255
231
--------------------- ------ ------------------
@@ -270,21 +246,17 @@ peer_id number 配置ID
270
246
?persistent_keepalive number 节点保活
271
247
?mtu number 节点的mtu
272
248
```
273
- :::
274
249
275
250
#### Docstring
276
251
277
252
You can also show the docstring by appending a ` ? ` to the method. It
278
253
will show all the parameter and usage examples.
279
254
280
- ``` text
255
+ ``` {.sourceCode . text}
281
256
api_client.wg_client.set_config?
282
257
```
283
258
284
- ::: collapse
285
- Output
286
-
287
- ``` text
259
+ ``` {.sourceCode .text}
288
260
Signature: api.wg_client.set_config(params=None)
289
261
Type: GlInetApiCall
290
262
File: ~/.local/lib/python3.10/site-packages/pyglinet/api_helper.py
@@ -315,7 +287,6 @@ Example request:
315
287
Example response:
316
288
{\"jsonrpc\": \"2.0\", \"id\": 1, \"result\": {}}
317
289
```
318
- :::
319
290
320
291
#### Method call
321
292
@@ -324,7 +295,7 @@ how parameters need to be passed.
324
295
325
296
api_client.wg_client.get_all_config_list()
326
297
327
- ``` bash
298
+ ``` {.sourceCode . bash}
328
299
Out[12]: {'name': 'wg_client__get_all_config_list', 'config_list': [{'name': 'wg_client__get_all_config_list', 'username': '', 'group_name': 'AzireVPN', 'peers': [], 'password': '', 'auth_type': 1, 'group_id': 9690}]}
329
300
```
330
301
@@ -336,55 +307,52 @@ data.
336
307
337
308
### API Access Via Direct Request
338
309
339
- Instead of using the dynamically created api_client , it is also possible
340
- to use the ` GlInet ` instance to make api requests. In fact, the
341
- api_client uses the ` GlInet ` session under the hood.
310
+ Instead of using the dynamically created api \_ client , it is also
311
+ possible to use the ` GlInet ` instance to make api requests. In fact, the
312
+ api \_ client uses the ` GlInet ` session under the hood.
342
313
343
314
Once logged in, you simply can use the ` glinet.request(method, params) `
344
315
method to access or retrieve data from the api. Information about the
345
316
method and the parameters can either be found in the
346
317
[ documentation] ( https://dev.gl-inet.cn/docs/api_docs_page ) or via the
347
- api_client .
318
+ api \_ client .
348
319
349
320
e.g.
350
321
351
322
glinet.request("call", ["adguardhome", "get_config"])
352
323
353
- ``` bash
324
+ ``` {.sourceCode . bash}
354
325
Out[12]: {'name': 'adguardhome__get_config', 'id': 13, 'jsonrpc': '2.0', 'result': {'name': 'adguardhome__get_config', 'enabled': False}}
355
326
```
356
327
357
328
is equivalent to
358
329
359
330
api_client.adguardhome.get_config()
360
331
361
- ``` bash
332
+ ``` {.sourceCode . bash}
362
333
Out[13]: {'name': 'adguardhome__get_config', 'enabled': False}
363
334
```
364
335
365
- ::: note
366
- ::: title
367
- Note
368
- :::
336
+ ** Note:**
369
337
370
338
The output of the ` request ` method returns the whole response body
371
- whereas the api_client just returns the result dict.
372
- :::
339
+ whereas the api\_ client just returns the result dict.
373
340
374
- ## Roadmap
341
+ Roadmap
342
+ -------
375
343
376
344
### V1.0.0
377
345
378
- - [x] Add dynamically docstring for API calls
379
- - [x] Create pip compliant package
380
- - [x] Publish pip package
381
- - [x] Add tests
382
- - [x] Improve documentation
383
- - [x] Increase test coverage
384
- - [ ] replace crypt dependency to allow also Windows execution
385
- - [ ] Add wrapper for execution via terminal
346
+ - ☒ Add dynamically docstring for API calls
347
+ - ☒ Create pip compliant package
348
+ - ☒ Publish pip package
349
+ - ☒ Add tests
350
+ - ☒ Improve documentation
351
+ - ☒ Increase test coverage
352
+ - ☐ replace crypt dependency to allow also Windows execution
353
+ - ☐ Add wrapper for execution via terminal
386
354
387
355
### V2.0.0
388
356
389
- - [ ] Add asyncio support
390
- - [ ] \. ..
357
+ - ☐ Add asyncio support
358
+ - ☐ \. ..
0 commit comments