Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pyanderson/gather-client-ws
Gather WebSocket service client
https://github.com/pyanderson/gather-client-ws
gather gather-town python python3 websockets
Last synced: 2 months ago
JSON representation
Gather WebSocket service client
- Host: GitHub
- URL: https://github.com/pyanderson/gather-client-ws
- Owner: pyanderson
- License: mit
- Created: 2023-03-20T02:24:26.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-04T12:37:16.000Z (about 1 year ago)
- Last Synced: 2024-10-29T08:25:07.577Z (2 months ago)
- Topics: gather, gather-town, python, python3, websockets
- Language: Python
- Homepage: https://pypi.org/project/gather-client-ws/
- Size: 143 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gather WebSocket Client
## Installation
```bash
pip install gather-client-ws
```## Documentation
### Auth
Generate your `API_KEY` here: [https://gather.town/apiKeys](https://gather.town/apiKeys)
### Basic Usage
``` python
import asynciofrom gather_client_ws import GatherClient
async def producer(client):
await client.set_text_status("new status text")
await client.set_emoji_status("😁")async def main():
client = GatherClient(api_key=API_KEY, space_id=SPACE_ID)
await client.run(producer)asyncio.run(main())
# Output
[2023-03-19 22:44:57,340][INFO] Connected to wss://engine-a00a0.aaa0-.prod.do.gather.town:443/
[2023-03-19 22:44:57,637][INFO] Connected as user USER_ID
```### Adding extra args and kwargs
```python
import asynciofrom gather_client_ws import GatherClient
async def producer(client, *args, **kwargs):
await client.set_text_status("new status text")
await client.set_emoji_status("😁")
print(args)
print(kwargs)async def main():
client = GatherClient(api_key=API_KEY, space_id=SPACE_ID)
await client.run(producer, 'arg', k='kwarg')asyncio.run(main())
# Output
[2023-03-19 22:44:57,340][INFO] Connected to wss://engine-a00a0.aaa0-.prod.do.gather.town:443/
[2023-03-19 22:44:57,637][INFO] Connected as user USER_ID
('arg',)
{'k': 'kwarg'}
```### Server response callback
A callback function can be defined, this function will receive the `client` and the `ServerClientBatch` message:
```python
...async def callback(client, server_response):
for event in server_response.events:
print(event.WhichOneof("event"))async def producer(client):
await asyncio.sleep(30) # hold the connection for 30 secondsasync def main():
client = GatherClient(api_key=API_KEY, space_id=SPACE_ID, callback=callback)
await client.run(producer)asyncio.run(main())
# Output
[2023-03-19 22:56:33,840][INFO] Connected to wss://engine-a00a0.aaa0-.prod.do.gather.town:443/
[2023-03-19 22:56:34,351][INFO] Connected as user USER_ID
transactionStatus
transactionStatus
serverHeartbeat
serverHeartbeat
serverHeartbeat
```### Logger level
It is possible to define the client log level.
```python
import logging...
async def main():
client = GatherClient(api_key=API_KEY, space_id=SPACE_ID, log_level=logging.DEBUG)
await client.run(producer)asyncio.run(main())
# Output
[2023-03-19 23:01:08,274][INFO] Connected to wss://engine-a00a0.aaa0-a.prod.do.gather.town:443/
[2023-03-19 23:01:08,581][INFO] Connected as user USER_ID
[2023-03-19 23:01:08,582][DEBUG] Receiving messages
[2023-03-19 23:01:08,582][DEBUG] Heartbeat sent
[2023-03-19 23:01:08,743][DEBUG] Message received: events {
transactionStatus {
txnId: 3675756270
succeeded: true
}
}
events {
transactionStatus {
txnId: 226152914
succeeded: true
}
}[2023-03-19 23:01:18,514][DEBUG] Message received: events {
serverHeartbeat {
lastRTT: 4240423196
}
}
```### Actions
Listing the available actions:
```python
...
print(client.available_actions)
# Output
['client_heartbeat', 'client_backup_heartbeat', ..., 'start_recording']
```Accessing the basic documentation of each action:
```python
...
print(client.set_text_status.__doc__)
# Output
set_text_status
Args:
text_status (str)
target_id (str)
```OR
```python
help(client.craft)
# Output
Help on method method in module gather_client_ws.actions:async method(*args, **kwargs) method of gather_client_ws.client.GatherClient instance
craft
Args:
inputs (InputsEntry)
```You can check all available actions [here](ACTIONS.md).