Skip to content

Commit e784a65

Browse files
committed
Update README.md with installation and usage
1 parent 35664a1 commit e784a65

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

README.md

+63
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,65 @@
11
# xpipe_client
22
Python client for the XPipe API
3+
4+
## Installation
5+
```
6+
python3 -m pip install git+https://github.com/coandco/python_xpipe_client
7+
```
8+
9+
## Usage
10+
11+
```python
12+
from xpipe_client.clients import Client
13+
14+
# By default, Client() will read the API key from xpipe_auth on the local filesystem
15+
# and talk to the XPipe API on localhost. To connect to a remote instance with an API
16+
# key, use Client(token="foo", base_url = "http://servername:21723")
17+
client = Client()
18+
19+
# connection_query accepts glob-based filters on the category, connection name, and connection type
20+
all_connections = client.connection_query()
21+
22+
# Each connection includes uuid, category, connection, and type information
23+
first_connection_uuid = all_connections[0]["uuid"]
24+
25+
# Before any shell commands can be run, a shell session must be started on a connection
26+
client.shell_start(first_connection_uuid)
27+
28+
# Prints {'exitCode': 0, 'stdout': 'hello world', 'stderr': ''}
29+
print(client.shell_exec(first_connection_uuid, "echo hello world"))
30+
31+
# Clean up after ourselves
32+
client.shell_stop(first_connection_uuid)
33+
```
34+
35+
There's also an async version of the client that can be accessed as AsyncClient:
36+
```python
37+
import asyncio
38+
from xpipe_client.clients import AsyncClient
39+
40+
41+
async def main():
42+
# By default, AsyncClient() will read the API key from xpipe_auth on the local filesystem
43+
# and talk to the XPipe API on localhost. To connect to a remote instance with an API
44+
# key, use Client(token="foo", base_url = "http://servername:21723")
45+
client = AsyncClient()
46+
47+
# connection_query accepts glob-based filters on the category, connection name, and connection type
48+
all_connections = await client.connection_query()
49+
50+
# Each connection includes uuid, category, connection, and type information
51+
first_connection_uuid = all_connections[0]["uuid"]
52+
53+
# Before any shell commands can be run, a shell session must be started on a connection
54+
await client.shell_start(first_connection_uuid)
55+
56+
# Prints {'exitCode': 0, 'stdout': 'hello world', 'stderr': ''}
57+
print(await client.shell_exec(first_connection_uuid, "echo hello world"))
58+
59+
# Clean up after ourselves
60+
await client.shell_stop(first_connection_uuid)
61+
62+
63+
if __name__ == "__main__":
64+
asyncio.run(main())
65+
```

0 commit comments

Comments
 (0)