-
Notifications
You must be signed in to change notification settings - Fork 0
SteamID
steam.steamid.SteamID converts between every representation of a Steam identifier:
-
32-bit account id —
76580(just the account number). -
64-bit "steam64" —
76561197960342308(universe + type + instance + account). -
Steam2 —
STEAM_1:0:38290(with the GoldSrcSTEAM_0:...variant). -
Steam3 —
[U:1:76580](also[G:...],[g:...],[T:...], etc for other entity types). -
Community URL —
https://steamcommunity.com/profiles/76561197960342308or.../id/vanityurl. -
s.team invite code —
cv-dgb. -
CS:GO friend code —
AEBJA-ABDC.
SteamID is a subclass of int — anywhere Steam wants a 64-bit id, you can pass a SteamID directly.
from steam.steamid import SteamID
SteamID() # invalid (universe=Invalid, type=Invalid)
SteamID(76580) # bare 32-bit account id
SteamID('76580') # same, as string
SteamID(76561197960342308) # 64-bit steam64
SteamID('76561197960342308') # same, as string
SteamID('STEAM_1:0:38290') # steam2
SteamID('STEAM_0:0:38290') # steam2 GoldSrc (universe defaults to Public)
SteamID('[U:1:76580]') # steam3
SteamID('[g:1:4]') # steam3 clan
SteamID(id=76580, type='Individual', universe='Public', instance=1) # keyword form
SteamID(id=76580, type=EType.Individual, universe=EUniverse.Public) # enum formAny format goes in, int(...) comes out as steam64.
SteamID(*args, **kwargs)
Handles all of the forms above via make_steam64(). Positional args after the first (id) are (type), (type, universe), or (type, universe, instance). Kwargs override positional: type=, universe=, instance=.
Every conversion lives as a read-only property on the instance:
-
.id/.account_id— 32-bit account id (int). -
.as_32— same as.id, semantic name for the 32-bit representation. -
.as_64— 64-bit int form (also justint(sid)). -
.as_steam2—"STEAM_1:0:38290". -
.as_steam2_zero—"STEAM_0:0:38290"(GoldSrc / Orange Box). -
.as_steam3—"[U:1:76580]". Handles clan (g), chat (T,c,L), and anon-gameserver instance-included variants. -
.as_invite_code—"cv-dgb". Only defined forIndividualtype + valid ids. -
.as_csgo_friend_code—"AEBJA-ABDC". Only defined forIndividualtype + valid ids. -
.invite_url—"https://s.team/p/cv-dgb"for the invite code. -
.community_url—"https://steamcommunity.com/profiles/76561197960342308"for individuals,.../gid/...for clans. -
.type—ETypeenum member. -
.universe—EUniverseenum member. -
.instance— 20-bit int.
The relevant enums are re-exported off SteamID:
SteamID.EType # Individual, Multiseat, GameServer, AnonGameServer, Pending,
# ContentServer, Clan, Chat, ConsoleUser, AnonUser
SteamID.EUniverse # Invalid, Public, Beta, Internal, Dev, Max
SteamID.EInstanceFlag # Clan, Lobby, MMSLobbyParse a cv-dgb / https://s.team/p/cv-dgb string back into a SteamID.
sid = SteamID.from_invite_code('cv-dgb')Returns None if the code is malformed. Also exposed as the module-level from_invite_code().
Parse a CS:GO friend code back into a SteamID.
sid = SteamID.from_csgo_friend_code('AEBJA-ABDC')Given a Steam community URL, resolve it to a SteamID. Handles:
https://steamcommunity.com/profiles/{steam64}https://steamcommunity.com/profiles/{steam3}https://steamcommunity.com/id/{vanityurl}https://steamcommunity.com/gid/{steam64_or_steam3}https://steamcommunity.com/groups/{groupname}https://steamcommunity.com/user/{invitecode}
sid = SteamID.from_url('https://steamcommunity.com/id/valve')Warning: each call is an HTTP fetch to steamcommunity.com. For reliable production use, prefer WebAPI.ISteamUser.ResolveVanityURL(vanityurl='...') — see WebAPI.
Returns None if the URL can't be resolved.
sid.is_valid()Returns True if the id parses into a plausible Steam identity — universe not Invalid, type not Invalid, instance ≤ 4, account id > 0, etc. Full logic in steam/steamid.py.
from steam.steamid import SteamID
# Someone gave you STEAM_1:0:38290 in a chat log.
sid = SteamID('STEAM_1:0:38290')
# Turn it into every other form.
sid.as_64 # 76561197960342308
sid.as_steam3 # '[U:1:76580]'
sid.community_url # 'https://steamcommunity.com/profiles/76561197960342308'
sid.as_invite_code # 'cv-dgb'
# Pass it anywhere Steam wants a 64-bit int.
resp = api.ISteamUser.GetPlayerSummaries(steamids=str(sid))- Resolving a vanity URL reliably? Use WebAPI's
ISteamUser.ResolveVanityURLinstead ofSteamID.from_url— no scraping, no rate-limit surprises. - Working with community group ids (
Clantype)?.community_urlgives you.../gid/...; instantiate viaSteamID('[g:1:4]')or the numeric form.
H47R15/steam — maintained fork of ValvePython/steam. MIT licensed.