# steampy
**Repository Path**: chancedoor/steampy
## Basic Information
- **Project Name**: steampy
- **Description**: No description available
- **Primary Language**: Python
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 2
- **Created**: 2022-03-09
- **Last Updated**: 2022-03-10
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
Steam Trade Offers Client for Python
=======
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XC8BMJ8QRD9ZY "Donate to this project via PayPal")
[](https://blockchain.info/payment_request?address=3FCe4D73J7tJ1zH2Q8NM3xnEeLsevvX3jR&message=Development+of+steampy&amount_local=12¤cy=USD&nosavecurrency=true "Donate to this project via Bitcoin")
`steampy` is a library for Python, inspired by node-steam-tradeoffers, node-steam and other libraries for Node.js.
It was designed as a simple lightweight library, combining features of many steam libraries from Node.js into a single python module.
`steampy` is capable of logging into steam, fetching trade offers and handling them in simple manner, using steam user credentials
and SteamGuard file(no need to extract and pass sessionID and webCookie).
`steampy` is developed with Python 3 using type hints and many other features its supported for Windows, Linux and MacOs.
Table of Content
================
* [Installation](https://github.com/bukson/steampy#installation)
* [Usage](https://github.com/bukson/steampy#usage)
* [Examples](https://github.com/bukson/steampy#examples)
* [SteamClient methods](https://github.com/bukson/steampy#steamclient-methods)
* [Market methods](https://github.com/bukson/steampy#market-methods)
* [Guard module functions](https://github.com/bukson/steampy#guard-module-functions)
* [SteamChat methods](https://github.com/bukson/steampy#steamchat-methods)
* [Test](https://github.com/bukson/steampy#test)
* [License](https://github.com/bukson/steampy#license)
Installation
============
```
pip install steampy
```
Usage
=======
[Obtaining API Key](http://steamcommunity.com/dev/apikey)
[Obtaining SteamGuard from mobile device]( https://github.com/SteamTimeIdler/stidler/wiki/Getting-your-%27shared_secret%27-code-for-use-with-Auto-Restarter-on-Mobile-Authentication )
[Obtaining SteamGuard using Android emulation]( https://github.com/codepath/android_guides/wiki/Genymotion-2.0-Emulators-with-Google-Play-support)
```python
from steampy.client import SteamClient
steam_client = SteamClient('MY_API_KEY')
steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE/DICT')
```
If you have `steamid`, `shared_secret` and `identity_secret` you can place it in file `Steamguard.txt` instead of fetching SteamGuard file from device or pass directly to method as dict below:
```python
{
"steamid": "YOUR_STEAM_ID_64",
"shared_secret": "YOUR_SHARED_SECRET",
"identity_secret": "YOUR_IDENTITY_SECRET"
}
```
Examples
========
You'll need to obtain your API key and SteamGuard file in order to run the examples,
and then fill login and password in `storehose.py` file.
The `storehouse.py` file contains an example of handling incoming trade offers.
```
python storehouse.py
```
If you want to generate authentication codes and use steampy as steam desktop authenticator
then fill required secrets in `desktop_authenticator.py` file.
The `desktop_authenticator.py` file contains examples of generating such one time codes/
```
python desktop_authenticator.py
```
SteamClient methods
===================
Unless specified in documentation, the method does not require login to work(it uses API Key from constructor instead)
**login(username: str, password: str, steam_guard: str or dict) -> requests.Response**
Log into the steam account. Allows to accept trade offers and some other methods.
```python
from steampy.client import SteamClient
steam_client = SteamClient('MY_API_KEY')
steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE/DICT')
```
You can also use `with` statement to automatically login and logout.
```python
with SteamClient(api_key, login, password, steam_guard_file_or_dict) as client:
client.some_method1(...)
client.some_method2(...)
...
```
**logout() -> None**
Using `SteamClient.login` method is required before usage
Logout from steam.
```python
from steampy.client import SteamClient
steam_client = SteamClient('MY_API_KEY')
steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE/DICT')
steam_client.logout()
```
You can also use `with` statement to automatically login and logout.
```python
with SteamClient(api_key, login, password, steam_guard_file_or_dict) as client:
client.some_method1(...)
client.some_method2(...)
...
```
**is_session_alive() -> None**
Using `SteamClient.login` method is required before usage
Check if session is alive. This method fetches main page and check
if user name is there. Thanks for vasia123 for this solution.
```python
from steampy.client import SteamClient
steam_client = SteamClient('MY_API_KEY')
steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE/DICT')
is_session_alive = steam_client.is_session_alive()
```
**api_call(request_method: str, interface: str, api_method: str, version: str, params: dict = None) -> requests.Response**
Directly call api method from the steam api services.
[Official steam api site](https://developer.valvesoftware.com/wiki/Steam_Web_API)
[Unofficial but more elegant](https://lab.xpaw.me/steam_api_documentation.html)
```python
from steampy.client import SteamClient
steam_client = SteamClient('MY_API_KEY')
params = {'key': 'MY_API_KEY'}
summaries = steam_client.api_call('GET', 'IEconService', 'GetTradeOffersSummary', 'v1', params).json()
```
**get_trade_offers_summary() -> dict**
**get_trade_offers(merge: bool = True) -> dict**
Fetching trade offers from steam using an API call.
Method is fetching offers with descriptions that satisfy conditions:
* Are sent by us or others
* Are active (means they have `trade_offer_state` set to 2 (Active))
* Are not historical
* No time limitation
If `merge` is set `True` then offer items are merged from items data and items description into dict where items `id` is key
and descriptions merged with data are value.
**get_trade_offer(trade_offer_id: str, merge: bool = True) -> dict**
**get_trade_receipt(trade_id: str) -> list**
Using `SteamClient.login` method is required before usage
Getting the receipt for a trade with all item information after the items has been traded.
Do NOT store any item ids before you got the receipt since the ids may change.
"trade_id" can be found in trade offers: `offer['response']['offer']['tradeid']`. Do not use ´tradeofferid´.
**make_offer(items_from_me: List[Asset], items_from_them: List[Asset], partner_steam_id: str, message:str ='') -> dict**
Using `SteamClient.login` method is required before usage
`Asset` is class defined in `client.py`, you can obtain `asset_id` from `SteamClient.get_my_inventory` method.
This method also uses identity secret from SteamGuard file to confirm the trade offer.
No need to manually confirm it on mobile app or email.
This method works when partner is your friend or steam.
In returned dict there will be trade offer id by the key `tradeofferid`.
```python
from steampy.client import SteamClient, Asset
from steampy.utils import GameOptions
steam_client = SteamClient('MY_API_KEY')
steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE/DICT')
partner_id = 'PARTNER_ID'
game = GameOptions.CS
my_items = steam_client.get_my_inventory(game)
partner_items = steam_client.get_partner_inventory(partner_id, game)
my_first_item = next(iter(my_items.values()))
partner_first_item = next(iter(partner_items.values()))
my_asset = Asset(my_first_item['id'], game)
partner_asset = Asset(partner_first_item['id'], game)
steam_client.make_offer([my_asset], [partner_asset], partner_id, 'Test offer')
```
**make_offer_with_url(items_from_me: List[Asset], items_from_them: List[Asset], trade_offer_url: str, message: str = '', case_sensitive: bool = True) -> dict**
Using `SteamClient.login` method is required before usage
This method is similar to `SteamClient.make_offer`, but it takes trade url instead of friend account id.
It works even when partner isn't your steam friend
In returned dict there will be trade offer id by the key `tradeofferid`.
If `case_sensitive` is False, then url params with be parsed with case insensitive params keys.
**get_escrow_duration(trade_offer_url: str) -> int**
Using `SteamClient.login` method is required before usage
Check the escrow duration for trade between you and partner(given partner trade offer url)
**accept_trade_offer(trade_offer_id: str) -> dict**
Using `SteamClient.login` method is required before usage
This method also uses identity secret from SteamGuard file to confirm the trade offer.
No need to manually confirm it on mobile app or email.
**decline_trade_offer(trade_offer_id: str) -> dict**
Decline trade offer that **other** user sent to us.
**cancel_trade_offer(trade_offer_id: str) -> dict**
Cancel trade offer that **we** sent to other user.
**get_my_inventory(game: GameOptions, merge: bool = True, count: int = 5000) -> dict**
Using `SteamClient.login` method is required before usage
If `merge` is set `True` then inventory items are merged from items data and items description into dict where items `id` is key
and descriptions merged with data are value.
`Count` parameter is default max number of items, that can be fetched.
Inventory entries looks like this:
```python
{'7146788981': {'actions': [{'link': 'steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S%owner_steamid%A%assetid%D316070896107169653',
'name': 'Inspect in Game...'}],
'amount': '1',
'appid': '730',
'background_color': '',
'classid': '1304827205',
'commodity': 0,
'contextid': '2',
'descriptions': [{'type': 'html',
'value': 'Exterior: Field-Tested'},
{'type': 'html', 'value': ' '},
{'type': 'html',
'value': 'Powerful and reliable, the AK-47 '
'is one of the most popular assault '
'rifles in the world. It is most '
'deadly in short, controlled bursts '
'of fire. It has been painted using '
'a carbon fiber hydrographic and a '
'dry-transfer decal of a red '
'pinstripe.\n'
'\n'
'Never be afraid to push it to '
'the limit'},
{'type': 'html', 'value': ' '},
{'app_data': {'def_index': '65535',
'is_itemset_name': 1},
'color': '9da1a9',
'type': 'html',
'value': 'The Phoenix Collection'},
{'type': 'html', 'value': ' '},
{'app_data': {'def_index': '65535'},
'type': 'html',
'value': '