Skip to content

Commit 69d920e

Browse files
committed
docs: add usage examples
1 parent 81712c4 commit 69d920e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/index.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,51 @@
11
NetAuth for Python
22
==================
33

4+
.. highlight:: python
5+
46
A `NetAuth <https://netauth.org>`_ client library for Python.
57

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+
649
.. currentmodule:: netauth
750

851
.. autoclass:: NetAuth

0 commit comments

Comments
 (0)