File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1
1
NetAuth for Python
2
2
==================
3
3
4
+ .. highlight :: python
5
+
4
6
A `NetAuth <https://netauth.org >`_ client library for Python.
5
7
8
+ To install: ``pip install netauth ``
9
+
10
+ Usage
11
+ ~~~~~
12
+
13
+ This library centers around the :class: `NetAuth ` object::
14
+
15
+ na = netauth.NetAuth("netauth.example.org")
16
+
17
+ try:
18
+ resp = na.system_status()
19
+ print(resp)
20
+ except netauth.error.NetAuthRpcError as e:
21
+ print(f"Request failed: {e}")
22
+
23
+ na.close()
24
+
25
+ :class: `NetAuth ` can also be used as a context manager and be initialized from a NetAuth configuration file::
26
+
27
+
28
+ with netauth.NetAuth.with_config(Path("/etc/netauth/config.toml")) as na:
29
+ try:
30
+ resp = na.system_status()
31
+ print(resp)
32
+ except netauth.error.NetAuthRpcError as e:
33
+ print(f"Request failed: {e}")
34
+
35
+ For interactive or dynamic applications, operations that require authentication can use a callback to retrieve the user's secret::
36
+
37
+ def secret_cb() -> str:
38
+ return getpass(prompt="Secret: ")
39
+
40
+ with netauth.NetAuth("netauth.example.org", entity="demo", secret=secret_cb) as na:
41
+ try:
42
+ na.entity_kv_add("demo", "foo", ["bar", "baz"])
43
+ except error.NetAuthRpcError as e:
44
+ print(f"Request failed: {e}")
45
+
46
+ API
47
+ ~~~
48
+
6
49
.. currentmodule :: netauth
7
50
8
51
.. autoclass :: NetAuth
You can’t perform that action at this time.
0 commit comments