Query Source and GoldSource servers for name, map, players and more.
Maintained. Last release 6 months ago, commits in 1 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install python-a2sPython A2S
Library to query Source and GoldSource servers. Implements Valve's Server Query Protocol. Rewrite of the python-valve module. Supports both synchronous and asyncronous applications.
Official demo application: Sourcequery
Requirements
Python >=3.9, no external dependencies
Install
pip3 install python-a2s or python3 setup.py install
API
Functions
a2s.info(address, timeout=DEFAULT_TIMEOUT, encoding=DEFAULT_ENCODING)a2s.players(address, timeout=DEFAULT_TIMEOUT, encoding=DEFAULT_ENCODING)a2s.rules(address, timeout=DEFAULT_TIMEOUT, encoding=DEFAULT_ENCODING)
All functions also have an async version as of package 1.2.0 that adds an a prefix, e.g.
ainfo, aplayers, arules.
Parameters
- address:
Tuple[str, int]- Address of the server. - timeout:
float- Timeout in seconds. Default: 3.0 - encoding:
strorNone- String encoding, None disables string decoding. Default: utf-8
Return Values
- info: SourceInfo or GoldSrcInfo. They are documented in the source file.
- players: List of Player items. Also documented in the corresponding source file.
- rules: Dictionary of key - value pairs.
Exceptions
a2s.BrokenMessageError(Exception)- General decoding errora2s.BufferExhaustedError(BrokenMessageError)- Response too shortsocket.timeout- No response (synchronous calls)asyncio.exceptions.TimeoutError- No response (async calls)socket.gaierror- Address resolution errorConnectionRefusedError- Target port closedOSError- Various networking errors like routing failure