Query#

class a2squery.A2SQuery(host: str, port: int = 27015, timeout: float = 10)#

Query various information from running Source/GoldSource game servers.

This class allows you to interface with servers that implement the A2S query protocol. Each instance of A2SQuery opens a socket and connects to the specified server until closed. A2SQuery will authenticate server challenge requests.

__init__(host: str, port: int = 27015, timeout: float = 10)#

Create a new A2SQuery instance connected to the specified server.

Parameters
  • host – The IP address of the server. Do not include a port here.

  • port – The query port of the server. This is the same as the connection port for most games.

  • timeout – How long to wait for connection/requests before timing out.

close() None#

Close the query socket. All requests after this will fail.

info() Union[a2squery.data.SourceInfo, a2squery.data.GoldSourceInfo]#

Query general information about the server.

Returns

a2squery.SourceInfo or a2squery.GoldSourceInfo depending on server’s engine/response.

player() List[a2squery.data.Player]#

Query the server’s current players/bots.

Returns

List of Player objects

players() List[a2squery.data.Player]#

Query the server’s current players/bots.

This is an alias of A2SQuery.player().

Returns

List of Player objects

rules() Dict[str, str]#

Query the server’s rules/configuration variables in key/value pairs.

The Console variables included are the ones marked with FCVAR_NOTIFY as well as any additional ones listed in the server configuration.

Returns

Key/value dictionary of rules