utils
Utility package with various useful functions
- steam.utils.chunks(arr, size)
Splits a list into chunks
- class steam.utils.WeakRefKeyDict
Bases:
objectPretends to be a dictionary. Use any object (even unhashable) as key and store a value. Once the object is garbage collected, the entry is destroyed automatically.
utils.appache
Appache file parsing examples:
>>> from steam.utils.appcache import parse_appinfo, parse_packageinfo
>>> header, apps = parse_appinfo(open('/d/Steam/appcache/appinfo.vdf', 'rb'))
>>> header
{'magic': b"(DV\x07", 'universe': 1}
>>> next(apps)
{'appid': 5,
'size': 79,
'info_state': 1,
'last_updated': 1484735377,
'access_token': 0,
'sha1': b'\x87\xfaCg\x85\x80\r\xb4\x90Im\xdc}\xb4\x81\xeeQ\x8b\x825',
'change_number': 4603827,
'data_sha1': b'\x87\xfaCg\x85\x80\r\xb4\x90Im\xdc}\xb4\x81\xeeQ\x8b\x825',
'data': {'appinfo': {'appid': 5, 'public_only': 1}}}
>>> header, pkgs = parse_packageinfo(open('/d/Steam/appcache/packageinfo.vdf', 'rb'))
>>> header
{'magic': b"'UV\x06", 'universe': 1}
>>> next(pkgs)
{'packageid': 7,
'sha1': b's\x8b\xf7n\t\xe5 k#\xb6-\x82\xd2 \x14k@\xfeDQ',
'change_number': 7469765,
'data': {'7': {'packageid': 7,
'billingtype': 1,
'licensetype': 1,
'status': 0,
'extended': {'requirespreapproval': 'WithRedFlag'},
'appids': {'0': 10, '1': 80, '2': 100, '3': 254430},
'depotids': {'0': 0, '1': 95, '2': 101, '3': 102, '4': 103, '5': 254431},
'appitems': {}}}}
utils.binary
- class steam.utils.binary.StructReader(data)
Bases:
objectSimplifies parsing of struct data from bytes
- Parameters:
data (
bytes) – data bytes
- rlen()
Number of remaining bytes that can be read
- Returns:
number of remaining bytes
- Return type:
- read(n=1)
Return n bytes
- read_cstring(terminator=b'\x00')
Reads a single null termianted string
- Returns:
string without bytes
- Return type:
- unpack(format_text)
Unpack bytes using struct modules format
- Parameters:
format_text (
str) – struct’s module format- Return data:
result from
struct.unpack_from()- Return type:
utils.proto
utils.throttle
- class steam.utils.throttle.ConstantRateLimit(times, seconds, exit_wait=False, sleep_func=<built-in function sleep>)
Bases:
objectContext manager for enforcing constant rate on code inside the block .
rate = seconds / times
- Parameters:
Example:
with RateLimiter(1, 5) as r: # code taking 1s r.wait() # blocks for 4s # code taking 7s r.wait() # doesn't block # code taking 1s r.wait() # blocks for 4s
- wait()
Blocks until the rate is met