Skip to main content

Gather WebSocket service client

Project description

Installation

pip install gather-client-ws

Documentation

Auth

Generate your API_KEY here: https://gather.town/apiKeys

Basic Usage

import asyncio

from 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

import asyncio

from 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:

...

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 seconds


async 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.

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:

...
print(client.available_actions)
# Output
['client_heartbeat', 'client_backup_heartbeat', 'update_subscriptions', 'move', 'set_affiliation', 'set_status', 'spotlight', 'ring', 'ban', 'kick', 'set_impassable', 'chat', 'interact', 'enter_whisper', 'leave_whisper', 'set_emoji_status', 'actively_speaking', 'set_name', 'set_text_status', 'teleport', 'exit', 'enter', 'set_work_condition', 'respawn', 'spawn', 'ghost', 'init', 'set_outfit_string', 'shoot_confetti', 'set_event_status', 'set_in_conversation', 'set_current_desk', 'set_current_area', 'set_image_pointer', 'set_go_kart_id', 'map_set_dimensions', 'map_set_collisions', 'map_set_background_image_path', 'map_set_foreground_image_path', 'map_set_sprites', 'map_set_spawns', 'map_set_spaces', 'map_set_portals', 'map_set_announcer', 'map_set_assets', 'map_set_objects', 'map_set_name', 'map_set_mute_on_entry', 'map_set_use_drawn_b_g', 'map_set_walls', 'map_set_floors', 'map_set_areas', 'map_add_object', 'map_delete_object', 'map_set_spawn', 'set_is_alone', 'map_set_mini_map_image_path', 'map_set_enabled_chats', 'map_set_description', 'map_set_decoration', 'map_set_tutorial_tasks', 'play_sound', 'map_set_script', 'set_is_mobile', 'set_screen_pointer', 'set_emote_v2', 'set_focus_mode_end_time', 'map_delete_object_by_id', 'custom_action', 'block', 'set_item_string', 'trigger_item', 'notify', 'set_follow_target', 'request_to_lead', 'enter_portal', 'set_manual_video_src', 'set_subtitle', 'player_updates_session', 'map_move_object', 'chat_message_updated', 'fx_shake_object', 'fx_shake_camera', 'register_command', 'send_command', 'speaker_updates_session', 'add_inventory_item', 'remove_inventory_item', 'set_vehicle_id', 'set_speed_modifier', 'high_five', 'update_space_items', 'stop_sound', 'hip_to_be_square', 'craft', 'trigger_inventory_item', 'set_allow_screen_pointer', 'precompute_enter', 'request_mute', 'set_desk_info', 'map_set_nooks', 'request_to_join_nook', 'update_nook_permission', 'wave', 'set_pronouns', 'set_title', 'set_timezone', 'set_phone', 'set_description', 'set_profile_image_url', 'set_personal_image_url', 'set_away', 'set_city', 'set_country', 'set_start_date', 'start_recording']

Accessing the basic documentation of each action:

...
print(client.set_text_status.__doc__)
# Output
set_text_status
Args:
        text_status (str)
        target_id (str)

OR

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gather-client-ws-0.0.4.tar.gz (38.9 kB view details)

Uploaded Source

Built Distribution

gather_client_ws-0.0.4-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file gather-client-ws-0.0.4.tar.gz.

File metadata

  • Download URL: gather-client-ws-0.0.4.tar.gz
  • Upload date:
  • Size: 38.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for gather-client-ws-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c53e89ffbbbfed07a16db2c20ed867300e98d9e8f65a64b301c086b8c12d46fc
MD5 9d0cb89e32c093126921cd04fb7ec7d5
BLAKE2b-256 769ba244070a07a7ba08b28757a6fc6a0e6da073ef5775d4b9ddbdca529abecc

See more details on using hashes here.

File details

Details for the file gather_client_ws-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for gather_client_ws-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fb1f7ceffbde1f9d31a19cb58fbe3c3988bbcf3f9f46fcb21ad40b856eb5395c
MD5 7c14b3933bcbddb09bbf9f20749fba78
BLAKE2b-256 7e2c6879267ccfd7879f1015585af6cbd7c0511d59fed46c5299ded5b4be024a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page