Package: ts3query
Forked fromhttps://github.com/benediktschmitt/py-ts3, which only supports ServerQuery. However, benediktschmitts
version is more likely to be up-to-date, since this was only forked for one specific project and only implements a small
subset of ClientQuery methods.This package provides aPython 3 APIfor:TS3 query connectionsTS3 query eventsTS3 file transfersYou can find a complete API documentationhere.InstallationThis package is registered on PyPi, so you’re done with:$pip3installts3TS3 Server configurationIf you want to send lots of queries to the TS3 server, make sure, that you’re
connection is not closed by theanti-flood protectionof the TS3 server.
So it may be wise to add the host that runs the TS3 queries to thequery_ip_whitelist.txtof your TS3 server:$echo"192.168.178.42">>path/to/ts3/server/directory/query_ip_whitelist.txtIntroductionThe easiest way to get to grips with this library is taking a look at theexamples.If you need information about the possible query commands, take a look at theTS3 Server Query Manual.ExamplesYou can find more examples in thets3.examplespackage.Show all clients on the virtual server with the server id 1:#!/usr/bin/python3importts3withts3.query.TS3ServerConnection("localhost")asts3conn:# Note, that the client will wait for the response and raise a# **TS3QueryError** if the error id of the response is not 0.try:ts3conn.login(client_login_name="serveradmin",client_login_password="FoOBa9")exceptts3.query.TS3QueryErroraserr:print("Login failed:",err.resp.error["msg"])exit(1)ts3conn.use(sid=1)# Each query method will return a **TS3QueryResponse** instance,# with the response.resp=ts3conn.clientlist()print("Clients on the server:",resp.parsed)print("Error:",resp.error["id"],resp.error["msg"])# Note, the TS3Response class and therefore the TS3QueryResponse# class too, can work as a rudimentary container. So, these two# commands are equal:forclientinresp.parsed:print(client)forclientinresp:print(client)Say hello to all clients:#!/usr/bin/python3importts3withts3.query.TS3ServerConnection("localhost")asts3conn:ts3conn.login(client_login_name="serveradmin",client_login_password="FoOBa9")ts3conn.use(sid=1)forclientints3conn.clientlist():msg="Hi{}".format(client["client_nickname"])ts3conn.clientpoke(clid=client["clid"],msg=msg)Say hello to all clients but use it with the ClientQuery plugin instead of a ServerQuery connection:#!/usr/bin/python3importts3withts3.query.TS3Connection("localhost",25639)asts3conn:ts3conn.auth(apikey="AAAA-BBBB-CCCC-DDDD-EEEEh")forclientints3conn.clientlist():msg="Hi{}".format(client["client_nickname"])ts3conn.clientpoke(clid=client["clid"],msg=msg)Event handling (Server Query):#!/usr/bin/python3importtimeimportts3withts3.query.TS3ServerConnection("localhost")asts3conn:ts3conn.login(client_login_name="serveradmin",client_login_password="FoOBa9")ts3conn.use(sid=1)# Register for eventsts3conn.servernotifyregister(event="server")whileTrue:event=ts3conn.wait_for_event()# Greet new clients.ifevent[0]["reasonid"]=="0":print("client connected")ts3conn.clientpoke(clid=event[0]["clid"],msg="Hello :)")A simple TS3 viewer:#!/usr/bin/python3importts3# The examples package already contains this implementation.# Note, that the ts3.examples.viewer module has an helpful class to# build a complete channel tree of a virtual server: ChannelTreeNodefromts3.examples.viewerimportviewwithts3.query.TS3ServerConnection("localhost")asts3conn:ts3conn.login(client_login_name="serveradmin",client_login_password="FoOBa9")view(ts3conn,sid=1)Download and upload files:#!/usr/bin/python3importts3withts3.query.TS3ServerConnection("localhost")asts3conn:ts3conn.login(client_login_name="serveradmin",client_login_password="FoOBa9")# Create a new TS3FileTransfer instance associated with the# TS3ServerConnection.ts3ft=ts3.filetransfer.TS3FileTransfer(ts3conn)# Upload the image *baz.png* to the channel with the id 2 on the# TS3 server.# Note the opening mode ("rb").withopen("baz.png","rb")asfile:ts3ft.init_upload(input_file=file,name="/baz.png",cid=2)# Download the file into *baz1.png*.withopen("baz1.png","wb")asfile:ts3ft.init_download(output_file=file,name="/baz.png",cid=2)Event handling (Client Query):#!/usr/bin/python3importtimeimportts3withts3.query.TS3ClientConnection("localhost")asts3conn:ts3conn.auth(apikey="AAAA-....-EEEE")ts3conn.use()# Register for eventsts3conn.clientnotifyregister(event="any")whileTrue:event=ts3conn.wait_for_event()print(event.parsed)BugsIf you found a bug please report it or sent a pull request.Please report grammar or spelling errors too.VersioningFor the version numbers, take a look athttp://semver.org/.LicenseThis package is licensed under the MIT License.The docstrings copied from the TS3 Server Query Manual are the property of theTeamSpeak Systems GmbH.