Asynchronous python library for Steam authorization using protobuf
Project description
Asynchronous python library for Steam authorization using protobuf
Install
pip install pysteamauth
Usage
import asyncio
from pysteamauth.auth import Steam
async def main():
steam = Steam(
login='login',
password='password',
steamid=123456789,
)
await steam.login_to_steam()
result: bool = await steam.is_authorized()
await steam.request('https://steamcommunity.com')
await steam.request('https://store.steampowered.com')
await steam.request('https://help.steampowered.com')
if __name__ == '__main__':
asyncio.run(main())
If account have Steam Guard
from pysteamauth.auth import Steam, AuthenticatorData
steam = Steam(
login='login',
password='password',
steamid=123456789,
authenticator=AuthenticatorData(
shared_secret='shared_secret',
device_id='device_id',
identity_secret='identity_secret',
)
)
Cookie storage
Library uses default cookie storage BaseCookieStorage
, which stores Steam cookies in application memory.
But you can write own cookie storage. For example, redis storage:
import asyncio
import json
from typing import Dict
from aioredis import Redis
from pysteamauth.abstract import CookieStorageAbstract
from pysteamauth.auth import Steam
class RedisStorage(CookieStorageAbstract):
redis = Redis()
async def set(self, login: str, cookies: Dict) -> None:
await self.redis.set(login, json.dumps(cookies))
async def get(self, login: str, domain: str = 'steamcommunity.com') -> Dict:
cookies = await self.redis.get(login)
if not cookies:
return {}
return json.loads(cookies).get(domain, {})
async def main():
steam = Steam(
login='login',
password='password',
steamid=123456789,
cookie_storage=RedisStorage,
)
await steam.login_to_steam()
if __name__ == '__main__':
asyncio.run(main())
Error processing
import asyncio
from pysteamauth.auth import Steam
from pysteamauth.errors import SteamError
async def main():
try:
await Steam('login', 'password', 123456789).login_to_steam()
except SteamError as error:
print(error)
if __name__ == '__main__':
asyncio.run(main())
Or
import asyncio
from pysteamauth.auth import Steam
from pysteamauth.errors import SteamError, custom_error_exception
class LoginError(SteamError):
...
class RateLimitExceeded(SteamError):
...
# Error codes are stored in pysteamauth.errors
custom_error_exception({
5: LoginError,
84: RateLimitExceeded,
})
async def main():
try:
await Steam('login', 'password', 123456789).login_to_steam()
except LoginError as error:
print(error)
if __name__ == '__main__':
asyncio.run(main())
Output
{'error': 'InvalidPassword', 'code': 5}
Proto files
- https://github.com/SteamDatabase/Protobufs/blob/master/steam/enums.proto
- https://github.com/SteamDatabase/Protobufs/blob/master/steam/steammessages_base.proto
- https://github.com/SteamDatabase/Protobufs/blob/master/steam/steammessages_auth.steamclient.proto
- https://github.com/SteamDatabase/Protobufs/blob/master/steam/steammessages_unified_base.steamclient.proto
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pysteamauth-0.0.5.tar.gz
(34.7 kB
view hashes)
Built Distribution
Close
Hashes for pysteamauth-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb4b8163a22b03b217049d81c4f1145a35e12f5d279b36f6af402f427cb9ae58 |
|
MD5 | a0776fc6021ff02741f8a3ad74893c47 |
|
BLAKE2b-256 | 029fbc5f4112eabc48f6c40a5cb19166270b28cd98e13255811932f95a765789 |