Skip to main content

Simple Python API for the Teamspeak 3 Server Query API

Python Package Building CodeQL Pylint

Python 3 API that allows interactive access to the Teamspeak 3 Server Query interface.

Installation

Either clone the GitHub repository and use local imports, or install it via pip:

pip install ts3API

If you want to use SSH connections also install the optional dependency Paramiko:

pip install paramiko

Code Example

from ts3API.TS3Connection import TS3Connection
import ts3API.Events as Events

HOST = "serverhost"
PORT = 10011 # Default Port
USER = 'serveradmin' # Default login
PASS = 'password'
DEFAULTCHANNEL = 'Botchannel-or-any-other'
SID = 1 # Virtual server id
NICKNAME = "aName"

def on_event(sender, **kw):
    """
    Event handling method
    """
    # Get the parsed event from the dictionary
    event = kw["event"]
    print(type(event))
    """
    # This generates output for every event. Remove the comment if you want more output
    for attr, value in event.__dict__.items():
        print("\t"+attr+":", value)
    """
    if isinstance(event, Events.ClientBannedEvent):
        print("Client was banned!")
        print("\tClient ID:", event.client_id)
        print("\tReason Message:", event.reason_msg)
        print("\tInvokerID:", event.invoker_id)
        print("\tInvokerName:", event.invoker_name)
        print("\tBantime:", event.ban_time)
    if isinstance(event, Events.ClientKickedEvent):
        print("Client was kicked!")
        print("\tClient ID:", event.client_id)
        print("\tReason Message:", event.reason_msg)
        print("\tInvokerID:", event.invoker_id)
        print("\tInvokerName:", event.invoker_name)

    if isinstance(event, Events.ClientLeftEvent):
        print("Client left!")
        print("\tClient ID:", event.client_id)
        print("\tReason Message:", event.reason_msg)
    if type(event) is Events.TextMessageEvent:
        # Prevent the client from sending messages to itself
        if event.invoker_id != int(ts3conn.whoami()["client_id"]):
            ts3conn.sendtextmessage(targetmode=1, target=event.invoker_id, msg="I received your message!")

# Connect to the Query Port
ts3conn = TS3Connection(HOST, PORT)
# Login with query credentials
ts3conn.login(USER, PASS)
# Choose a virtual server
ts3conn.use(sid=SID)
# Find the channel to move the query client to
channel = ts3conn.channelfind(pattern=DEFAULTCHANNEL)[0]["cid"]
# Give the Query Client a name
ts3conn.clientupdate(["client_nickname="+NICKNAME])
# Move the Query client
ts3conn.clientmove(channel, int(ts3conn.whoami()["client_id"]))
# Register for server wide events
ts3conn.register_for_server_events(on_event) 
# Register for private messages
ts3conn.register_for_private_messages(on_event)
# Register for channel message in botchannel
ts3conn.register_for_channel_events(channel, on_event) 
# Start the loop to send connection keepalive messages
ts3conn.start_keepalive_loop()

For a more elaborated example of this API see the ts3Bot project: https://github.com/Murgeye/ts3Bot

Calling functions not explicitly implemented

Thanks to Chrisg2000's contribution, the API implements any command accepted by a TeamSpeak3 server. You can call any command mentionend in the server query manual (should come with you server installation) using keyword arguments, even if it's not explicitly implemented in code. See this code snippet for example:

servergroupaddclient(sgid=servergroup_id, cldbid=client_db_id)  

The servergroupaddclient command is not currently implemented explicitly. However, you can still call it if you know the parameters it need (sgid and cldbid).

Troubleshooting

For general troubleshooting please also have a look at the troubleshooting section in https://github.com/Murgeye/ts3Bot. If any questions remain, feel free to open an issue.

Release files for ts3API 0.9.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ts3API 0.9.4
File Size Uploaded
ts3API-0.9.4.tar.gz 22.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ts3API 0.9.4
File Interpreter ABI Platform
ts3API-0.9.4-py3-none-any.whl Python 3 none any Details

Total release size: 44.2 kB

Release files / ts3API-0.9.4.tar.gz

Download URL ts3API-0.9.4.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e8b4f3ca1b8c9a2be60f328c222e833300e58ccfe5fb2205e949c13ff4ee9cfb
BLAKE2b-256 checksum
How to use checksums
c4e62151088564c24acec1a64135906feeb73515f97dea6b7918c6c64b8d41b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / ts3API-0.9.4-py3-none-any.whl

Download URL ts3API-0.9.4-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d7704f36815bf6d4333bcefb952d6ccde068254e02daa09dbc370c7cdccd67f
BLAKE2b-256 checksum
How to use checksums
d8b332bc394439ea3d46f74f7bcc284b4c6f497b8eb5acd97005c48f39113a95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.9.4 This release

2 release files

0.9.2

1 release file

0.9.1

2 release files

0.9.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page