smiley / steamapi Goto Github PK
View Code? Open in Web Editor NEWAn unofficial object-oriented Python library for accessing the Steam Web API.
License: MIT License
An unofficial object-oriented Python library for accessing the Steam Web API.
License: MIT License
Right now, the master branch only supports the Singleton-based APIConnection
to call the API, and the user needs to know ahead the entire API path to call it.
This isn't too friendly because you still need to open the API documentation to know what's what, and that isn't in line with SteamAPI's original goal: fast, easy development & prototyping.
GetSupportedAPIList (ISteamWebAPIUtil::GetSupportedAPIList(void)
) returns an entire, gigantic list of APIs the given key can access, and potentially this also exposes publisher-restricted APIs -- so if a game developer or publisher calls this API, they'd get more APIs only available to them.
This is ideal, and should be implemented as the new, uniform way of talking to the API (underneath the SteamApp
, SteamUser
and other classes, of course).
When the API is asked for the user's profile visibility setting, some "Public" and "Friends Only" profiles return "Friends of Friends". Mine is a good example:
>>> me = user.SteamUser(76561197996416028)
>>> me.privacy
3 # = FRIENDS_OF_FRIENDS. should be 5, which is PUBLIC
This is a known issue with the API. It can only be fixed server-side.
Currently, a lot of information dropped out of GetUserStatsForGame response. Only achievements are used.
But there is more useful information for some games in 'playerstats'.
Was trying to create a pull request with that tweak :)
There's currently no officially supported way for third-party developers to ask Steam, programmatically, for product details. For example, there's no way to ask "Team Fortress 2" and get the appid "440" in return.
However, there is the Big Picture API, which uses standard HTTP. I've avoided implementing that because it is, after all, a private API that can change at all times. Even worse, since Steam auto-updates and requires having the latest version to connect, Valve can change the entire Big Picture API layout overnight and not break a single thing.
But it also seems pretty stable. SteamDB uses this for live store data and by the looks of it (no further posts about it) they didn't run into any private-API issues.
So it comes down to thinking it through (and hopefully hearing someone else's opinion on this -- this is your cue watchers/starrers!).
I'm trying to check the state property of a user and I believe i'm getting the cached version of the property. I read in your documentation "to expire a cached property value manually just do::
del instance._cache[property name]", however I seem to not be able to refresh it. Sorry, i'm new to programming and don't really understand this concept.
So I've been toying with this api for a while and its pretty cool! I'm trying to build a small app that tells a user their top 5 rarest achievements. I'm running into an issue though with getting the achievement attribute, where if the game doesn't have achievements it will give a key error. However any checks I do to make sure the attribute exists or than it is a length greater than 0 don't work. Please if you have any input let me know!
Hello, first off I'm extremely new to GitHub so I hope I'm doing this properly. Second, I've noticed that recently_played only shows the games that were recently played and not the amount of time played in the past two weeks (or the total amount played). Is there any way to access this through steamapi? Thank you!
The use of @Property in this code has any other objective other then make the attribute 'read-only' by the caller? If the only use is the above it's really not pythonic and non-sense to use it.
When I was making some codes I asked many senior python devs and they all said that no matter what we do to make our code the most "private" and secure, the user will always have access to everything, after all, this is Python.
It's read-only if the user cals directly 'usr.id', but if he trully want to mess with the code he can call 'usr._id' , 'usr._summary.loccountrycode', '.usr._summary.realname', and so on, and have all access.
This kind of approach isn't good for Python, as it make the code long and it really doesn't change much. A common thinking in Python is "we're all consenting adults here".
More info:
https://mail.python.org/pipermail/tutor/2003-October/025932.html
http://blog.startifact.com/posts/older/what-is-pythonic.html
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
So, I suggest that you change the approach regaring the use of @Property to make the code more slim and pythonic.
After installing and importing the library (which both give no errors, requests 2.8.13 is installed) I get the following error when connecting to the API like this:
steamapi.core.APIConnection(api_key="<API-KEY>", validate_key=True)
(Btw I changed the API-Key to a placeholder here)
Traceback (most recent call last):
File "test.py", line 3, in <module>
steamapi.core.APIConnection(api_key="<API-KEY>", validate_key=True)
File "C:\localstore\python\3.6.2\lib\site-packages\steamapi-0.1-py3.6.egg\steamapi\decorators.py", line 117, in __call__
self._instance = self._decorated(*args, **kwargs)
File "C:\localstore\python\3.6.2\lib\site-packages\steamapi-0.1-py3.6.egg\steamapi\core.py", line 408, in __init__
self.call("ISteamWebAPIUtil", "GetSupportedAPIList", "v1")
File "C:\localstore\python\3.6.2\lib\site-packages\steamapi-0.1-py3.6.egg\steamapi\core.py", line 462, in call
response_obj = response.json()
File "C:\localstore\python\3.6.2\lib\site-packages\requests-2.18.3-py3.6.egg\requests\models.py", line 892, in json
return complexjson.loads(self.text, **kwargs)
File "C:\localstore\python\3.6.2\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\localstore\python\3.6.2\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\localstore\python\3.6.2\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I'm using python version 3.6.x 32 and 64bit. I have tried this on 3 different windows PCs. 1 works and 2 don't. So far no idea why.
I see that you can supply the argument userurl="smileybarry", ex: steamapi.user.SteamUser(userurl="smileybarry"), and also the 64 bit user id, ex: steamapi.user.SteamUser(76561197996416028, but the type of ID I want to supply is the one that shows in this format: STEAM_0:X:XXXXXX
I want to do this because that number basically reflects the timeframe in which the account was made, as these numbers are assigned incrementally. The thousandth Steam user would have SteamID STEAM_0:0:1000, I believe.
I can't find any further documentation on the arguments that can be supplied here. All I know is from the readme. Hope this makes sense.
https://partner.steamgames.com/doc/webapi/IPlayerService#GetOwnedGames
The image URL is part of the API response when requesting owned games.
Example Code:
#!/usr/bin/env python
from steamapi import core, user
core.APIConnection(api_key="APIKEYHERE")
steam_user = user.SteamUser(userid=USERIDHERE)
name = steam_user.name
# List all the attributes
thestuff = dir(steam_user.games[0])
print(thestuff)
This will list the following:
python list_dict.py
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_cache', '_id', '_owner', '_schema', '_userid', 'achievements', 'appid', 'from_api_response', 'id', 'name', 'owner', 'playtime_forever']
Is there anyway to grab that part of the API response with smiley/steamapi?
I am suggesting to support the package through pypi, so installation as well as distribution is easier.
Currently installing this package otherwise is just unnecessary complicated.
The package could even be tagged as alpha and nicht production ready.
If requested I could modify the setup.py accordingly.
hi when i launch the file storehouse.py i got this error (i'm on unbuntu)
Traceback (most recent call last):
File "storehouse.py", line 47, in
main()
File "storehouse.py", line 21, in main
client.login(username, password, steamguard_path)
File "/home/thomas/.local/lib/python3.5/site-packages/steampy/client.py", line 76, in login
LoginExecutor(username, password, self.steam_guard['shared_secret'], self._session).login()
File "/home/thomas/.local/lib/python3.5/site-packages/steampy/login.py", line 24, in login
self._check_for_captcha(login_response)
File "/home/thomas/.local/lib/python3.5/site-packages/steampy/login.py", line 67, in _check_for_captcha
raise CaptchaRequired('Captcha required')
steampy.login.CaptchaRequired: Captcha required
Do you think you could either implement a game search function or an array of all games? (preferably the former, for speed ๐)
Wasn't able to find it using dir(steamapi.app)
, but I apologize if it's already there... although this is in desperate need of documentation.
Do you know way to get tags from steam page of game? Can you add this?
TypeError(repr(o) + " is not JSON serializable")
TypeError: <SteamApp "Need for Speed: Undercover" (17430)> is not JSON serializable
When i try make json.loads(me.games) from example i have error.
json.dumps(me.games) dosen`t help. thx. ?
Is there in lib somthin like (steamapi.user.SteamUser(userurl='test',format='json') ?
Python Package Index (https://pypi.python.org/pypi)
It will be a lot easier for everyone using this API to have it on PyPI, so that people can easily install it using 'pip install steamapi'.
Using this code, i can get user name, user level, but can't get user's friends list, getting error steamapi.errors.APIUnauthorized: This API is not accessible to you.
import steamapi
from steamapi import core, user
steamapi.core.APIConnection(api_key="<api key>", validate_key=True)
print(steamapi.user.SteamUser(<steamid>)
steam_user = user.SteamUser(userid=<steamid>)
print(steam_user.level)
print(steam_user.friends)
Hi, first off I want to thank you for this great tool you have created, it has helped me immensely with my current project I am working on! However, I noticed that you are missing a feature that however very specific, was a major roadblock in the development of my project. I needed a way to quickly access the tags for a specified list of games, and I couldn't find any way to do that with your interface or anything on the web. So in order to fix this I created a python script that created a database file of all games on steam and their tags. I plan on either hosting off my computer, or some free random hosting service, this database in an easily accessible way for use in my project, and think it could be a valuable addition to your tool to be able to add the tags of a game to its steamapp object. Here is a link to the code that creates the db https://github.com/BronxBombers/Steam-Tags-Database if you are interested in adding this to your project let me know and I can give you a link to wherever I decide to host it to, and I could also code the implementation to your system for you if ya wanted.
Seems like project not updating anymore but i need it right now so, its still working?
Hi, I had problems with installation.
I tried some ways to install it, but it doesn't installed.
Can you write a command (and in README too, I think) to install steamapi
?
Is there a way to print what server IP a user is on? It's so I can make a script do something like this:
What is your SteamID? : CultureCoder
Game information:
Counter-Strike Source
82.39.79.142:27015
Thanks!
Richard.
Hello,Bro. I'm very happy to see your great project. Recently, I'm establishing a tool for full body tracking. And I want to implement a function that my users can go shopping in my application.However,I tried to get responses from steamwork web api which is 'https://partner.steam-api.com/ISteamMicroTxnSandBox/InitTxn/v3/'. I could enture that I get the true responses which include a url. But when I linked this url, It is always failed to load, and display a information that is 'Sorry for the transaction authorization error, please try again'. How can I solve it ? If you could help me ,I would be very very very grateful !!!
What am I doing wrong here?
>>> import steamapi
>>> steamapi.core.APIConnection(api_key="my API key")
# object gets created
>>> steamapi.user.SteamUser(userurl='my userid`)
steamapi.errors.APIPRIVATE
`
How we can send messages our friends ? Or delete & add requests to others.
Does the current state of the api support Python 3.5? I forked this and plan to make updates to possibly support async from PY35, if time permits!
As more and more issues in making this object-oriented become apparent, a suggested solution would be to use caching on actual API calls: If the exact same call is done before a specified time has passed, a cached copy of the API call should be given instead.
Certainly better than Singletons and two-way binding things...
Can't understand why, the api download everyone else's steam information but if i ask my account info the api give some errors as:
\steamapi\decorators.py", line 67, in __get__
value, last_update = inst._cache[self.__name__]
AttributeError: 'SteamApp' object has no attribute '_cache'
During handling of the above exception, another exception occurred:
\steamapi\errors.py", line 107, in check
raise APIPrivate("You have no permission to use this API, or your key may be invalid.")
steamapi.errors.APIPrivate: You have no permission to use this API, or your key may be invalid.
I already tried with my Id64 instead of Profile URL Id, can't understand where is the problem
This is a copy of the full error log:
FullError.txt
Some of the code -- as shown in #16 -- doesn't work in Python 3.x, while some doesn't act as expected. This includes:
dict.keys()
in returns a dict_keys
object that can't be accessed by-index. (#16)errors.py:76
causing all checks in raiseAppropriateException
to fail and, consequently, raise a debug exception thrown by debug.no_return
.SteamObject.__repr__
causes the resulting string to be a bytes
object instead and end up ..."b'Smiley'"...
instead of ..."Smiley"...
.range
instead of xrange
(xrange
became range
on 3.x, theoretical performance changes on 2.x are acceptable)This needs to be fixed as soon as possible, since Python 3 is very much in use and considered standard Python.
Can you give me example?
Code:
import steamapi
import pprint
steamapi.core.APIConnection(api_key="B9XXXXXX20")
usr = steamapi.user.SteamUser(76561198067618735)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(usr.friends)
Traceback:
Traceback (most recent call last):
File "C:\Development\Languages\Python34\lib\site-packages\steamapi-0.1-py3.4.egg\steamapi\decorators.py", line 67, in
__get__
value, last_update = inst._cache[self.__name__]
AttributeError: 'SteamUser' object has no attribute '_cache'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Documents\HomeBroker\main.py", line 9, in <module>
pp.pprint(usr.friends)
File "C:\Development\Languages\Python34\lib\site-packages\steamapi-0.1-py3.4.egg\steamapi\decorators.py", line 71, in
__get__
value = self.fget(inst)
File "C:\Development\Languages\Python34\lib\site-packages\steamapi-0.1-py3.4.egg\steamapi\user.py", line 322, in frien
ds
chunks = [ids[start:start+CHUNK_SIZE] for start in range(len(ids))[::CHUNK_SIZE]]
File "C:\Development\Languages\Python34\lib\site-packages\steamapi-0.1-py3.4.egg\steamapi\user.py", line 322, in <list
comp>
chunks = [ids[start:start+CHUNK_SIZE] for start in range(len(ids))[::CHUNK_SIZE]]
TypeError: 'dict_keys' object is not subscriptable
See #61
Their doesn't appear to be any sort of guidelines for the code base which leads to some confusing formatting as seen in the pull above.
I would suggest standardizing in some way.
Going with Pep8 is an easy choice and is often well integrated into many editors.
When APIResponse is given a dictionary to wrap, if one of the values (wherever in the tree) is a list of non-dictionary objects, wrapping breaks because of trying to enumerate it like a dictionary.
We either get an error for wrongful iteration ("string indices must be integers, not str") or an error for even trying to iterate. ("'int' object is not iterable")
This can be reproduced with either example:
>>> from steamapi import *
>>> core.APIResponse({'a': 1, 'b': 2, 'c': ['this', 'will', 'break']})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "steamapi\core.py", line 433, in __init__
self._real_dictionary[item] = [APIResponse(entry) for entry in father_dict[item]]
File "steamapi\core.py", line 430, in __init__
if type(father_dict[item]) is dict:
TypeError: string indices must be integers, not str
>>> from steamapi import *
>>> core.APIResponse({'a': 1, 'b': 2, 'c': [123]})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "steamapi\core.py", line 433, in __init__
self._real_dictionary[item] = [APIResponse(entry) for entry in father_dict[item]]
File "steamapi\core.py", line 429, in __init__
for item in father_dict:
TypeError: 'int' object is not iterable
I can't find a way to retrieve the user's description (or Summary) on their profile.
Today, the Steam Web API experienced some serious outage. Requests took as long as 20 seconds and multiple retransmissions throughout the connection to complete, severely crippling any interactivity this library usually provides.
This signals a need for full serialization and support for "offline objects", meaning Steam API objects which either don't automatically request data from the server, or request it asynchronously and return the old data in the meantime.
This also means gevent
should be looked into again as an asynchronous solution, since requests
natively supports it for async requests.
"is_unlocked" fetches the entire achievement unlocks list for its game, then only uses its own value. While this value is then cached (so the same achievement's status doesn't change as long as the achievements list isn't re-fetched), asking another achievement the same thing will cause unnecessary slowdowns.
There needs to be a way to fetch achievements for an entire game, not through the game object itself. Maybe two-way binding is the right solution, but that might screw up garbage collection.
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 18, in <module>
install_requires=local_requirements(),
File "setup.py", line 8, in local_requirements
return [str(ir.req) for ir in install_reqs]
File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1240, in parse_requirements
skip_regex = options.skip_requirements_regex
AttributeError: 'NoneType' object has no attribute 'skip_requirements_regex'
I will do a pull request for a fix.
I am planing to make a game blocker which blocks the game after some time of use . And i need some help with that. So first i was planning to write a script with py autogui and make a .bat file to launch the python script with the game but I thought maybe i can use the current session time to monitor and close the game. can someone help me on how to get the current session time. Thanks in advance!
im trying to figure out how to make it return just the Game name but I am having a hard time
APIs like SteamApp(...).achievements are becoming expensive with more and more functionality split into different API functions. ".achievements" requires 2 API calls if the game isn't user-associated (=1-2 seconds) or 3 API calls if the game is associated (=2-3 seconds).
While production servers might not experience much due to having a superb connection (each API call will probably amount to <60msec rather than the 310+ msec I'm experiencing), semi-asynchronous, "combined" calls should be looked into.
The easiest solution would be to just call these APIs synchronously, but all at the same time, then wait on all as a group. Another possible solution would be to use lazy-initialized proxy objects to these responses and just keep going, causing in a non-blocking flow until the data is absolutely necessary.
Get summery of a specific friend?
Am I able to send chat messages to other users with this?
Just downloaded this amazing API and it says that I can't import 'core'.
steamapi.core.APIConnection(api_key=STEAM_API_KEY, validate_key=True) AttributeError: module 'steamapi' has no attribute 'core'
I tried :
import steamapi
from steamapi import *
-- Nothing.
and when I do
from steamapi import core
it says : ImportError: cannot import name 'core'
What should I do ? Thanks ^^
https://micheles.googlecode.com/hg/decorator/documentation3.html#definitions goes a bit into the problems it causes, same for the functools library
more practically: http://i.imgur.com/2vt7Awi.png (IPython) | http://i.imgur.com/kWO7AOK.png (dreampie
neither responses explain the interface of the actual function/class
this is probably fairly low priority, but it can be useful for IDEs / custom interpreters
might not be practical/useful once auto-populated interfaces become used more (unless the interfaces provide documentation)
In Recent times i somehow randomly get this error when creating instances in a loop, i tried deleting each instance in the end of the loop, which kinda reduced the problem to a decent to non existing level but didn't fix it.
Any Idea what causes the problem?
games = test.me.recently_played
File "C:\Python34\lib\site-packages\steamapi-0.1-py3.4.egg\steamapi\decorators.py", line 71, in __get__
value = self.fget(inst)
File "C:\Python34\lib\site-packages\steamapi-0.1-py3.4.egg\steamapi\user.py", line 372, in recently_played
return self._convert_games_list(response.games, self._id)
File "C:\Python34\lib\site-packages\steamapi-0.1-py3.4.egg\steamapi\user.py", line 149, in _ convert_games_list
game_obj = SteamApp(game.appid, game.name, associated_userid)
File "C:\Python34\lib\site-packages\steamapi-0.1-py3.4.egg\steamapi\core.py", line 506, in __ getattribute__attr=item))
AttributeError: 'APIResponse' has no attribute 'name'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.