Skip to main content

Query Source and GoldSource servers for name, map, players and more.

Project description

Python A2S

Library to query Source and GoldSource servers. Rewrite of the python-valve module.

Requirements

Just Python 3.5+

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)

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
  • socket.gaierror - Address resolution error

Examples

Example output shown may be shortened.

>>> import a2s
>>> address = ("stomping.kinofnemu.net", 27015)
>>> a2s.info(address)
SourceInfo(protocol=17, server_name=" 24/7 Dustbowl :: Nemu's Stomping Ground", map_name='cp_dustbowl',
folder='tf', game='Team Fortress', app_id=440, player_count=31, max_players=33, bot_count=21,
server_type='d', platform='l', password_protected=True, vac_enabled=True, version='5579073',
edf=177, port=27015, steam_id=85568392920040090, stv_port=None, stv_name=None,
keywords='brutus,celt,couch,cp,dustbowl,increased_maxplayers,nemu,nocrits,nodmgspread,pony,replays,vanilla',
game_id=440, ping=0.253798684978392)

>>> a2s.players(address)
[Player(index=0, name='Brutus', score=34, duration=836.4749145507812),
 Player(index=0, name='RageQuit', score=6, duration=1080.8099365234375),
 Player(index=0, name="Screamin' Eagles", score=1, duration=439.8598327636719)]

>>> a2s.rules(address)
{'coop': '0', 'deathmatch': '1', 'decalfrequency': '10', 'metamod_version': '1.10.7-devV',
 'mp_allowNPCs': '1', 'mp_autocrosshair': '1', 'mp_autoteambalance': '0', 'mp_disable_respawn_times': '0',
 'mp_fadetoblack': '0'}

Tested Games

Team Fortress 2, Counter-Strike: Global Offensive

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-a2s-1.0.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

python_a2s-1.0.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file python-a2s-1.0.0.tar.gz.

File metadata

  • Download URL: python-a2s-1.0.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.6

File hashes

Hashes for python-a2s-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1c16b8f1bd97e847aa52f0a15723d6a893eb1771f048f20d85470b4ddd708c55
MD5 4e8215792a1c58abb305ad6dd93ac7bc
BLAKE2b-256 61ab39a5a444d54bd8d1801956671cc76468f8fa891620a52f8e1adecb4f3d8a

See more details on using hashes here.

File details

Details for the file python_a2s-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: python_a2s-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.6

File hashes

Hashes for python_a2s-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5499d559f5ae3f33c5279adda3d4fb32cbaa55ef410bb3262b82650c0c0564c0
MD5 e2e280c00f8425881a9c7af261276558
BLAKE2b-256 74537ec6cd946b635cb9c87ae65873909c6d2358715a3d89b855d0f20d287917

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page