Skip to content

First script

cbyte edited this page Jul 19, 2026 · 1 revision

First script

Two short examples to get you moving. The first hits the CM protocol via SteamClient. The second stays on HTTP and only uses WebAPI — no gevent, no client extra.

1. Anonymous PICS lookup (SteamClient)

The shortest complete flow — connect anonymously, request public product info, log out.

from steam.client import SteamClient

client = SteamClient()
assert client.anonymous_login()
resp = client.get_product_info(apps=[553850], timeout=15)  # Helldivers 2
print(resp['apps'][553850]['common']['name'])
client.logout()
client.disconnect()

Expected output:

HELLDIVERS 2

Walking through it line by line:

  1. SteamClient() — instantiates the client. No network yet; this just wires up the event emitter and mixin state.

  2. client.anonymous_login() — resolves a CM (connection manager) server, opens a TCP connection, performs the handshake, and issues an anonymous ClientLogon message. Returns an EResult. Anonymous is enough for public metadata like PICS. See SteamClient for the credential login flavours.

  3. client.get_product_info(apps=[553850], timeout=15) — issues ClientPICSProductInfoRequest and blocks until all response chunks arrive. 553850 is the appid for Helldivers 2 — swap in whatever appid you care about. The return value is a dict keyed by appid; the parsed VDF payload lives under ['apps'][appid].

    Signature: get_product_info(apps=[], packages=[], meta_data_only=False, raw=False, auto_access_tokens=True, timeout=15)

  4. resp['apps'][553850]['common']['name'] — reads the game's display name from Steam's canonical common block. There's a lot more in the response (extended, depots, config, ufs, …); print resp['apps'][553850].keys() to explore.

  5. client.logout() followed by client.disconnect() — Steam's CM drops the connection as soon as ClientLogOff is acknowledged, but calling disconnect() afterwards guarantees the local socket + gevent loop are torn down cleanly.

2. Server info via WebAPI (no login)

Some endpoints don't need a key or an authenticated session. ISteamWebAPIUtil.GetServerInfo is one of them — a great "is the connection working" ping:

from steam.webapi import get

resp = get('ISteamWebAPIUtil', 'GetServerInfo', 1)
print(resp)

Expected output:

{'servertime': 1721406000, 'servertimestring': 'Fri Jul 19 15:00:00 2026'}

Or via the class-based interface, which auto-discovers every method Steam exposes:

from steam.webapi import WebAPI

api = WebAPI(key=None)  # None is fine — GetServerInfo is unauthenticated
print(api.ISteamWebAPIUtil.GetServerInfo())

If you have a key, resolve a vanity URL:

api = WebAPI(key='YOUR_KEY_HERE')
resp = api.ISteamUser.ResolveVanityURL(vanityurl='valve', url_type=2)
print(resp)   # -> {'response': {'steamid': '103582791429521412', 'success': 1}}

Get a key from steamcommunity.com/dev/apikey. Full details on WebAPI.

Next steps

  • Real login (credentials + 2FA): SteamClient → the "Login" section.
  • Session cookies for the storefront: WebAuth.
  • Downloading depot files: CDNClient — needs a logged-in client with a game license.
  • Anything id-related: SteamID — pass any format in, get any format out.

Clone this wiki locally