A2SQuery#
A2SQuery is a python implementation of Valve’s A2S protocol.
Features#
Supports synchronous and asynchronous querying.
Multi-packet response support for Source and GoldSource engines.
Supports BZIP2 compressed responses.
Handles MTU edge cases for Source games.
Fully type hinted (PEP 561 compliant) with modern design and dataclass response objects.
Enforces limits on challenge-response handshakes to prevent infinite recursion loops.
Zero dependencies.
Prerequisites#
Python >= 3.7
Installation#
Install the library via PyPi with:
pip install a2squery
Getting Started (Synchronous)#
To start querying servers, we’ll need an
instance of a2squery.A2SQuery. We can either create one manually,
or use a context manager. For this example, we will be using a context manager.
Tip
When using a2squery.A2SQuery without a context manager,
remember to call a2squery.A2SQuery.close() when finished.
>>> from a2squery import A2SQuery
>>> with A2SQuery("127.0.0.1", 27015) as a2s:
>>> print(a2s.info())
SourceInfo(
protocol=17, name="Awp Bhop", map="awp_iceworld",
folder="csgo", game="Counter-Strike: Global Offensive",
app_id=730, players=43, max_players=64, bots=0,
server_type=ServerType.Dedicated, environment=Environment.Linux,
password=False, vac=True, version="1.38.4.4", extra_data_flag=177,
mode=None, witnesses=None, duration=None,
port=27015, steam_id=85568392924437989, spectator_port=None,
spectator_name=None, keywords="awp,bhop,a2squeryiscool", game_id=730
)
Getting Started (Asynchronous)#
To start querying servers, we’ll need an
instance of a2squery.AsyncA2SQuery. We can either create one manually,
or use a context manager. For this example, we will be using a context manager.
Tip
When using a2squery.A2SQuery without a context manager,
you will need to call a2squery.AsyncA2SQuery.connect() to start the
connection, and call a2squery.A2SQuery.close() when finished.
>>> from a2squery import A2SQuery
>>> async with A2SQuery("127.0.0.1", 27015) as a2s:
>>> print(await a2s.info())
SourceInfo(
protocol=17, name="Awp Bhop", map="awp_iceworld",
folder="csgo", game="Counter-Strike: Global Offensive",
app_id=730, players=43, max_players=64, bots=0,
server_type=ServerType.Dedicated, environment=Environment.Linux,
password=False, vac=True, version="1.38.4.4", extra_data_flag=177,
mode=None, witnesses=None, duration=None,
port=27015, steam_id=85568392924437989, spectator_port=None,
spectator_name=None, keywords="awp,bhop,a2squeryiscool", game_id=730
)
Supported Games (Non-Exhaustive)#
App ID |
Game |
Notes |
|---|---|---|
… |
All Half-Life/Half-Life 2 mods and games |
|
10 |
||
440 |
||
550 |
||
730 |
||
1002 |
||
2400 |
This game has various unique fields on |
|
4000 |
||
17710 |
||
70000 |
||
107410 |
The query port is the server port + 1. |
|
115300 |
||
211820 |
||
244850 |
The query port is the server port + 1. |
|
304930 |
The query port is the server port + 1. |
|
251570 |
||
252490 |
||
282440 |
||
346110 |
||
108600 |