• Stars
    star
    146
  • Rank 252,769 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A2S Query API for Python

Python 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.7, 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: str or None - 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 error
  • a2s.BufferExhaustedError(BrokenMessageError) - Response too short
  • socket.timeout - No response (synchronous calls)
  • asyncio.exceptions.TimeoutError - No response (async calls)
  • socket.gaierror - Address resolution error
  • ConnectionRefusedError - Target port closed
  • OSError - Various networking errors like routing failure

Examples

Example output shown may be shortened. Also the server shown in the example may be down by the time you see this.

>>> import a2s
>>> address = ("chi-1.us.uncletopia.com", 27015)
>>> a2s.info(address)
SourceInfo(protocol=17, server_name='Uncletopia | Chicago | 1', map_name='pl_badwater',
folder='tf', game='Team Fortress', app_id=440, player_count=24, max_players=24, bot_count=0,
server_type='d', platform='l', password_protected=False, vac_enabled=True, version='7370160',
edf=241, port=27015, steam_id=85568392924469984, stv_port=27016,
stv_name='Uncletopia | Chicago | 1 | STV', keywords='nocrits,nodmgspread,payload,uncletopia',
game_id=440, ping=0.2339219159912318)

>>> a2s.players(address)
[Player(index=0, name='AmNot', score=22, duration=8371.4072265625),
Player(index=0, name='TAAAAANK!', score=15, duration=6251.03173828125),
Player(index=0, name='Tiny Baby Man', score=17, duration=6229.0361328125)]

>>> a2s.rules(address)
{'coop': '0', 'cronjobs_version': '2.0', 'crontab_version': '2.0', 'deathmatch': '1',
'decalfrequency': '10', 'discord_accelerator_version': '1.0', 'discord_version': '1.0',
'extendedmapconfig_version': '1.1.1', 'metamod_version': '1.11.0-dev+1145V', 'mp_allowNPCs': '1'}

Notes

  • Some servers return inconsistent or garbage data. Filtering this out is left to the specific application, because there is no general approach to filtering that makes sense for all use cases. In most scenarios, it makes sense to at least remove players with empty names. Also the player_count value in the info query and the actual number of players returned in the player query do not always match up. Sometimes the player query returns an empty list of players.

  • For some games, the query port is different from the actual connection port. The Steam server browser will show the connection port and querying that will not return an answer. There does not seem to be a general solution to this problem so far, but usually probing port numbers up to 10 higher and lower than the connection port usually leads to a response. There's also the option of using http://api.steampowered.com/ISteamApps/GetServersAtAddress/v0001?addr={IP} to get a list of game servers on an IP (thanks to Nereg for this suggestion). If you're still not successful, use a network sniffer like Wireshark to monitor outgoing packets while refreshing the server popup in Steam.

  • Player counts above 255 do not work and there's no way to make them work. This is a limitation in the specification of the protocol.

  • This library does not implement rate limiting. It's up to the application to limit the number of requests per second to an acceptable amount to not trigger any firewall rules.

Tested Games

Half-Life 2, Half-Life, Team Fortress 2, Counter-Strike: Global Offensive, Counter-Strike 1.6, ARK: Survival Evolved, Rust

License

MIT

More Repositories

1

gogdb

Website that collects data on GOG games
Python
123
star
2

gogextract

Script for unpacking GOG Linux installers
Python
61
star
3

gogapidocs

Community created documentation of the GOG.com APIs
Python
50
star
4

pygogapi

Python wrapper around the GOG JSON APIs. Long outdated, please do not use this!
Python
21
star
5

gog_protocols

Reverse engineered protobuf files for GOG Galaxy
15
star
6

idcard-qr

Documentation of the QR code found on new Austrian ID cards.
Python
10
star
7

willywerkel

Documentation of the game "Flugzeuge bauen mit Willy Werkel"
Python
9
star
8

orfstreams

List of ORF live stream urls.
HTML
6
star
9

l4d2query

Python
5
star
10

TileCodecs

Python library of ported Tile Molester image codecs
Python
5
star
11

sourcequery

Website for querying servers that support the A2S protocol.
HTML
5
star
12

adbtools

Tools for hacking ADB Epicentro routers
Python
4
star
13

crosstex

Cross-platform port of the DirectXTex block compression codecs
C++
4
star
14

vtfconv

Convert between vtf textures and various image formats
C++
3
star
15

libsaints

Library for Saints Row file formats
C++
3
star
16

oebbwlan

Automatically dismisses the portal page of OEBB train WLAN, so you don't have to manually open it in your browser
Python
3
star
17

galaxyimport

Import library for linking to the GOG Galaxy SDK with MSVC.
2
star
18

dayzquery

Small Python module to decode the DayZ rules binary response.
Python
2
star
19

saintstools

CLI and GUI tools for modifying Saints Row files
C++
2
star
20

yepoleb.github.io

Repo for my website
HTML
2
star
21

libsrcdemo

Work in progress library for reading source demo files
C++
2
star
22

saintsrow-python

Quick Python implementations of Saints Row formats
Python
2
star
23

3dssmb

FTP-like client for managing New Nintendo 3DS microSD shares.
Python
2
star
24

smoothic

Minetest port of the Smoothic Minecraft texture pack by Leozy
Shell
2
star
25

libsoundiopp

C++ wrapper around libsoundio
C++
2
star
26

srtextool

Tool for converting DDS textures to and from the Volition bitmap format
C++
2
star
27

adventofcode

Advent of Code 2018 Solutions
C++
1
star
28

stx

Collection of C++ standard library extensions and replacements
C++
1
star
29

rconshell

Basic RCON shell
Python
1
star
30

aiv

GUI for viewing compressed and uncompressed Images in GBA-ROMs
Python
1
star
31

libhifive

Alternative SDK for the SiFive HiFive1 Rev B.
C
1
star
32

gog_gdpr

Documentation of the GOG GDPR response and most of the files I received.
1
star
33

hashinstall

Restore installations from a list of file hashes
Python
1
star
34

libcwrapper

Assembly wrapper around libc to allow calling the System V AMD64 ABI using the Microsoft x64 calling convention
Assembly
1
star
35

gv.at

Sanitized list of Austrian government domains with TLS
HTML
1
star
36

vdfparser

Small library for parsing VDF files
C++
1
star
37

doxygenfiles

Script to download header documentation from Doxygen and extract the file contents.
Python
1
star
38

conntrack

Script to remotely access the /proc/net/ip_conntrack file and sort the IPs by connection count.
Python
1
star